Skip to content

fix(ai): avoid retrying conflicting Responses terminal statuses - #149242

Merged
RomneyDa merged 3 commits into
mainfrom
openclaw/fix-responses-terminal-consistency
Sep 21, 2026
Merged

RomneyDa merged 3 commits into
mainfrom
openclaw/fix-responses-terminal-consistency

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: Responses sessions start an output-limit continuation when an unfinished tool call is followed by response.incomplete and max_output_tokens, even though the response explicitly says it completed, failed, or was cancelled.

User Impact

Sessions no longer make an unnecessary continuation request for contradictory terminal statuses. Genuine output-limit recovery still preserves settled tool results without repeating work, including compatible endpoints that omit response.status. No configuration or migration is required.

Why This Change Was Made

Retain the canonical terminal stop reason before tool validation replaces the message-level reason with an error, and require that recorded reason to be length alongside the existing incomplete-event and output-token-limit evidence. Tool settlement, session retry, and embedded recovery consume the same predicate. Refusal and cancellation precedence remain unchanged; partial arguments never become executable.

Related: #149071. This independent main-targeted fix does not include or depend on that PR’s earlier validation/drain change.

Evidence

  • Original regression proof: 10 managed-transport cases and five real AgentSession.prompt cases failed before the fix and passed afterward.
  • September 21 refresh: rebased onto main be3d22b1745917a2c03a1adb999ed51960a3c275. Resolved the session-table conflict by preserving all landed identity-conflict cases alongside the terminal-status matrix. Range-diff confirms the four-line production change is unchanged; no unrelated CI patches or other PR features were added.
  • Fresh focused proof: 228 tests passed across eight files covering terminal mapping, managed SSE transport, async settlement, loopback WS/SSE continuation and cache behavior, embedded accounting, and session recovery. The loopback tests used NO_PROXY=127.0.0.1,localhost for fixture servers. The original seven-file run took 37.69 seconds; the newly covered embedded-recovery suite passed all 89 tests. Per-file single-worker costs are recorded below.
  • Fresh independent autoreview inspected the final working-tree repair at P0–P2; its sole staging-only finding was resolved by staging the reviewed named fixture data. No code findings remain. git diff --check passed. The eight-file changed-check pass and incremental recovery-fixture pass both succeeded, covering all nine changed files.
  • Accepted ClawSweeper P2: updated the shared outputLimitDetails fixture with the producer’s stopReason: "length" and kept negative event/reason cases otherwise coherent. Reproduced five failures locally and in the previous CI job; all 89 embedded-recovery tests pass after the repair. Retry budgets and production recovery logic are unchanged.
  • Current head: ebd190517738e135f291cdcc6a71fc4020aa573a. Exact-head CI succeeded, including openclaw/ci-gate; the repository watcher reported GREEN. ClawSweeper rated this head platinum hermit (4/6) with the prior P2 resolved and no remaining actionable findings.
  • Additional boundary proof: all nine existing embedded transcript/projection integration tests passed (36.95 seconds wall), including the transport-generated output-limit recovery path.
  • Coverage caveat: CodeQL completed NEUTRAL with a warning that 16 main-branch scan configurations were absent, so introduced-alert comparison is incomplete. This is an advisory, not a failed CI check.
  • Contract checked against OpenAI SDK 7.15.0 source: Response.status is optional and explicit statuses remain authoritative. No authenticated live-provider testing is claimed.
Per-file test cost

Each listed file was run separately with NO_PROXY=127.0.0.1,localhost node scripts/run-vitest.mjs <file> --maxWorkers=1, measured by /usr/bin/time. Wall time includes runner startup and uses the existing compiler cache; no new Gateway boots or sleeps were introduced. CI seconds below sum reported passing-case durations from successful run 35585345477; they exclude job setup and are not whole-job wall times.

File Local wall seconds CI case seconds
packages/agent-core/src/agent-loop.async-tools.test.ts 4.64 1.816
packages/agent-core/src/agent-loop.responses-continuation.test.ts 1.91 0.056
packages/ai/src/providers/openai-chatgpt-responses.cache.test.ts 2.10 0.371
packages/ai/src/transports/openai-responses-client.terminal-error.test.ts 1.74 0.037
src/agents/embedded-agent-runner/run/attempt-execution-phase.test.ts 8.31 1.722
src/agents/sessions/agent-session-responses-eof.test.ts 15.47 4.016
src/agents/embedded-agent-runner/run/attempt-recovery.test.ts 7.48 0.349

