Skip to content

fix(ai): retain usage and provider errors after rejected Responses tool calls - #149071

Merged
RomneyDa merged 1 commit into
mainfrom
openclaw/fix-responses-rejection-terminal-facts
Sep 29, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
openclaw/fix-responses-rejection-terminal-facts

Conversation

@roboclaw-bot

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

Copy link
Copy Markdown
Collaborator

Related: #147040, #147611

What Problem This Solves

Fixes: Responses tool-call rejection can discard final token usage and provider failure details when an item completes with an unfinished status or malformed JSON arguments.

User Impact

Rejected and subsequent tool calls remain non-executable, while already-admitted work settles and reported accounting is retained. Malformed JSON is neither repaired nor automatically classified as token exhaustion. No configuration or migration is required.

Why This Change Was Made

Extend the existing admission latch to retain completion-validation errors and drain terminal facts before reporting the rejection. Cancellation and provider refusal/failure retain their precedence. Runner recovery and terminal diagnostic contracts are unchanged.

The September 21 conflict resolution retains main’s output-identity tracking and parse-once argument selection. The terminal validator is now unchanged from main; no competing argument-selection path remains. No unrelated baseline-CI repair is included.

Evidence

  • Original regressions reproduced lost usage, lost provider/cancellation details, and missing rejection details at EOF. Coverage includes incomplete/in-progress/malformed/truncated completions, provider failure/filtering, EOF, and cancellation.
  • Refreshed transport and real agent-loop proof: seven focused suites, 150 tests passed. With --maxWorkers=1, the combined runner wall was 5.07 seconds (Vitest 4.12 seconds). An admitted async call settles; rejected and later calls never execute.
  • Fresh conflict-resolution autoreview: P0–P2 scoped-clean. The unchanged parser was supplied as dependency evidence; malformed streamed JSON returns null rather than escaping the validation latch.
  • Refreshed head: 81d78bdacb0d74656a383e04448942af808b8627; base: be3d22b1745917a2c03a1adb999ed51960a3c275. git range-diff confirms unchanged regression tests and the deliberate removal of the old argument-selection relocation in favor of main’s parse-once owner. Whitespace checks pass.
  • node scripts/check-changed.mjs --base be3d22b1745917a2c03a1adb999ed51960a3c275 --staged passed, including production/test typechecks, formatting, lint, dead-export scans, and applicable guards.
  • Individual changed-file runs with --maxWorkers=1 also passed: terminal-error 42 cases / 1.79 s wall, terminal-recovery 38 cases / 1.72 s, real-loop rejection 3 cases / 1.82 s. These reruns overlap the 150-case suite and are not additional test counts.
  • Exact-head CI run 35583975711, attempt 1, completed successfully: 92 successful jobs, 17 skipped, zero pending or failed. Both required openclaw/ci-gate checks pass, and the repository watcher returned GREEN. CodeQL’s neutral advisory is not a failed check.
  • ClawSweeper’s refreshed review explicitly reviews this head and rates it platinum hermit (4/6), with no actionable code/security findings or unresolved review threads. Ready for maintainer review; not merged.

These are synthetic transport and real agent-loop boundary tests, not live-provider proof. No visual changes.

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 blocked

Automated review did not run, so no review verdict was produced.

Reason: The input-safety check could not safely complete for this revision.

ClawSweeper will not retry this unchanged revision.

Next step: No contributor action is requested. Maintainers should inspect the linked workflow run.

View the workflow run.

@roboclaw-bot roboclaw-bot reopened this Sep 15, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 15, 2026 12:18
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@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, 5:40 AM ET / 09:40 UTC (Revision 5).

ClawSweeper review

What this changes

The Responses transport retains token usage and provider errors after rejecting unfinished or malformed tool calls while preventing later calls from executing.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main and the latest release still lose terminal facts for these rejection paths. The refreshed patch preserves the existing parser and identity checks, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 81d78bdacb0d74656a383e04448942af808b8627

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful regression coverage and no identified blocking defect; reported execution remains supplemental to this source review.
Proof confidence 🌊 off-meta tidepool Not applicable: The bot-authored PR is exempt from the external-contributor proof gate. Its reported tests exercise the Responses processor and real agent loop with synthetic streams, including retained usage and settlement; they do not establish live-provider behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The bot-authored PR is exempt from the external-contributor proof gate. Its reported tests exercise the Responses processor and real agent loop with synthetic streams, including retained usage and settlement; they do not establish live-provider behavior.
Evidence reviewed 8 items Pinned introduction and preserved owners: The merge-base-to-head diff changes the rejection latch and its regression coverage. Argument selection, terminal validation, and output-identity tracking remain with their existing owners.
Still necessary on current main: Current main has the same production baseline as the pinned merge base: only status=incomplete activates draining, and other completion-validation errors escape before terminal accounting. The terminal validator has no difference between current main and this head.
Latest release retains the defect: The source at the supplied v2026.9.5 release commit also uses the incomplete-only latch and directly invokes completion validation before reading the terminal response. The release blob was inspected through GitHub after local historical-object access failed.
Findings None None.
Security None None.

How this fits together

OpenClaw’s Responses transport converts provider stream events into assistant messages and executable tool completions. Its terminal accounting and errors feed the agent loop’s settlement and recovery decisions.

