Skip to content

fix(agents): resume output-limited tool calls without repeating work - #148440

Merged
steipete merged 2 commits into
mainfrom
codex/fix-incomplete-tool-continuation
Sep 14, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-incomplete-tool-continuation

Conversation

@steipete

@steipete steipete commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes tasks stopping with an unfinished-tool-call error when an OpenAI Responses request reaches its output limit, even though completed work can be retained.

User Impact

Tasks continue from completed tool results within the existing retry budget. The truncated call never executes. Stop, provider refusals, and intentional tool termination still prevent continuation. No configuration or migration is required.

Why This Change Was Made

The session already owns continuation, but output-limit failures bypassed it and reached the guard against replaying an entire attempt. This change reuses session continuation after admitted tools settle, preserving their results and the original failure in durable history. The provider's bounded incomplete reason distinguishes this case from refusals and inconsistent terminal responses.

Cancellation and tool outcomes take precedence over recovery. The original usage-bearing terminal is recorded once, and retry accounting resets only when a response completes, so streamed tool fragments cannot reset the budget. The outer replay guard remains unchanged.

Evidence

  • The original output-limit regression failed before the fix. Coverage includes same-response async settlement, no repeated completed tool, no truncated-call execution, retry exhaustion, cancellation during recovery and critical tool termination, disabled retries, refusals, and invalid terminals.
  • 205 focused tests passed across core scheduling, session recovery, embedded terminal accounting, and the full memory-index file. CI exposed an extra zero-usage terminal during development; the original accounting assertions now pass unchanged.
  • A memory queue fixture's background startup catchup could consume its controlled sync mocks. That fixture now uses the existing writable CLI purpose and retains its rejection, recovery, and indexing assertions.
  • Full build and selected changed checks passed; independent Codex review through P2 is scoped-clean and deslop is complete. The final rebase preserved both reviewed commits exactly, verified with git range-diff.
  • Final CI run 34894493720, attempt 2, passed on b401f47679e38d251eba8343121ef7edab4feed4. Its first attempt rejected an unchanged plugin-inspection fixture's config before inspection. The single failed-shard rerun passed on Ubuntu under existing workflow policy; the original Blacksmith rejection remains unexplained. Test assertions, setup, timeouts, and retry policy were unchanged. The original failure and independent controls are retained separately.
  • Shared CI blockers were fixed by test: route provider integration and wizard recovery tests correctly #148504, merged as 867e655d51d892c47ee68fc7f02c7e8ca0a5628d, before the final rebase.
  • Provider truncation is covered through the real Responses parser and AgentSession with deterministic fixtures; no live provider truncation was induced.

@clawsweeper

clawsweeper Bot commented Sep 14, 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: L maintainer Maintainer-authored PR labels Sep 14, 2026
@steipete
steipete marked this pull request as ready for review September 14, 2026 18:17
@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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 4:49 PM ET / 20:49 UTC (Revision 4).

ClawSweeper review

What this changes

The PR lets output-limited OpenAI Responses requests continue from settled tool results, preserves cancellation and retry accounting, and adds regression coverage and documentation.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and the latest release lack this recovery classification. No actionable correctness or security defect was found in the introduced changes; this maintainer-authored PR should remain open for normal landing.

Priority: P2
Reviewed head: b401f47679e38d251eba8343121ef7edab4feed4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused recovery repair with meaningful cancellation, accounting, and retry-limit coverage and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Available coverage connects the real Responses parser to session recovery using deterministic fixtures; it does not establish live provider truncation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Available coverage connects the real Responses parser to session recovery using deterministic fixtures; it does not establish live provider truncation.
Evidence reviewed 10 items Pinned PR identity: The live REST response confirms the PR remains open and unmerged at the reviewed head, with base 867e655. Review used the merge-base-to-head changes, not current-main endpoint drift.
Current main still needs the fix: Current main delegates exclusively to the generic retry classifier and removes a trailing assistant message; it lacks the output-limit-specific continuation path.
Latest release check: The retry owner at the supplied latest release, v2026.9.4, likewise lacks the new output-limit classification. No shipped replacement was established.
Findings None None.
Security None None.

How this fits together

OpenClaw’s built-in agent loop turns model responses into tool executions and recorded results. The session recovery owner uses those results to continue an interrupted task without replaying the original request.

flowchart TD
  A[Model response stream] --> B{Output limit interrupts a tool call?}
  B -->|Yes| C[Settle admitted tools]
  C --> D[Record results and terminal usage]
  D --> E{Cancelled or intentionally stopped?}
  E -->|Yes| F[End run]
  E -->|No| G[Bounded session retry]
  G --> A
  B -->|Other failure| F
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +51, Tests +374, Docs +6. Total +431 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 7 95 44 +51
Tests 6 471 97 +374
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 572 141 +431

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +51 net lines; tests +374 net lines Production growth implements bounded recovery classification and settlement ordering; most growth protects failure-path behavior.