Worked on by: @RomneyDa

Work sessions

@clawsweeper

clawsweeper Bot commented Sep 15, 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 agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 15, 2026
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/fix-responses-terminal-consistency branch from 107e19d to b1f0370 Compare September 15, 2026 15:53
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 15, 2026 15:55
@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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 6:30 AM ET / 10:30 UTC (Revision 6).

ClawSweeper review

What this changes

The PR preserves the interpreted Responses terminal status so contradictory completion signals cannot trigger output-limit retries, and updates recovery regression coverage.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main and the latest release. The prior fixture finding is resolved, and this review found no remaining actionable correctness or security defects.

Priority: P2
Reviewed head: ebd190517738e135f291cdcc6a71fc4020aa573a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant regression coverage, documented validation costs, and the prior fixture defect resolved.
Proof confidence 🌊 off-meta tidepool Not applicable: This bot-authored PR is exempt from the external-contributor proof gate. Supplied evidence covers terminal mapping, injected-event session recovery, and loopback transport propagation; it does not claim authenticated live-provider verification.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This bot-authored PR is exempt from the external-contributor proof gate. Supplied evidence covers terminal mapping, injected-event session recovery, and loopback transport propagation; it does not claim authenticated live-provider verification.
Evidence reviewed 9 items Introduced production change: The pinned introduction delta adds the canonical stop reason to terminal diagnostics and requires length in the existing output-limit predicate. No independent retry owner is introduced.
Current-main necessity: Current main still accepts incomplete-event and max-output-token evidence without checking the interpreted terminal status. Both changed production files are unchanged between the pinned merge base and fetched main.
Latest-release check: The supplied latest release, v2026.9.5, also contains the predicate without the canonical stop-reason guard; this change is not already shipped there.
Findings None None.
Security None None.

How this fits together

OpenClaw’s Responses transport converts provider events into assistant messages and terminal diagnostics. Agent execution and session recovery use those facts to decide whether to settle tools and continue sampling.

flowchart TD
  A[Provider response events] --> B[Interpret terminal status]
  B --> C[Record terminal facts]
  C --> D[Validate tool completion]
  D --> E{Coherent output limit?}
  E -->|Yes| F[Settle tools and bounded continuation]
  E -->|No| G[Normal terminal error handling]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +4, Tests +56. Total +60 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 2 4 0 +4
Tests 7 82 26 +56
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 86 26 +60

Review metrics

None.

Technical review

Best possible solution:

Keep terminal-status interpretation in the existing transport owner and use its recorded result consistently for bounded recovery.

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

Yes, from source: an unfinished tool followed by response.incomplete/max_output_tokens and an explicit conflicting status still satisfies main’s recovery predicate. The PR supplies matching regression cases; this review did not execute them.

Is this the best way to solve the issue?

Yes. Recording the existing canonical interpretation before tool validation and checking it in the shared predicate is a narrow repair that preserves omitted-status compatibility.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes unnecessary continuation requests for contradictory provider terminal events while preserving ordinary output-limit recovery.
  • 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: This bot-authored PR is exempt from the external-contributor proof gate. Supplied evidence covers terminal mapping, injected-event session recovery, and loopback transport propagation; it does not claim authenticated live-provider verification.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • VACInc: 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 (5 earlier review cycles)
  • reviewed 2026-09-15T16:02:30.618Z sha b1f0370 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T16:48:02.918Z sha b1f0370 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-21T09:35:29.019Z sha 0f46e6e :: needs changes before merge. :: [P2] Update the embedded recovery fixture for the stricter predicate
  • reviewed 2026-09-21T09:56:09.125Z sha ebd1905 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-21T10:04:28.668Z sha ebd1905 :: needs maintainer review before merge. :: none