flowchart TD
  A[Provider stream] --> B[Responses transport]
  B --> C{Tool completion valid?}
  C -->|Yes| D[Agent tool execution]
  C -->|No| E[Close further tool admission]
  E --> F[Collect terminal usage and errors]
  D --> G[Settle admitted work]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +11, Tests +178. Total +189 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 31 20 +11
Tests 3 191 13 +178
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 222 33 +189

Review metrics

Metric Value Why it matters
Production versus regression coverage production net +11 lines; tests net +178 lines The small production increase extends the existing rejection latch; most growth exercises terminal outcomes and async settlement.

Technical review

Best possible solution:

Keep strict tool validation and the existing admission owner while retaining terminal accounting and authoritative provider failures on rejected responses.

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

Yes, from source: an invalid completed tool call or in-progress item completion throws on current main before a later terminal response can supply usage and provider errors. Tests were inspected but not executed during this read-only review.

Is this the best way to solve the issue?

Yes. Extending the existing rejection latch is a narrow repair that retains the canonical parser, identity checks, and terminal-error projection.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs accounting and error reporting for bounded Responses tool-rejection cases without adding configuration or changing normal successful calls.
  • 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 bot-authored PR is exempt from the external-contributor proof gate. Its reported tests exercise the Responses processor and real agent loop with synthetic streams, including retained usage and settlement; they do not establish live-provider behavior.

Evidence

What I checked:

  • Pinned introduction and preserved owners: The merge-base-to-head diff changes the rejection latch and its regression coverage. Argument selection, terminal validation, and output-identity tracking remain with their existing owners. (packages/ai/src/transports/openai-responses-stream-internal.ts:675, 81d78bdacb0d)
  • Still necessary on current main: Current main has the same production baseline as the pinned merge base: only status=incomplete activates draining, and other completion-validation errors escape before terminal accounting. The terminal validator has no difference between current main and this head. (packages/ai/src/transports/openai-responses-stream-internal.ts:318, d2580ac064bc)
  • Latest release retains the defect: The source at the supplied v2026.9.5 release commit also uses the incomplete-only latch and directly invokes completion validation before reading the terminal response. The release blob was inspected through GitHub after local historical-object access failed. (packages/ai/src/transports/openai-responses-stream-internal.ts:676, ec9c1a13db89)
  • Error precedence and admission fencing: Rejected calls skip subsequent nonterminal events; terminal accounting is collected before the saved rejection is thrown. Provider failure/error events remain authoritative, cancellation is checked, and the client projects the final failure through its existing error owner. (packages/ai/src/transports/openai-responses-stream-internal.ts:689, 81d78bdacb0d)
  • Focused regression coverage and reported execution: The managed-client test covers four rejection forms across seven endings, including usage, provider failure, cancellation, and EOF. The new agent-loop cases verify one admitted async call settles and later calls never execute. The captured PR body reports 150 passing tests across seven suites in 5.07 seconds wall time and explicitly identifies synthetic transport coverage; this reviewer did not execute tests. (packages/ai/src/transports/openai-responses-client.terminal-error.test.ts:56, 81d78bdacb0d)
  • Implementation boundary: The changed owner consumes OpenAI Responses events inside OpenClaw’s built-in transport. Repository documentation explicitly distinguishes the native Codex harness’s separate Responses loop; this patch supplies no affirmative dependency on that harness. Public docs: docs/providers/openai/models.md. (docs/providers/openai/models.md:125, 81d78bdacb0d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SunnyShu0925: 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 (4 earlier review cycles)
  • reviewed 2026-09-15T12:32:30.177Z sha 060b447a22cf335e0ac8a4c3cdc38641ccd6029a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T13:14:10.999Z sha 060b447a22cf335e0ac8a4c3cdc38641ccd6029a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T13:35:09.891Z sha b16ee3b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T15:11:38.700Z sha b16ee3b :: needs maintainer review before merge. :: none

Drain terminal accounting after rejected item completions without admitting later tools or replacing the original validation error.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/fix-responses-rejection-terminal-facts branch from b16ee3b to 81d78bd Compare September 21, 2026 09:33
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Refreshed onto current main, preserving output-identity tracking and parse-once argument selection. The terminal validator now remains unchanged from main. All 150 focused tests pass and the fresh dependency-grounded autoreview is clean. Updated scope and verification evidence 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.

Re-review progress:

@RomneyDa
RomneyDa merged commit a1a0ec6 into main Sep 29, 2026
156 checks passed
@RomneyDa
RomneyDa deleted the openclaw/fix-responses-rejection-terminal-facts branch September 29, 2026 02:24
roboclaw-bot added a commit to lraesly/openclaw that referenced this pull request Sep 29, 2026
Merge canonical main after openclaw#149071 landed and PR147611 became conflicting. Preserve the published PR head and original contributor ancestry. Keep canonical transport drain and current retry-policy ownership unchanged.

Retain both the bounded terminal-coherence tests and the landed rejection-ending fencing matrix. Adapt the real Gateway/Responses/file-tool proof to allow early malformed item completion only after coherent terminal evidence, retain all unsafe negatives, and add the no-terminal EOF boundary.

Co-authored-by: Dallin Romney <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
…aw#149071)

Drain terminal accounting after rejected item completions without admitting later tools or replacing the original validation error.

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

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: M 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.

3 participants