Repository navigation
fix(agents): OpenAI Responses turns repeat runtime context after every tool call - #169632
Conversation
…OpenAI Responses Continuation renewal re-queued the turn-scoped runtime-context system update after each tool result. That compensates for Anthropic in-history routes, where turn-scoped system messages carry clear_at "next_user_message" and tool results clear them. Native OpenAI Responses inherited the renewal when it gained in-history system updates, but its projection keeps every operator message visible, so each tool round stacked another full copy (one Team turn persisted the same carrier 107 times). Renew only on the Anthropic Messages route; other in-history routes keep the original carrier visible for the whole turn. Existing transcripts are not rewritten.
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR restricts runtime-context renewal to Anthropic Messages so Responses turns retain one carrier across tool calls. Example: A Responses turn executes three refresh tool calls.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR open: fetched main still duplicates runtime context across Responses tool rounds, and the patch fixes the producer without changing Anthropic renewal; no actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe embedded runner prepares continuation instructions, AgentSession records context messages, and provider serializers turn those messages into model input. flowchart LR
A[User turn] --> B[Embedded runner]
B --> C[AgentSession context]
C --> D[Continuation preparation]
D --> E[Responses serializer]
D --> F[Anthropic serializer]
E --> G[Model request]
F --> G
Technical reviewBest possible solution: Retain the original Responses carrier throughout each turn and renew it only where Anthropic clears it. Do we have a high-confidence way to reproduce the issue? Fetched main renews the carrier after each tool result and Responses serializes every retained copy; the author records the corresponding before/after regression, while this read-only review ran no tests. Is this the best way to solve the issue? The patch fixes duplicate creation at its owner, preserves provider-specific clearing semantics, and avoids filtering or rewriting existing history. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 31a46b005884. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +84, Docs +1. Total +89 across 4 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 12, 2026, 1:32 AM ET / 05:32 UTC. |
|
Merged via squash.
|
…OpenAI Responses (openclaw#169632) Continuation renewal re-queued the turn-scoped runtime-context system update after each tool result. That compensates for Anthropic in-history routes, where turn-scoped system messages carry clear_at "next_user_message" and tool results clear them. Native OpenAI Responses inherited the renewal when it gained in-history system updates, but its projection keeps every operator message visible, so each tool round stacked another full copy (one Team turn persisted the same carrier 107 times). Renew only on the Anthropic Messages route; other in-history routes keep the original carrier visible for the whole turn. Existing transcripts are not rewritten.
What Problem This Solves
Fixes: on native OpenAI Responses routes, every tool call in a turn re-appends the turn's whole runtime-context block (inter-session origin notice, exec/subagent/media facts, temporal context), so long tool-heavy turns accumulate dozens of identical model-visible copies.
User Impact
User impact: tool-heavy turns on OpenAI Responses carry the current runtime context once per user turn instead of once per tool round, so long code-mode or subagent turns stop burning context window and input tokens on duplicates. Anthropic in-history routes keep their existing behavior. Transcripts written before this change keep their duplicates until compaction; nothing rewrites history.
Why This Change Was Made
The continuation renewal was built for Anthropic in-history routes. There, turn-scoped system messages carry
clear_at: "next_user_message", and tool results are user-role, so each tool result clears the carrier and renewal keeps exactly one copy visible. When native OpenAI Responses later gained in-history system updates, it inherited that renewal. However, the Responses projection keeps every operator message as a developer/system input item and never clears turn-scoped ones, so each renewal stacked another visible copy.Renewal now runs only on the Anthropic Messages route, whose provider clears the carrier. Other in-history routes keep the original carrier visible for the whole turn and send it once. The prompt-update refresh between tool rounds is unchanged.
Observed on a production Gateway (OpenAI Responses): one subagent code-mode turn persisted the same 923-character carrier 107 times, once after every tool result. Its parent dashboard session had identical runs of 24, 6, 45 and 11 carriers (~171 KB). Inter-session origin context was only one passenger in that block: every runtime fact repeated the same way.
Evidence
src/agents/sessions/agent-session-steering-context.test.ts.expected [ 1, 2, 3, 4 ] to deeply equal [ 1, 1, 1, 1 ](copies of the carrier visible per request; 4 persisted copies).pnpm test src/agents/sessions/agent-session-steering-context.test.ts --maxWorkers=1: 12/12 passed, new test 193 ms, file 42.5 s wall (84% cold transform, pre-existing).attempt-session.test.ts(26) andattempt-prompt-submit.foreground.test.ts(10) pass;pnpm tsgo:core,oxfmt --check,git diff --checkclean.Not covered: no live OpenAI request in this PR; the boundary test asserts the provider-bound message list, and the Responses projection maps each operator message to one developer/system input item.