roboclaw-bot and others added 2 commits September 21, 2026 09:25
Keep the canonical terminal stop reason before incomplete-tool validation overwrites the message error. Require coherent output-limit evidence for continuation and preserve status-absent compatibility.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
OpenClaw-Publication: 856c94de-d066-44dc-9f3f-b929b908bbec
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/fix-responses-terminal-consistency branch from b1f0370 to 0f46e6e Compare September 21, 2026 09:27
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Rebased onto current main and resolved the session regression-table conflict while preserving both landed identity-conflict coverage and the terminal-status cases. Production fix unchanged; fresh focused proof: 139 passing tests, independent autoreview P0–P2 scoped-clean. Updated details are in the PR body.

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 21, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Addressed the accepted P2 in 78ac61bd61a3407d9af48f047aff0ca16f08bdd8: the embedded output-limit fixture now includes the canonical length stop; negative event/reason cases retain the other positive preconditions. The five failures were reproduced locally and in CI, then all 89 embedded-recovery tests passed. Fresh independent autoreview is P0–P2 scoped-clean. Per-file single-worker test costs and the finding disposition are now in the PR body.

@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Preserve the canonical length stop in positive output-limit fixtures and keep negative event/reason cases otherwise coherent. This repairs the five failures reproduced through recoverEmbeddedRunAttempt after the main refresh.

Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/fix-responses-terminal-consistency branch from 78ac61b to ebd1905 Compare September 21, 2026 09:48
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Finalized the accepted fixture repair in ebd190517738e135f291cdcc6a71fc4020aa573a. Canonical diagnostic data is now a named fixture rather than an unsafe array-index access; strict test typechecking, applicable changed checks, and all 89 embedded-recovery cases pass. The reviewed working-tree repair is committed, both required coauthors are retained, and the PR body includes the P2 disposition and measured per-file test costs.

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 21, 2026
@RomneyDa
RomneyDa enabled auto-merge (squash) September 21, 2026 11:37
@RomneyDa
RomneyDa merged commit 9488ca1 into main Sep 21, 2026
179 checks passed
@RomneyDa
RomneyDa deleted the openclaw/fix-responses-terminal-consistency branch September 21, 2026 11:38
vincentkoc added a commit that referenced this pull request Sep 21, 2026
* commit '0883394977d1fb3af657635967f6e447bd7fff9a': (72 commits)
  fix(ui): await scheduled rail layout in focus test
  fix(cron): keep healthy active runs from delaying job lists (#154421)
  fix(plugins): prevent config conflicts during legacy plugin installation (#154539)
  perf(gateway): reduce repeated session-list work (#154551)
  fix(tasks): retain admitted work across list retries (#154338)
  perf(gateway): speed up transcript artifact downloads (#154726)
  chore(ui): refresh control ui locales (#154580)
  fix(release): keep two extended-stable months eligible (#154777)
  fix(tests): avoid avatar descriptor reuse race (#154747)
  perf(plugins): reduce callback scope overhead (#154625)
  fix(ui): include final request time in completed work summaries (#149240)
  fix(ai): avoid retrying conflicting Responses terminal statuses (#149242)
  fix: identify malformed Code Mode JavaScript as input errors (#149222)
  fix(doctor): settle imported JSONL transcript leftovers (#154413)
  fix(cloud): restore node bootstrap with bundled browser runtime (#154654)
  test(ui): await publication state notifications (#154768)
  fix(plugins): keep unchanged plugins running across metadata refreshes (#151281)
  fix: keep chat panel accessibility targets within each pane (#153478)
  fix: forced Gateway restarts cancel healthy subagent work (#154300)
  improve: reduce session delivery reader imports (#154740)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…claw#149242)

* fix(ai): avoid retrying conflicting Responses terminal statuses

Keep the canonical terminal stop reason before incomplete-tool validation overwrites the message error. Require coherent output-limit evidence for continuation and preserve status-absent compatibility.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>

* fix(ai): avoid retrying conflicting Responses terminal statuses

OpenClaw-Publication: 856c94de-d066-44dc-9f3f-b929b908bbec
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>

* test(agents): align output-limit recovery fixtures with terminal facts

Preserve the canonical length stop in positive output-limit fixtures and keep negative event/reason cases otherwise coherent. This repairs the five failures reproduced through recoverEmbeddedRunAttempt after the main refresh.

Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: RomneyDa <[email protected]>

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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.

2 participants