fix(BLO-803): add secondary sort by ID for deterministic handler ordering #55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Deterministic Ordering for Generators with Same Weight
Implementation Plan
registry.goat line 40-50 where map iteration causes random orderingListConversationHandlers()function inregistry.goto add secondary sort by IDregistry_test.goto verify deterministic orderingProblem
In
registry.go, theListConversationHandlers()function iterates over a map (which has non-deterministic iteration order in Go) and then sorts only by weight. When multiple handlers have the same weight (e.g.,evm-events-callsandevm-events-calls-rawboth have weight 82), they would randomly swap positions between runs, leading to inconsistent user experience.Solution
Added a secondary sort key (handler ID) to ensure deterministic alphabetical ordering within the same weight group. The sort now:
This ensures consistent user experience where choices appear in the same order every time.
Changes Made:
Modified
registry.go: UpdatedListConversationHandlers()function to add secondary sort by ID for deterministic orderingCreated
registry_test.go: Added comprehensive unit testsTestListConversationHandlers_DeterministicOrdering: Verifies consistent ordering across 10 runsTestListConversationHandlers_WeightOrdering: Verifies weight-based sortingTestListConversationHandlers_RealWorldEVMScenario: Tests actual EVM generator scenarioUpdated
.gitignore: Added compiled binaries to prevent future accidentsFixed
evm-events-calls/convo_test.go: CorrectedTestInvalidWrappedABIFormattestSeqMsgwrapper when error messages are returned directly as*pbconvo.SystemOutputSystemOutputreturnVerification:
✅ All new tests pass
✅ Build succeeds without errors
✅ All tests pass (including the previously failing integration test)
✅ Binary removed and .gitignore updated
✅ Code review passed with no comments
✅ CodeQL security scan found 0 vulnerabilities
Security Summary
No security vulnerabilities were introduced or found in this change. CodeQL analysis completed with 0 alerts.
Fixes https://linear.app/streamingfast/issue/BLO-803/substreams-codegen-ordering-issue
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.