fix: sort script toolset keys for deterministic prompt ordering#3235
Merged
simonferquel merged 2 commits intoJun 25, 2026
Merged
Conversation
Both Instructions() and Tools() iterated over a Go map, producing non-deterministic output order on every call. This caused Anthropic (and similar) prompt-caching to miss every turn because the system prompt changed byte-order. Sort the tool names before iterating in both methods so output is always alphabetical and stable. Add TestScriptToolSet_DeterministicOrdering to assert the alphabetical order of Tools() results and Instructions() headings. Fixes docker#3233
Also remove redundant toolName variable in Tools() (Go 1.22+ per-iteration range semantics make the copy unnecessary).
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The changes are correct and well-implemented. Both Instructions() and Tools() now collect map keys into a sorted slice before iterating, ensuring deterministic prompt output on every call. The tool.Args sort in Instructions() closes the remaining non-determinism for multi-arg tools. Removal of the redundant toolName := name alias is safe under Go 1.22+ per-iteration range semantics. The new test TestScriptToolSet_DeterministicOrdering provides solid coverage of both tool-level and arg-level ordering.
dgageot
approved these changes
Jun 25, 2026
|
Я свою роботу виконав далі потрібно виправити одну помилку в коді. |
|
Вона невелика. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Both
Instructions()andTools()inScriptToolSetiterated directly over Go maps, producing non-deterministic output order on every call. This caused Anthropic (and similar) prompt-caching to miss every turn because the system prompt changed byte-order between calls.shellToolskeys before iterating in bothInstructions()andTools()tool.Argskeys before iterating insideInstructions()(fixes multi-arg tools)toolName := namevariable inTools()(Go 1.22+ per-iteration range)TestScriptToolSet_DeterministicOrderingcovering both tool-level and arg-level orderingFixes #3233