Repository navigation
fix(ai): reshape+restore non-canonical tool-call ids for HTTP continuation - #134425
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 28, 2026, 9:02 PM ET / September 29, 2026, 01:02 UTC (Revision 22). ClawSweeper reviewWhat this changesThe branch changes OpenClaw’s Responses transport to recognize reshaped tool-call IDs, restore raw provider IDs in continuation requests, and track unresolved calls across responses. Merge readiness⛔ Blocked before merge - 1 item remains Current main and the latest release still compare the replayed tool-call ID with the provider’s raw ID, so this PR retains a distinct fix. The earlier collision and call-ownership findings appear addressed at this head. No new blocking defect was established. Priority: P2 Review scores
Verification
How this fits togetherThe Responses transport turns agent conversation history into provider requests. Its continuation resolver decides whether to send only new input with a previous response ID or resend full history. flowchart LR
A[Agent history] --> B[Replay tool IDs]
B --> C[Continuation resolver]
D[Cached provider response] --> C
C --> E{History and call owner match?}
E -->|Yes| F[Raw-ID delta request]
E -->|No| G[Full-history request]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +335, Tests +1002. Total +1337 across 9 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain one continuation resolver for HTTP and WebSocket, with raw provider IDs restored only when a replayed result has one unambiguous cached call owner. Do we have a high-confidence way to reproduce the issue? Yes at source level: current main compares replayed and cached IDs in their different forms. The branch’s loopback trace exercises the resulting transport behavior; this read-only review did not execute it. Is this the best way to solve the issue? Yes. The change stays in the shared continuation resolver and falls back to full history when a call owner is unknown or ambiguous. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a6bc0f03b39a. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (21 earlier review cycles; latest 8 shown)
|
3f41f58 to
5f764c8
Compare
…ation (blocked on openclaw#128633) (openclaw#134425) Combined-deploy squash of openclaw#134425. See that PR for the full commit history, review discussion, and live-verification evidence.
|
This pull request has been automatically marked as stale due to inactivity. |
5f764c8 to
cec8866
Compare
… for eligibility normalizeOpenAIResponsesToolCallIds re-sanitizes call_id for provider-format compatibility on replay, which previously made the eligibility check either reject every multi-round tool-calling turn (blanket compare) or, after a prior loosening, blanket-drop call_id from the comparison entirely -- letting an unrelated changed function-call id through as if it were the known reshape, and shipping the client's reshaped call_id instead of the raw provider id on the wire delta. A server that reconstructs continuation history server-side from its own cached raw response (e.g. a proxy virtualizing previous_response_id) pairs function_call_output against the function_call it cached verbatim, so the reshaped call_id reads as orphaned and the tool result gets dropped. Canonicalize call_id/fc_id through the same reshape for the eligibility comparison (fail-closed: only forgives ids that reshape TO the cached raw id, never an arbitrary difference), and restore the raw provider id on the wire-bound delta before it's sent. Also fixes a lossless-integer gap in the arguments comparison (distinct unsafe integers could round to the same JS number under plain JSON.parse and wrongly compare equal).
…inuation eligibility Replay reshapes a function_call's id by pairing call_id and item id into one call_id|fc_id string before hashing (normalizeOpenAIResponsesToolCallIds). The continuation eligibility comparison and the raw-id restore path only canonicalized the cached response's bare call_id, ignoring its paired item id, so they hashed a different input than replay actually produced and permanently returned history_changed for any turn whose provider ids needed reshaping. Reconstruct the same call_id|item_id pairing from the cached raw response before canonicalizing, mirroring the exact idempotent short-circuit replay's own resolver uses so already provider-shaped ids are left unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ation (openclaw#134425) * fix(ai): restore raw call_id on continuation wire delta, canonicalize for eligibility normalizeOpenAIResponsesToolCallIds re-sanitizes call_id for provider-format compatibility on replay, which previously made the eligibility check either reject every multi-round tool-calling turn (blanket compare) or, after a prior loosening, blanket-drop call_id from the comparison entirely -- letting an unrelated changed function-call id through as if it were the known reshape, and shipping the client's reshaped call_id instead of the raw provider id on the wire delta. A server that reconstructs continuation history server-side from its own cached raw response (e.g. a proxy virtualizing previous_response_id) pairs function_call_output against the function_call it cached verbatim, so the reshaped call_id reads as orphaned and the tool result gets dropped. Canonicalize call_id/fc_id through the same reshape for the eligibility comparison (fail-closed: only forgives ids that reshape TO the cached raw id, never an arbitrary difference), and restore the raw provider id on the wire-bound delta before it's sent. Also fixes a lossless-integer gap in the arguments comparison (distinct unsafe integers could round to the same JS number under plain JSON.parse and wrongly compare equal). * fix(ai): canonicalize cached call_id with its paired item id for continuation eligibility Replay reshapes a function_call's id by pairing call_id and item id into one call_id|fc_id string before hashing (normalizeOpenAIResponsesToolCallIds). The continuation eligibility comparison and the raw-id restore path only canonicalized the cached response's bare call_id, ignoring its paired item id, so they hashed a different input than replay actually produced and permanently returned history_changed for any turn whose provider ids needed reshaping. Reconstruct the same call_id|item_id pairing from the cached raw response before canonicalizing, mirroring the exact idempotent short-circuit replay's own resolver uses so already provider-shaped ids are left unchanged. * fix(test): keep the call_id-reshape test focused on ids, not argument whitespace tolerance openclaw#134423 landed while this branch was in flight and scoped the lossless unsafe-integer/whitespace argument comparison to fromResponse (cached, provider-origin) items only -- replayed arguments are now compared strictly, byte for byte, since a caller-side edit is meaningful and must not be silently tolerated (see 'keeps already-sent arguments strict'). This test's fixture had an incidental whitespace difference between the cached and replayed arguments string, left over from before that refinement landed -- post-openclaw#134423 that's now a genuine (correct) history_changed, not the call_id-reshape scenario this test is actually about. Made the replayed arguments byte-identical to the cached ones (a real client replay never actually changes them) so the test proves what its name says: call_id reshaping, not argument tolerance. * test(ai): add the non-canonical call_id integration test, blocked on openclaw#128633 Real loopback HTTP+SSE server (no SDK mocking) proof for this PR's own reshape-then-restore mechanism, using a genuinely non-canonical call_id/id pair shaped like a real moonshotai/kimi-k2.5-via-openrouter connection would produce -- the only shape that exercises canonicalizeCachedCallId's reshaping at all (a native api.openai.com connection already returns canonical call_*/fc_* ids, making the reshape a permanent no-op there). describe.skip on this branch: reaching this path requires compat.supportsResponsesContinuation eligibility widening, which is openclaw#128633's work, not part of this PR. Confirmed this genuinely passes (not just theoretically) by copying this file plus this PR's own production changes onto openclaw#128633's branch checkout, un-skipping, and running it there -- green. Un-skip for real once this branch stacks on openclaw#128633 (or after it merges to main). * fix(ai): clean up rebase fallout (dead helpers, assertion ratchet) Rebasing this branch onto current main surfaced two check-changed findings from the conflict resolution: - Resolving the conflict in embedded-agent-helpers/openai.ts against a stale hunk by keeping the wrong side resurrected DowngradeOpenAIReasoningBlocksOptions and hasFollowingNonThinkingBlock, both already unused on current main and never referenced anywhere in this file (the same class of mistake already fixed once on the combined deployment branch in ee346ded273). Caught by tsgo's own unused-declaration check (TS6196/TS6133). - The two new type assertions restoreRawCallIdsInDelta introduced in openai-responses-continuation.ts pushed that file's uncommented- assertion count past its grandfathered ratchet baseline (2 -> 4). Added // SAFETY: comments documenting why each cast is sound instead of loosening the ratchet. Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6 * fix(ai): canonicalize the tool-call id pair on both replay and cache, not just the cache ClawSweeper flagged a real continuation regression: canonicalizeReplayedCallId reshaped only the bare replayed call_id, while canonicalizeCachedCallId reshaped the call_id/item.id *pair* on the cached side. A direct Responses transport caller that preserves same-model tool-call ids verbatim (transcript-transform.ts's transformMessages same-model branch) replays a completely unchanged, non-canonical call_id/id pair -- identical to the cached side in every way -- but the two sides canonicalized to different hashes for that exact case, permanently forcing history_changed and resending the whole conversation every round. Fix: use one canonicalization function (renamed to canonicalizeToolCallId) for both sides, pairing call_id with the item's own id before reshaping either way. New regression test proves an unchanged raw pair now continues. * test(ai): enable the non-canonical call_id integration test now that openclaw#128633 landed The compat/proxy eligibility widening this test was waiting on (compat.supportsResponsesContinuation) merged into main; un-skip and drop the now-stale pre-merge type-cast workaround. Passes for real. * fix(ai): preserve continuation when replay omits the optional item id ClawSweeper flagged a real regression from unifying call_id canonicalization onto always-pair-with-item-id: a direct transport caller configured with replayResponsesItemIds:false (e.g. the ChatGPT-Responses provider) omits function_call.id from the wire while preserving its raw, non-canonical call_id verbatim -- that replayed item structurally has no id to pair with, so it always canonicalizes via the bare-call_id branch. The cached side (which always has the full raw pair from the provider's own response) only ever computed the paired canonicalization, so this legitimate unchanged replay permanently forced history_changed. Fix: compare the replayed tool round against two candidate cached-history shapes -- normally paired with the cached item's own id, or, failing that, ignoring it entirely -- and accept either as unchanged. Both are real replay shapes; which one a given connection produces depends on its own replayResponsesItemIds setting. New regression test proves the omitted-id case now continues; TDD-verified it fails without the fix. * test(ai): cover Responses continuation replay identity * fix(ai): preserve Responses continuation identity * chore(ai): retain assertion safety rationale * test(systemd): include first-hop timing helper in fixture * fix(ai): brace continuation comparison branches * test(ai): reject Responses ID normalization collisions * test(ai): cover invalid Responses continuation outputs * test(ai): cover ambiguous Responses continuation fallback * fix(ai): reject ambiguous Responses continuation IDs * test(ai): avoid map spread in Responses fixture * fix(ai): unify Responses continuation ID ownership * fix(ai): track Responses continuation call owners * docs(ai): clarify continuation ID test * fix(ai): preserve Responses continuation call owners * fix(ai): preserve pending Responses call order * fix(ai): match replayed Responses ID shapes * fix(ai): narrow replayed Responses call ID * fix(ai): drop unused continuation loop binding * style(ai): brace Responses continuation guards --------- Co-authored-by: Patrick Erichsen <[email protected]>
… merge Main moved again since the last push -- openclaw#134425 (non-canonical tool-call-ID handling) merged directly into openai-responses-continuation.ts and its test file, conflicting with this PR's default/cache-bound changes in the same functions. Reconstructed via GitHub's own PR diff applied fresh onto current main; hand-merged the three real conflicts (the 90-minute default + capacity/byte-bound eviction logic around Patrick's new dispatchedPreviousResponseId/recordResponsesContinuationState call shape in claimOpenAIResponsesHttpContinuation, and the matching test additions). Split the growing continuation.test.ts (now over the 700-line ratchet after merging both PRs' additions) into a new sibling openai-responses-continuation.cache-bounds.test.ts carrying the capacity/byte-budget/eviction-order/reclaim-race tests -- new max-lines suppressions aren't allowed, and this group was already a coherent, separable unit. No functional changes to this PR's own default-TTL/cache-bound logic. Full targeted suite green (73 files, 1205 tests); oxfmt/oxlint clean; max-lines ratchet and config-doc baseline verified.
…d the cache (#128848) * fix(ai): rebuild onto main after #134425's tool-call-ID-shape merge Main moved again since the last push -- #134425 (non-canonical tool-call-ID handling) merged directly into openai-responses-continuation.ts and its test file, conflicting with this PR's default/cache-bound changes in the same functions. Reconstructed via GitHub's own PR diff applied fresh onto current main; hand-merged the three real conflicts (the 90-minute default + capacity/byte-bound eviction logic around Patrick's new dispatchedPreviousResponseId/recordResponsesContinuationState call shape in claimOpenAIResponsesHttpContinuation, and the matching test additions). Split the growing continuation.test.ts (now over the 700-line ratchet after merging both PRs' additions) into a new sibling openai-responses-continuation.cache-bounds.test.ts carrying the capacity/byte-budget/eviction-order/reclaim-race tests -- new max-lines suppressions aren't allowed, and this group was already a coherent, separable unit. No functional changes to this PR's own default-TTL/cache-bound logic. Full targeted suite green (73 files, 1205 tests); oxfmt/oxlint clean; max-lines ratchet and config-doc baseline verified. * refactor(ai): simplify bounded continuation ownership and strengthen proof * fix(plugins): queue compatibility removals pending reader migration --------- Co-authored-by: Patrick Erichsen <[email protected]>
…d the cache (openclaw#128848) * fix(ai): rebuild onto main after openclaw#134425's tool-call-ID-shape merge Main moved again since the last push -- openclaw#134425 (non-canonical tool-call-ID handling) merged directly into openai-responses-continuation.ts and its test file, conflicting with this PR's default/cache-bound changes in the same functions. Reconstructed via GitHub's own PR diff applied fresh onto current main; hand-merged the three real conflicts (the 90-minute default + capacity/byte-bound eviction logic around Patrick's new dispatchedPreviousResponseId/recordResponsesContinuationState call shape in claimOpenAIResponsesHttpContinuation, and the matching test additions). Split the growing continuation.test.ts (now over the 700-line ratchet after merging both PRs' additions) into a new sibling openai-responses-continuation.cache-bounds.test.ts carrying the capacity/byte-budget/eviction-order/reclaim-race tests -- new max-lines suppressions aren't allowed, and this group was already a coherent, separable unit. No functional changes to this PR's own default-TTL/cache-bound logic. Full targeted suite green (73 files, 1205 tests); oxfmt/oxlint clean; max-lines ratchet and config-doc baseline verified. * refactor(ai): simplify bounded continuation ownership and strengthen proof * fix(plugins): queue compatibility removals pending reader migration --------- Co-authored-by: Patrick Erichsen <[email protected]>
What Problem This Solves
Continuation replay re-sanitizes tool-call ids for provider compatibility (
normalizeOpenAIResponsesToolCallIdsinembedded-agent-helpers), so afunction_call'scall_idthe client echoes back on round N+1 never matched the rawcall_idthe continuation resolver cached straight from the provider's own response on round N — for any provider whose native tool-call ids aren't alreadycall_*/fc_*-shaped (e.g. Kimi K2, OpenRouter-style ids). Every such multi-round tool-calling turn permanently missed continuation and resent the whole conversation history on the next round.Split out of #128910 (see that PR's history for the full trace); this is the raw-ID reshape/restore half.
Why This Change Was Made
canonicalizeToolCallIdreshapes both sides of the comparison through the exact same transform replay applies (normalizeOpenAIResponsesFunctionCallId, pairingcall_idwith the item's ownidfirst), and only treats the ids as equal when they canonicalize to the same value — fail-closed for an unrelated id change. The wire-bound delta then gets the raw providercall_idrestored (restoreRawCallIdsInDelta) before it's sent, so a server that reconstructs continuation history from its own cached copy of the raw response still sees afunction_call_outputwhosecall_idmatches thefunction_callit cached, instead of an orphaned id it silently drops.Two replay shapes besides the agent-reshaped one needed the same treatment, both caught by review and now covered:
call_id/idpair — now canonicalizes to the same value as the cached side.replayResponsesItemIds:false(e.g. ChatGPT-Responses) omitsfunction_call.idfrom the wire entirely while keeping the rawcall_id— the comparison now accepts either the paired or the id-less canonical form as "unchanged."Depends on #128633 (
compat.supportsResponsesContinuation), merged intomainon September 15 — that's what makes this reshape+restore path reachable at all, on a compat/proxy endpoint.Evidence
openai-responses-client.continuation-noncanonical-id.integration.test.ts: real loopback HTTP+SSE server, no SDK mocking, proves the reshape+restore path end-to-end. Real captured wire output:src/agents/embedded-agent-helpers/openai.test.ts(the realnormalizeOpenAIResponsesToolCallIdssuite this fix mirrors): 10/10.packages/ai/src/transports/suite green.Production LOC
reviewMetrics: production net +335 lines (82 pure-move lines discounted); tests net +1002. The 82-line move fromsrc/agents/embedded-agent-helpers/openai.tsplaces ID shaping in a shared helper becausepackages/aicannot import fromsrc/agents. The remaining growth keeps raw call ownership across superseding responses, verifies earlier call/result identities before dropping cached history, and rebuilds pending owners after a full-history retry. The existing state only records the latest response, so it cannot represent unresolved calls across response turns; the extra state and owner checks live in the shared resolver used by HTTP and WebSocket.Landing follow-up
previous_response_idis unsupported; this endpoint cannot provide successful continuation proof. No other configured live endpoint supports this test.dc1089e582ddfeded61be4398b858a96dbe6ca90is running: https://github.com/openclaw/openclaw/actions/runs/36505192016. The requiredopenclaw/ci-gateremains pending until all checks complete.