Technical review

Best possible solution:

Keep bounded continuation in the session owner, preserving settled results, durable failure history, cancellation, and existing tool admission checks.

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

Yes, from source: an incomplete-tool terminal caused by max_output_tokens bypasses current main’s session retry classifier. The regression fixtures model that path; this review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing session continuation preserves completed work without adding another retry owner or weakening the outer replay guard.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs a bounded agent-recovery failure triggered by output-limited tool generation.
  • 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 maintainer-authored PR is exempt from the external-contributor proof gate. Available coverage connects the real Responses parser to session recovery using deterministic fixtures; it does not establish live provider truncation.

Evidence

What I checked:

  • Pinned PR identity: The live REST response confirms the PR remains open and unmerged at the reviewed head, with base 867e655. Review used the merge-base-to-head changes, not current-main endpoint drift. (b401f47679e3)
  • Current main still needs the fix: Current main delegates exclusively to the generic retry classifier and removes a trailing assistant message; it lacks the output-limit-specific continuation path. (src/agents/sessions/agent-session-execution.ts:28, 5d461f09667b)
  • Latest release check: The retry owner at the supplied latest release, v2026.9.4, likewise lacks the new output-limit classification. No shipped replacement was established. (src/agents/sessions/agent-session-execution.ts:32, 3a9d69db306c)
  • Settlement and cancellation ordering: Output-limit handling waits for admitted executions before recording the original usage-bearing terminal. External cancellation changes that terminal to aborted; unanimous tool termination prevents retry. Existing tool preparation and final source-start admission checks remain in place. (packages/agent-core/src/agent-stream-response.ts:368, b401f47679e3)
  • Recovery boundary and regression coverage: The session tests exercise the real Responses parser with synthetic events and mocked model requests. They check retained results, no unfinished-call execution, retry exhaustion, cancellation, disabled retries, filtering, and intentional termination. This is OpenClaw’s own parser/session implementation; no Codex dependency contract is asserted. (src/agents/sessions/agent-session-responses-eof.test.ts:24, b401f47679e3)
  • Bounded diagnostic classification: Continuation requires an error with incomplete_tool_call, a max_output_tokens incomplete terminal, and no provider-refusal diagnostic. The terminal producer retains only enumerated incomplete reasons, mapping unknown values to unknown. (packages/ai/src/providers/openai-responses-terminal-usage.ts:15, b401f47679e3)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (3 earlier review cycles)
  • reviewed 2026-09-14T18:35:50.773Z sha e963845641d6436992afd941661ff28e287706a1 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-14T19:15:00.010Z sha 41ddd2a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-14T20:39:42.874Z sha a6cb27a115355ac07b5b32f3370d870d648dc5ef :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/fix-incomplete-tool-continuation branch from e963845 to 41ddd2a Compare September 14, 2026 19:08
@openclaw-barnacle openclaw-barnacle Bot added the extensions: memory-core Extension: memory-core label Sep 14, 2026
Continue from settled tool results after output-limit truncation while preserving cancellation, intentional tool termination, and bounded retries. Retain the provider incomplete reason and reset retries only after a complete response.
…overy

Persist the original output-limit terminal once after admitted tools settle, and keep cancellation ahead of critical tool-loop termination. Preserve the existing usage assertions and cover both event and result completion.

Isolate the memory queue rejection fixture from background startup catchup so its controlled sync mocks cannot be consumed by unrelated work.
@steipete
steipete force-pushed the codex/fix-incomplete-tool-continuation branch from a6cb27a to b401f47 Compare September 14, 2026 20:41
@steipete
steipete merged commit b99ccac into main Sep 14, 2026
330 of 335 checks passed
@steipete
steipete deleted the codex/fix-incomplete-tool-continuation branch September 14, 2026 22:10
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
…penclaw#148440)

* fix(agents): resume output-limited tool calls without repeating work

Continue from settled tool results after output-limit truncation while preserving cancellation, intentional tool termination, and bounded retries. Retain the provider incomplete reason and reset retries only after a complete response.

* fix(agents): preserve terminal accounting and cancellation during recovery

Persist the original output-limit terminal once after admitted tools settle, and keep cancellation ahead of critical tool-loop termination. Preserve the existing usage assertions and cover both event and result completion.

Isolate the memory queue rejection fixture from background startup catchup so its controlled sync mocks cannot be consumed by unrelated work.
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 extensions: memory-core Extension: memory-core 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: L 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