Skip to content

fix(init): preserve protocol selection order from server (BLO-802)#739

Merged
maoueh merged 2 commits intodevelopfrom
copilot/fix-choices-ordering-issue
Jan 9, 2026
Merged

fix(init): preserve protocol selection order from server (BLO-802)#739
maoueh merged 2 commits intodevelopfrom
copilot/fix-choices-ordering-issue

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

Protocol choices in substreams init displayed in random order due to Go map iteration having undefined ordering. The server sends generators sorted by weight, but this ordering was lost during client-side grouping.

Changes

cmd/substreams/init.go

  • Track protocol group insertion order using a protocolOrder slice alongside the grouping map
  • Iterate over the slice instead of the map when building UI options
// Before: random order due to map iteration
for _, value := range filteredProtocols {
    protocolOptions = append(protocolOptions, ...)
}

// After: preserves server order
var protocolOrder []string
for _, gen := range resp.Msg.Generators {
    if !groupExists {
        protocolOrder = append(protocolOrder, gen.Group)
        // ... 
    }
}
for _, group := range protocolOrder {
    value := filteredProtocols[group]
    protocolOptions = append(protocolOptions, ...)
}

cmd/substreams/init_test.go (new)

  • Unit test verifying protocol and generator order preservation

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Jan 8, 2026
@maoueh maoueh marked this pull request as ready for review January 8, 2026 21:24
Add protocolOrder slice to track insertion order when grouping generators by protocol, ensuring the protocol selection menu displays options in the order the server intended (sorted by weight).

Co-authored-by: maoueh <123014+maoueh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix choices ordering issue in substreams init command fix(init): preserve protocol selection order from server (BLO-802) Jan 8, 2026
Copilot AI requested a review from maoueh January 8, 2026 21:33
@maoueh
Copy link
Contributor

maoueh commented Jan 8, 2026

@copilot The plan was to fix all choices related ordering and not just the root generator list.

Here a sub questions exhibiting the same problem:

# run 1
┃ Chosen protocol:  EVM - EVM
┃ Choose the type of project that you want to create.
┃ > evm-hello-world      - Creates a Substreams that extracts USDC log data from blocks
┃   evm-events-calls-raw - (without ABI) Get raw Ethereum events/calls and create a Substreams as source
┃   evm-events-calls     - (with ABI) Decode Ethereum events/calls using an ABI and create a Substreams as source

# run 2
┃ Chosen protocol:  EVM - EVM
┃ Choose the type of project that you want to create.
┃ > evm-hello-world      - Creates a Substreams that extracts USDC log data from blocks
┃   evm-events-calls     - (with ABI) Decode Ethereum events/calls using an ABI and create a Substreams as source
┃   evm-events-calls-raw - (without ABI) Get raw Ethereum events/calls and create a Substreams as source

You need to fix the bug globally for any other choices

Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot The plan was to fix all choices related ordering and not just the root generator list.

Here a sub questions exhibiting the same problem:
...

I see the generator ordering issue you're showing. I've reviewed the code and the generator list is built by iterating selector.Generators which is populated in order from resp.Msg.Generators (lines 251-267).

Could you clarify which specific "sub questions" or other choice presentations you're seeing ordering issues with? Are you seeing:

  1. Different generator orders when selecting the same protocol between runs (as shown)?
  2. Other list selections later in the conversation flow that show ordering issues?
  3. Both?

This will help me identify if there's another map iteration we need to fix, or if the issue might be server-side (e.g., server sending generators in different orders).

@maoueh
Copy link
Contributor

maoueh commented Jan 9, 2026

@copilot Ok the other ordering bug was on the server, let merge this one and I will spawn you to fix the sever.

@maoueh maoueh merged commit e67cbba into develop Jan 9, 2026
4 of 5 checks passed
@maoueh maoueh deleted the copilot/fix-choices-ordering-issue branch January 9, 2026 15:00
Copilot stopped work on behalf of maoueh due to an error January 9, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants