Skip to content

fix(agents): recover tasks when Responses streams end mid-tool-call - #144583

Merged
steipete merged 1 commit into
mainfrom
codex/recover-responses-eof-tools
Sep 11, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/recover-responses-eof-tools

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users running agent tasks would see a generic "Agent run failed" error when an OpenAI Responses stream ended while a tool call was still unfinished, even though the task could continue from its saved transcript.

Why This Change Was Made

Recognize the transport's exact premature-end error in the shared incomplete-stream matcher, so existing transient continuation and settled-result finalization can handle it. Completed responses with inconsistent tool calls remain excluded; partial tool arguments are never admitted for execution.

User Impact

Tasks can recover from this interrupted stream without resubmitting the original request or automatically repeating completed tool actions. The existing retry budget and cancellation rules continue to apply.

Evidence

  • The synthetic regression feeds an unfinished call through the real Responses stream parser and AgentSession. Before the fix the session ended without an answer; afterward it recovers, the earlier tool executes exactly once, its result survives, and the unfinished call never executes.
  • Embedded-runner coverage verifies continuation from the existing transcript and preservation of settled-result finalization context. Classification coverage distinguishes premature EOF from an inconsistent completed response.
  • 1,342 focused tests passed across the session regression, retry/classification corpus, embedded recovery, and finalization-context suites.
  • The complete changed-file check passed, including core and test typechecking, lint, formatting, and repository guards. Independent blocking-issue review passed.
  • The original stream cutoff was observed in runtime logs, but its upstream cause remains unknown because raw SSE events were not recorded. No live deployment is claimed by this PR.

@clawsweeper

clawsweeper Bot commented Sep 11, 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 maintainer Maintainer-authored PR labels Sep 11, 2026
@steipete
steipete marked this pull request as ready for review September 11, 2026 02:11
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 11, 2026, 11:14 AM ET / 15:14 UTC (Revision 2).

ClawSweeper review

What this changes

Recognizes Responses streams interrupted during tool calls as recoverable failures, with documentation and regression coverage for preserving completed work.

Merge readiness

✅ Ready for maintainer review

The refreshed review finds no blocking defects at the unchanged head. The recovery gap remains on current main, so this protected maintainer PR remains useful.

Priority: P2
Reviewed head: bc09908c208b27871ce0950e37e41175560f8fbd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused shared-owner repair with useful regression coverage and no blocking findings; supplied validation is synthetic and CI-based.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer context exempts this PR from the external-contributor proof gate. Its parser-to-AgentSession regression is synthetic coverage of recovery and tool non-execution; no after-fix live transport run is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer context exempts this PR from the external-contributor proof gate. Its parser-to-AgentSession regression is synthetic coverage of recovery and tool non-execution; no after-fix live transport run is claimed.
Evidence reviewed 8 items Current main still lacks the recovery match: The fetched main matcher does not recognize the exact unresolved-tool EOF message; the PR adds that specific alternative without matching completed-response inconsistencies.
Transport contract and implementation boundary: The repository-owned parser checks caller cancellation before throwing the exact EOF error for active tool calls. Completed responses validate unresolved identities separately. The new test directly imports this parser; the changed behavior does not depend on the sibling Codex implementation.
Existing recovery owners consume the matcher: Transient retry evidence and settled-turn finalization both consume the shared matcher. The embedded recovery path checks interruption conditions and rechecks cancellation after waiting before continuing the existing transcript.
Findings None None.
Security None None.

How this fits together

OpenClaw’s Responses transport turns streamed model events into assistant messages and tool calls. The shared failure classifier determines whether the agent continues its existing transcript or reports a terminal failure.

flowchart TD
  A[Responses stream] --> B[Stream parser]
  B --> C[Completed tool calls]
  B --> D[Premature stream end]
  D --> E[Shared failure classifier]
  E --> F[Bounded transcript recovery]
  C --> F
  F --> G[Answer or terminal failure]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +17, Tests +115, Docs +2. Total +134 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 2 18 1 +17
Tests 4 117 2 +115
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 137 3 +134

Review metrics

Metric Value Why it matters
Production versus regression coverage production +2 net lines; tests and test support +130 net lines Production growth is limited to explaining the matcher change; the added coverage checks recovery across classification, finalization, and session execution.

Technical review

Best possible solution:

Keep premature EOF recognition in the shared classifier so existing bounded recovery preserves settled work while terminal tool-validation failures remain excluded.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes a deterministic path: end the Responses event sequence with an active tool call and no terminal event; current main emits an error that its recovery matcher misses. No runtime reproduction was executed in this review.

Is this the best way to solve the issue?

Yes. Extending the existing shared matcher is a narrow repair that reaches both retry and finalization consumers without changing transport admission or adding another recovery policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against af73c58582b5.

Labels

Label justifications:

  • P2: This repairs a bounded task-recovery failure triggered by premature Responses stream termination.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer context exempts this PR from the external-contributor proof gate. Its parser-to-AgentSession regression is synthetic coverage of recovery and tool non-execution; no after-fix live transport run is claimed.

Evidence

What I checked:

  • Current main still lacks the recovery match: The fetched main matcher does not recognize the exact unresolved-tool EOF message; the PR adds that specific alternative without matching completed-response inconsistencies. (src/agents/failover/message-patterns.ts:43, af73c58582b5)
  • Transport contract and implementation boundary: The repository-owned parser checks caller cancellation before throwing the exact EOF error for active tool calls. Completed responses validate unresolved identities separately. The new test directly imports this parser; the changed behavior does not depend on the sibling Codex implementation. (packages/ai/src/transports/openai-responses-stream-internal.ts:710, bc09908c208b)
  • Existing recovery owners consume the matcher: Transient retry evidence and settled-turn finalization both consume the shared matcher. The embedded recovery path checks interruption conditions and rechecks cancellation after waiting before continuing the existing transcript. (src/agents/embedded-agent-runner/run/attempt-recovery.ts:347, bc09908c208b)
  • Behavior-focused regression coverage: The complete new test feeds synthetic unfinished-call events through the real parser and AgentSession, asserting a recovered answer, exactly one tool execution, no unfinished tool completion, and preservation of the settled result. This is supplemental synthetic coverage, not a live transport run. (src/agents/sessions/agent-session-responses-eof.test.ts:21, bc09908c208b)
  • Release check: The supplied latest release, v2026.9.4, also lacks this exact EOF alternative in its shared matcher; no shipped fix for this recovery gap was established. (src/agents/failover/message-patterns.ts:43, 3a9d69db306c)
  • Re-review continuity and supplied validation: The previous completed review covered the same head with no findings. The maintainer request confirms unchanged code and reports completed preparation and CI; the captured body reports 1,342 focused tests and explicitly disclaims a live deployment. Tests were not executed during this read-only review, and the introduced diff passed git diff --check. (bc09908c208b)

Likely related people:

  • weiqinl: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-11T02:19:46.207Z sha bc09908 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The native merge guard requires a fresh review because the previous review expired overnight. The head remains bc09908; exact-head CI and native preparation have passed, and no code changed after the previous clean review.

@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 2bfa3fe into main Sep 11, 2026
254 checks passed
@steipete
steipete deleted the codex/recover-responses-eof-tools branch September 11, 2026 15:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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