Skip to content

fix: sort script toolset keys for deterministic prompt ordering#3235

Merged
simonferquel merged 2 commits into
docker:mainfrom
simonferquel-clanker:fix/sort-script-toolset-keys
Jun 25, 2026
Merged

fix: sort script toolset keys for deterministic prompt ordering#3235
simonferquel merged 2 commits into
docker:mainfrom
simonferquel-clanker:fix/sort-script-toolset-keys

Conversation

@simonferquel-clanker

Copy link
Copy Markdown
Contributor

Both Instructions() and Tools() in ScriptToolSet iterated 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.

  • Sort shellTools keys before iterating in both Instructions() and Tools()
  • Sort tool.Args keys before iterating inside Instructions() (fixes multi-arg tools)
  • Remove redundant toolName := name variable in Tools() (Go 1.22+ per-iteration range)
  • Add TestScriptToolSet_DeterministicOrdering covering both tool-level and arg-level ordering

Fixes #3233

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).
@simonferquel-clanker simonferquel-clanker requested a review from a team as a code owner June 25, 2026 13:36

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@simonferquel simonferquel merged commit 2c37d22 into docker:main Jun 25, 2026
8 checks passed
@stasyu2009-ux

Copy link
Copy Markdown

Я свою роботу виконав далі потрібно виправити одну помилку в коді.

@stasyu2009-ux

Copy link
Copy Markdown

Вона невелика.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants