Skip to content

fix(agents): OpenAI Responses turns repeat runtime context after every tool call - #169632

Merged
steipete merged 1 commit into
mainfrom
steipete/busy-easley-e93d2c
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/busy-easley-e93d2c

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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

  • Regression at the owning boundary (real AgentSession loop, scripted provider, OpenAI Responses route, production-shaped inter-session origin carrier, three tool rounds) in src/agents/sessions/agent-session-steering-context.test.ts.
    • Before the fix: expected [ 1, 2, 3, 4 ] to deeply equal [ 1, 1, 1, 1 ] (copies of the carrier visible per request; 4 persisted copies).
    • After the fix: one visible copy in every request, one persisted carrier.
  • The existing Anthropic renewal cases in the same file still pass unchanged (the carrier is renewed after tool results and extension context, and is not renewed across a new user message).
  • 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) and attempt-prompt-submit.foreground.test.ts (10) pass; pnpm tsgo:core, oxfmt --check, git diff --check clean.
  • Codex autoreview (P2): scoped-clean.
  • Production evidence (read-only transcript inspection): a subagent session persisted one 923-char runtime-context system update 107 times in a single turn, once after every tool result; its parent session showed identical runs of 24/6/45/11 carriers (~171 KB).

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.

…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.
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 12, 2026
@steipete
steipete marked this pull request as ready for review October 12, 2026 05:26
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Successive requests contain 1, 2, 3, and 4 copies of the runtime-context carrier.
  • After: All four requests contain one copy, and the session retains one carrier.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused repair with a meaningful session regression; confidence in executed behavior is limited to the supplied harness results.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored classification exempts ordinary contributor proof; supporting evidence exercises continuation preparation and LLM-bound messages through AgentSession, with no live after-fix Responses request claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Tool-heavy Responses turns accumulate identical runtime facts, wasting context capacity and input tokens.
Reason: The reported production duplication matches the current source path, and the existing feature owner supplies a narrow repair preserving intended Anthropic behavior.

Regression provenance

Possible 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
Reviewed head: fee0f53e0b94961b43304f026c58d4ea34314abd

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No after-fix shipped Gateway or serialized network-request trace is supplied; the recorded regression covers the real session loop with a scripted provider.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Continuation runtime-context renewal changes intended behavior with a stated reason (46ab36a: Renew Anthropic turn-scoped facts after tool results and extension context clear them; native Responses later inherited this continuation path.)
  • Responses context documentation keeps the original intent (18c801d: Keep current context before tool rounds so complete prior input remains a reusable continuation prefix.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 46ab36a adds src/agents/embedded-agent-runner/run/attempt-permission-prompt.ts:140 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 46ab36a493ac; files: src/agents/embedded-agent-runner/run/attempt-permission-prompt.ts)
  • Markus Hartung: Raw commit 18c801d adds docs/concepts/context.md:164 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 18c801daa116; files: docs/concepts/context.md)

PR surface

Source +4, Tests +84, Docs +1. Total +89 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 28 24 +4
Tests 2 87 3 +84
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 117 28 +89

Review metrics

Metric Value Why it matters
Production versus tests Production +4 net lines; tests +84 net lines The production growth is a route condition around existing renewal, and the test growth protects the multi-round duplication regression.

Labels

Label changes:

  • add P2: Repeated runtime context wastes input and context capacity in tool-heavy Responses turns, without evidence of a core outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Repeated runtime context wastes input and context capacity in tool-heavy Responses turns, without evidence of a core outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 12, 2026, 1:32 AM ET / 05:32 UTC.

@steipete
steipete merged commit acba98b into main Oct 12, 2026
188 of 190 checks passed
@steipete
steipete deleted the steipete/busy-easley-e93d2c branch October 12, 2026 05:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant