Repository navigation
Conversation
Greptile SummaryThis PR removes Root cause recap: Anthropic generates tool IDs in the form Key observations from the review:
Confidence Score: 4/5
Reviews (1): Last reviewed commit: "fix(agents): skip tool-call ID sanitizat..." | Re-trigger Greptile |
|
CI failures are unrelated to this PR:
Our change: exclusively in Happy to rebase once main stabilizes. |
ed4e4fe to
d6ae4ce
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6ae4ce571
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // ID rewriting in createOccurrenceAwareResolver causes cache prefix instability | ||
| // after subagent turns (repairToolUseResultPairing can reorder messages, changing | ||
| // encounter order → different sanitized IDs → full cacheWrite). See #52612. | ||
| const sanitizeToolCallIds = isGoogle || isMistral || requiresOpenAiCompatibleToolIdSanitization; |
There was a problem hiding this comment.
Keep sanitization for cross-provider replayed tool IDs
This change disables tool-call ID rewriting for all Anthropic/Bedrock transcript paths, which breaks cross-provider replay cases where OpenAI Responses history contains IDs like call_123|fc_123 (see src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts). When a session switches from OpenAI to Anthropic, sanitizeSessionHistory no longer normalizes those IDs (and OpenAI-specific downgrade logic does not run on Anthropic APIs), so pipe-delimited IDs are forwarded as-is and can trigger tool_use.id request-format failures on the next Anthropic turn.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Acknowledged. Cross-provider replay (OpenAI → Anthropic mid-session) is a valid edge case — pipe-delimited IDs like call_123|fc_123 from OpenAI history could be forwarded to Anthropic unsanitized. However, this scenario is distinct from the bug this PR fixes (#52612): native Anthropic sessions with subagents where the sanitization itself causes cache instability. The cross-provider case is pre-existing and unrelated to cache — happy to address it in a follow-up with more targeted sanitization (only sanitize non-toolu_* IDs).
d6ae4ce to
851cbc9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 851cbc905e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // ID rewriting in createOccurrenceAwareResolver causes cache prefix instability | ||
| // after subagent turns (repairToolUseResultPairing can reorder messages, changing | ||
| // encounter order → different sanitized IDs → full cacheWrite). See #52612. | ||
| const sanitizeToolCallIds = isGoogle || isMistral || requiresOpenAiCompatibleToolIdSanitization; |
There was a problem hiding this comment.
Restore tool ID sanitization for Anthropic replayed history
Turning off sanitizeToolCallIds for Anthropic removes the only normalization that strips OpenAI call_id|fc_id separators during provider switches. In an OpenAI → Anthropic/Bedrock handoff, history can legitimately contain IDs like call_123|fc_123; sanitizeSessionHistory only runs downgradeOpenAIFunctionCallReasoningPairs when the current modelApi is OpenAI Responses, so Anthropic requests now forward these IDs unchanged and can hit tool_use.id format errors. Fresh evidence: src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts explicitly preserves pipe-delimited IDs when replayable reasoning metadata is present.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same concern as prior two replies — see above. Cross-provider replay is a pre-existing gap, not introduced by this PR. Happy to discuss if maintainers want a different approach.
851cbc9 to
54ba67f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 54ba67f048
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // ID rewriting in createOccurrenceAwareResolver causes cache prefix instability | ||
| // after subagent turns (repairToolUseResultPairing can reorder messages, changing | ||
| // encounter order → different sanitized IDs → full cacheWrite). See #52612. | ||
| const sanitizeToolCallIds = isGoogle || isMistral || requiresOpenAiCompatibleToolIdSanitization; |
There was a problem hiding this comment.
Re-enable Anthropic ID sanitization for provider switches
Removing isAnthropic from this gate means Anthropic/Bedrock turns no longer run tool-id normalization on replayed history, so sessions that started on OpenAI Responses can carry persisted call_id|fc_id IDs straight into Anthropic requests. src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts confirms those pipe-delimited IDs are intentionally preserved in history when reasoning metadata exists; without the previous Anthropic sanitization pass, these IDs can hit Anthropic tool_use.id pattern/format validation and fail the next turn. Fresh evidence: in the parent version of this line (c60a4fef^), isAnthropic was included in sanitizeToolCallIds, so this regression is introduced by this commit.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same concern as prior replies — see above.
54ba67f to
035b0b0
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 035b0b0238
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // ID rewriting in createOccurrenceAwareResolver causes cache prefix instability | ||
| // after subagent turns (repairToolUseResultPairing can reorder messages, changing | ||
| // encounter order → different sanitized IDs → full cacheWrite). See #52612. | ||
| const sanitizeToolCallIds = isGoogle || isMistral || requiresOpenAiCompatibleToolIdSanitization; |
There was a problem hiding this comment.
Restore Anthropic ID sanitization for cross-provider replay
Dropping isAnthropic from this gate means Anthropic/Bedrock requests no longer normalize historical tool IDs, so OpenAI Responses transcripts can now carry raw call_id|fc_id values (for example call_123|fc_123) directly into Anthropic turns. That format is intentionally preserved in history when reasoning metadata exists (src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts), and Anthropic tool_use.id validation does not accept the | separator, so model switches from OpenAI → Anthropic can fail with request-format errors instead of being repaired. Fresh evidence versus prior feedback: before this commit, this exact line included isAnthropic, so the Anthropic replay sanitization path existed and is removed here.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same concern as prior replies — see above.
035b0b0 to
ad5a7f6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad5a7f60fa
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // ID rewriting in createOccurrenceAwareResolver causes cache prefix instability | ||
| // after subagent turns (repairToolUseResultPairing can reorder messages, changing | ||
| // encounter order → different sanitized IDs → full cacheWrite). See #52612. | ||
| const sanitizeToolCallIds = isGoogle || isMistral || requiresOpenAiCompatibleToolIdSanitization; |
There was a problem hiding this comment.
Restore tool-id sanitization for Bedrock replay paths
This gate now disables sanitizeToolCallIds for all bedrock-converse-stream requests, so a session that switches from OpenAI Responses to Bedrock can forward persisted IDs like call_123|fc_123 unchanged instead of normalizing them before replay. sanitizeSessionHistory only runs downgradeOpenAIFunctionCallReasoningPairs on OpenAI model APIs, so Bedrock turns no longer get a fallback rewrite and can fail with tool-use ID format errors on the next request. Fresh evidence versus prior thread feedback: the repo already models Bedrock as mixed Anthropic/non-Anthropic (see isAnthropicBedrockModel usage), so this blanket disable is broader than the Anthropic toolu_* cache-stability rationale.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same concern as prior replies — see above. Cross-provider replay normalization is a valid follow-up but orthogonal to this cache-stability fix. Happy to discuss further if maintainers want a different approach.
|
CI triage update: 3 remaining failures are upstream — same failures present on main. Failing (upstream):
Our area all passes:
Our change: 2 files ( |
ad5a7f6 to
9913979
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9913979f19
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // ID rewriting in createOccurrenceAwareResolver causes cache prefix instability | ||
| // after subagent turns (repairToolUseResultPairing can reorder messages, changing | ||
| // encounter order → different sanitized IDs → full cacheWrite). See #52612. | ||
| const sanitizeToolCallIds = isGoogle || isMistral || requiresOpenAiCompatibleToolIdSanitization; |
There was a problem hiding this comment.
Restore Anthropic/Bedrock tool ID replay sanitization
Removing isAnthropic from sanitizeToolCallIds disables tool ID normalization for Anthropic and Bedrock requests, so an OpenAI Responses session that preserved call_id|fc_id IDs can now carry those raw IDs into a provider switch and hit tool_use.id request-format errors instead of being repaired first. This is user-impacting in mixed-provider sessions because those pipe-delimited IDs are intentionally persisted for replay when reasoning metadata exists (src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts). Fresh evidence: in the parent revision (a1a226877bd913e070cf223d3272bf62d83683ed^), this same line still included isAnthropic, so this regression is introduced by this commit.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same concern as prior rounds — cross-provider replay (OpenAI→Anthropic pipe-delimited IDs) is a pre-existing edge case, not introduced by this PR. This PR fixes cache prefix instability caused by order-dependent sanitization of Anthropic's native toolu_* IDs. A follow-up targeting only non-toolu_* IDs during cross-provider replay would be the correct scope for that fix.
There was a problem hiding this comment.
Same concern as prior rounds — cross-provider replay (OpenAI→Anthropic pipe-delimited IDs) is a pre-existing edge case, not introduced by this PR. This PR fixes cache prefix instability caused by order-dependent sanitization of Anthropic's native toolu_* IDs. A follow-up targeting only non-toolu_* IDs during cross-provider replay would be the correct scope for that fix.
Anthropic generates tool IDs with underscores (toolu_01XYZ) that their API accepts natively. The strict-mode sanitization stripped underscores, and the order-dependent ID rewriting in createOccurrenceAwareResolver caused cache prefix instability after subagent turns—repairToolUseResultPairing can reorder messages between turns, changing encounter order and producing different sanitized IDs for the same original tool call, triggering a full cacheWrite instead of a cache hit. Remove isAnthropic from the sanitizeToolCallIds flag so Anthropic and Bedrock providers preserve their original tool IDs end-to-end. Closes openclaw#52612
9913979 to
8d7c613
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d7c613efc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // ID rewriting in createOccurrenceAwareResolver causes cache prefix instability | ||
| // after subagent turns (repairToolUseResultPairing can reorder messages, changing | ||
| // encounter order → different sanitized IDs → full cacheWrite). See #52612. | ||
| const sanitizeToolCallIds = isGoogle || isMistral || requiresOpenAiCompatibleToolIdSanitization; |
There was a problem hiding this comment.
Restore Anthropic replay tool-ID sanitization on provider switches
This change disables the only Anthropic/Bedrock-side rewrite that normalized persisted OpenAI Responses IDs, so sessions that switch providers can now forward call_id|fc_id values unchanged from history (those pairings are intentionally preserved in src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts). Anthropic tool-use IDs are pattern-constrained (alphanumeric plus _/-), so the | separator can cause request-format 400s on the first Anthropic follow-up turn. Fresh evidence: in the parent revision of this line, isAnthropic was part of the sanitization gate, and removing it here is what drops that normalization path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same concern as prior replies — see above.
|
I validated this against current main and I do not trust this PR as the merge vehicle anymore.\n\nThe core problem with the patch is structural drift: bundled Anthropic/Bedrock replay policy no longer lives in for the real provider-owned path. Current main resolves that behavior through , , and , so this PR is modifying an older seam.\n\nI also did not reproduce the claimed root cause in a direct current-main harness with Anthropic-style unique ids: the replay prefix stayed byte-stable when I appended a later subagent turn and ran the same sanitize+repair pipeline. That does not prove the issue is impossible, but it does mean this PR's underscore-stripping explanation is not proven on today's code.\n\nClosing this PR as stale / wrong seam. If still reproduces on current main, please post a fresh repro with cache trace/session evidence and open a new narrow PR against the provider-owned replay-policy path, not the old fallback logic. |
|
I validated this against current main and I do not trust this PR as the merge vehicle anymore. The core problem with the patch is structural drift: bundled Anthropic/Bedrock replay policy no longer lives in I also did not reproduce the claimed root cause in a direct current-main harness with Anthropic-style unique Closing this PR as stale / wrong seam. If #52612 still reproduces on current main, please post a fresh repro with cache trace/session evidence and open a new narrow PR against the provider-owned replay-policy path, not the old fallback logic. |
Summary
cacheWriteinstead of cache hits, causing unexpected cost increases. This affects all Anthropic users who use tool calls with subagents.isAnthropicfrom thesanitizeToolCallIdsflag inresolveTranscriptPolicyrepairToolUseResultPairingis unchanged — it still runs for all providerssanitizeToolCallIdfunction itself is unchangedChange Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
toolu_01AbCdEf). The "strict" sanitization mode stripped non-alphanumeric characters viacreateOccurrenceAwareResolver, which generates replacement IDs based on encounter order in the message array. After a subagent turn,repairToolUseResultPairingcan reorder, insert, or drop messages. This changes the encounter order → the same original tool ID maps to a different sanitized ID → Anthropic sees different bytes in the cache prefix → fullcacheWrite.sanitizeToolCallIdsflag was set uniformly for all non-OpenAI providers without distinguishing providers whose APIs accept their own native ID format.sanitizeToolCallIdswas introduced to handle providers that reject certain characters in tool call IDs (Google, Mistral, OpenAI-completions). Anthropic was included in this group despite generating IDs its own API accepts natively.repairToolUseResultPairingreorders messages, changing the encounter order forcreateOccurrenceAwareResolver. Single-agent sessions have stable message order, so the sanitized IDs happen to stay consistent.Regression Test Plan (if applicable)
src/agents/transcript-policy.test.tsresolveTranscriptPolicyreturnssanitizeToolCallIds: falseandtoolCallIdMode: undefinedfor Anthropic providersfalse, no downstream code will rewrite IDs regardless of message ordering."disables sanitizeToolCallIds for Anthropic provider"test (was assertingtrue, now correctly assertsfalse)User-visible / Behavior Changes
Security Impact (required)
NoNoNoNoNoRepro + Verification
Environment
Steps
Read the IDENTITY.md file. Do exactly as I ask.Ask a subagent to respond with a random emoji, then tell me which emoji it was.agent/:id/sessionsfolder)cacheWritevalue for the last message in the chainExpected
cacheWritemarginally increased,cacheReadis non-zero (cache prefix matches prior turns).Actual
cacheWriteis large (entire conversation rewritten),cacheReadis zero (cache prefix changed due to ID rewriting).Evidence
Human Verification (required)
resolveTranscriptPolicyreturnssanitizeToolCallIds: falsefor Anthropic providerresolveTranscriptPolicyreturnssanitizeToolCallIds: falsefor Bedrock Anthropic providersanitizeToolCallIds: truetoolCallIdModefalls through toundefined(not"strict") whensanitizeToolCallIdsisfalseReview Conversations
Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
isAnthropicto thesanitizeToolCallIdsflag inresolveTranscriptPolicy(1-line revert)src/agents/transcript-policy.tsonlytool_use_idformatRisks and Mitigations
toolu_*IDs with underscores (unverified assumption that it accepts them since it proxies Anthropic)anthropic-messagesmodelApi but generating non-toolu_*IDs would skip sanitization