fix(claude): drop invalid tool history before upstream#4577
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82ef4be747
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
82ef4be to
a93e8f3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a93e8f3476
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a93e8f3 to
a0081b9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0081b93e6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a0081b9 to
8b1a108
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8b1a108174
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
8b1a108 to
7cc7ee5
Compare
Fixes #4112.
Problem
Anthropic rejects stale or malformed Claude message history when:
tool_usehas no matching result in the immediately following user message;tool_resultreferences no tool call in the previous assistant message; ortool_resultappears after text or image content instead of in the leading result block group.The existing Claude-upstream sanitizer removed incompatible reasoning signatures but forwarded those structurally invalid tool blocks unchanged, producing HTTP 400 before model execution.
Change
Enable tool-history repair only in
SanitizeClaudeMessagesForClaudeUpstream:Other provider compatibility paths keep their existing behavior because the new option is disabled by default.
Verification
ClaudeExecutorregression confirming invalid blocks are absent from the Anthropic request body;go test ./internal/signature ./internal/runtime/executor -count=1;go test -racefor the sanitizer and Claude executor paths;go vet ./internal/signature ./internal/runtime/executor;go build -o test-output ./cmd/server && rm test-output;git diff --check.