You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(#2053): add reverse validation and merge-based repair for tool sequencing
validateSequencing only checked the forward direction: every assistant
tool_use must have a matching tool_result in the next user message. It
did not check the reverse: every tool_result must reference a tool_use
in the immediately preceding assistant message. Orphan tool_results
passed validation silently.
Additionally, repairSequencing inserted a synthetic user message with
missing tool_results *before* an existing user message that already
had partial tool_results. This split tool_results across two user
messages, causing the existing results to become orphaned:
assistant(tool_use: A, B)
synthetic_user(tool_result: B) <- repair inserted this
user(tool_result: A) <- A now orphaned (previous is synthetic_user)
Two fixes:
1. validateSequencing now also checks the reverse direction: for each
user message containing tool_result blocks, verify the immediately
preceding message is an assistant with corresponding tool_use IDs.
2. repairSequencing now merges missing tool_results into the existing
next user message instead of inserting a separate synthetic message.
This keeps all tool_results in a single user message adjacent to the
assistant, satisfying both forward and reverse invariants.
Assisted-By: docker-agent
slog.Warn("Anthropic sequencing invalid: missing tool_result for tool_use id in next user message", "assistant_index", i, "tool_use_id", missing[0], "missing_count", len(missing))
813
+
returnfmt.Errorf("missing tool_result for tool_use id %s in the next user message", missing[0])
slog.Warn("Anthropic sequencing invalid: missing tool_result for tool_use id in next user message", "assistant_index", i, "tool_use_id", missing[0], "missing_count", len(missing))
810
-
returnfmt.Errorf("missing tool_result for tool_use id %s in the next user message", missing[0])
817
+
// Reverse check: user with tool_result → previous message must be assistant with matching tool_use
0 commit comments