Skip to content

fix: continue agent tasks after temporary rate limits - #139397

Merged
steipete merged 4 commits into
mainfrom
codex/rate-limit-continuation
Sep 5, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/rate-limit-continuation

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #139312

What Problem This Solves

Temporary RPM/TPM limits could stop an agent after it had completed tools or written part of an answer, leaving the operator to restart useful work manually.

Why This Change Was Made

The shared attempt recovery owner waits with jittered exponential backoff, then injects a short continuation instruction against the existing transcript. The agent preserves completed work and inspects uncertain actions before deciding what to retry. The original user request is not appended again.

The default changes from three to up to eight continuations within the existing 90-second window, honoring pacing carried by provider errors. Prompt and assistant failure handlers retain profile/auth/fallback responsibilities; duplicate transient decisions and the special transport-drop counter are removed. Native Codex transport retries remain native, and terminal failures enter the shared continuation flow.

Failed deferred Codex attempts retain partial text and diagnostics without claiming final-message ownership. The eventual answer retains that ownership and any settlement warning. Retry progress uses the existing working indicator, survives reconnects, and clears on newer activity.

User Impact

Brief provider failures recover automatically. Stop cancels the wait. Authentication failures, billing/long-quota exhaustion, refusals, and operation-specific terminal outcomes keep their existing handling; timeout-compaction recovery retains priority.

No new configuration option, database schema, or protocol version. The existing embedded-runtime retry.provider.maxRetries setting still overrides the default. Relative to the current merge base, production is −10 lines, tests are +311, and docs are +11. Already-landed cleanup is excluded.

Evidence

  • Baseline reproduction: a completed tool followed by a terminal 429 stopped without continuation.
  • Live OpenAI API: real 200 response → completed tool → locally injected 429 → real 200 recovery in the same native thread. One tool effect, two native turns, one final answer, and clean reload.
  • Real Gateway/browser/Codex proof retained partial output, showed progressively slower retries, and produced one final answer without a duplicate badge. Stop during backoff aborted the run with no further provider request in the observation window.
  • Core recovery, UI retry/history/reconnect, and Codex transcript/settlement regressions passed, including 347 send/ack cases and 113 Codex cases. The real built-Gateway auth smoke verified retry exhaustion with two rate-limit requests, no rate-triggered auth rewarm, then one auth request and one auth rewarm.
  • Builds and aggregate changed checks passed. The final controller integration passed core and affected test-type checks, lint, and independent P0–P2 review. All 182 focused recovery/session tests passed on the final controller integration; CI passed on the final commit (run, attempt 2).

Test fixtures now state their retry budgets where they test terminal suspension or auth bookkeeping. The retry defaults and cancellation behavior retain separate controller and live-flow coverage. Event formatting stays with the existing Codex event owner, keeping the combined modules within the file-size limit.

Compatibility: the preamble helper forwards an existing event sequence into an in-memory UI reducer; it changes no stored representation. Existing transcript identities, partial content, and diagnostics remain. Reload and delayed-snapshot tests cover final ownership and retry-status ordering.

Review follow-through: merge conflicts are resolved while preserving the newer recovery refactors and deleted adapter. The integrated head passed 182 recovery/session tests and the affected type checks. The attached screenshots and recording were visually inspected locally; the automated review environment could not retrieve them, so the existing verified assets are retained.

Direct upstream inspection: HTTP 429 classification, native retryability, and retry notifications.

The final CI rerun cleared intermittent failures in unchanged Chrome bootstrap, A2UI rendering, and test-process cleanup; no assertions were weakened.

The attached captures contain synthetic users/data. The HTTP/SSE fixture makes Codex's initial WebSocket-to-HTTPS fallback notice expected.

Before: temporary rate limit ended the task after completed work

Retrying: the task remains active during backoff

After: preserved partial output and one recovered final answer

attachment-1309564108.mp4

@clawsweeper

clawsweeper Bot commented Sep 5, 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 app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling extensions: codex size: XL maintainer Maintainer-authored PR labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 5, 2026, 6:46 PM ET / 22:46 UTC.

ClawSweeper review

What this changes

The PR continues interrupted agent tasks from their existing transcript with bounded retries, preserves final-answer ownership, and displays retry progress through chat reconnects.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful fix against current main, with no concrete introduced correctness defect found. The earlier generic migration blocker is not supported by the inspected storage and reader boundaries.

Priority: P2
Reviewed head: 65c9f5d0e822347481b71a0bb073675ef6d1c1fa

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent recovery fix with relevant real-flow evidence and focused regression coverage; no actionable introduced defect was identified.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied live observations exercise the recovery owner through real Codex/OpenAI and Gateway/browser paths: injected 429 after completed work recovers with one tool effect and final answer, reload preserves ownership, and Stop prevents another request. Attachment retrieval failed here, without contradicting that evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Supplied live observations exercise the recovery owner through real Codex/OpenAI and Gateway/browser paths: injected 429 after completed work recovers with one tool effect and final answer, reload preserves ownership, and Stop prevents another request. Attachment retrieval failed here, without contradicting that evidence.
Evidence reviewed 10 items Pinned introduction boundary: Reviewed the merge-base-to-head changes at 65c9f5d. Base-only changes were excluded; the supplied stale test merge was not used to claim removal of current-main behavior.
Current-main necessity: Fetched main still limits continuation after completed tools to silent transport failures with settled-tool evidence, and retains a default of three transient retries. The merged cleanup at #139362 explicitly preserves behavior and does not supersede this recovery change. Inspection of the corresponding latest-release source failed because its blob was unavailable locally and could not be retrieved; no release implementation claim is made.
Recovery and cancellation boundary: The shared recovery owner excludes external cancellation, signal-owned interruption, run/tool/compaction timeouts, yields, client-tool handoff, native recovery failures, terminal CLI stops, and provider refusals. After waiting it checks cancellation and activates a transcript continuation; original-prompt replay and profile rotation retain replay-safety gating.
Findings None None.
Security None None.

How this fits together

The agent runner turns provider failures into recovery, fallback, or final errors. Codex supplies native turn results, while the Gateway and chat UI preserve transcript content and display run progress.

flowchart TD
  A[Provider failure] --> B[Recovery eligibility]
  B --> C[Bounded cancellable wait]
  C --> D[Continue existing transcript]
  D --> E[Final answer]
  B --> F[Fallback or terminal error]
  C --> G[Gateway and chat retry status]
  D --> G
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -10, Tests +311, Docs +11. Total +312 across 44 files.

View PR surface stats
Area Files Added Removed Net
Source 20 245 255 -10
Tests 22 490 179 +311
Docs 2 22 11 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 44 757 445 +312

Review metrics

Metric Value Why it matters
Recovery default 3 → 8 continuations; 90-second window retained Unconfigured runs gain more recovery opportunities while explicit saved budgets remain authoritative.

Stored data model

Persistent data-model change detected: serialized state: ui/src/pages/chat/tool-stream-preamble.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #139312
Summary: This PR is the explicit implementation candidate for the open task-continuation report; the related merged refactor preserves the older behavior.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep one bounded continuation owner that preserves completed work, existing retry preferences, cancellation, and terminal-error handling.

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

Yes: current-main source excludes a terminal 429 after completed tools from transcript continuation, matching the supplied baseline reproduction; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: consolidating recovery before existing failure escalation avoids competing retry loops, while preserving transcript identity and existing saved settings.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs bounded provider-failure recovery after partial work without evidence of an emergency or widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Supplied live observations exercise the recovery owner through real Codex/OpenAI and Gateway/browser paths: injected 429 after completed work recovers with one tool effect and final answer, reload preserves ownership, and Stop prevents another request. Attachment retrieval failed here, without contradicting that evidence.
  • proof: sufficient: Contributor real behavior proof is sufficient. Supplied live observations exercise the recovery owner through real Codex/OpenAI and Gateway/browser paths: injected 429 after completed work recovers with one tool effect and final answer, reload preserves ownership, and Stop prevents another request. Attachment retrieval failed here, without contradicting that evidence.

Evidence

What I checked:

  • Pinned introduction boundary: Reviewed the merge-base-to-head changes at 65c9f5d. Base-only changes were excluded; the supplied stale test merge was not used to claim removal of current-main behavior. (65c9f5d0e822)
  • Current-main necessity: Fetched main still limits continuation after completed tools to silent transport failures with settled-tool evidence, and retains a default of three transient retries. The merged cleanup at refactor(agents): simplify failure recovery bookkeeping #139362 explicitly preserves behavior and does not supersede this recovery change. Inspection of the corresponding latest-release source failed because its blob was unavailable locally and could not be retrieved; no release implementation claim is made. (src/agents/embedded-agent-runner/run/attempt-recovery.ts:152, a0ea2b71e335)
  • Recovery and cancellation boundary: The shared recovery owner excludes external cancellation, signal-owned interruption, run/tool/compaction timeouts, yields, client-tool handoff, native recovery failures, terminal CLI stops, and provider refusals. After waiting it checks cancellation and activates a transcript continuation; original-prompt replay and profile rotation retain replay-safety gating. (src/agents/embedded-agent-runner/run/attempt-recovery.ts:295, 65c9f5d0e822)
  • Default and saved-setting compatibility: The default increases to eight continuations, but setTransientRetryBudget still honors an existing saved value, including zero. The controller retains the 90-second window and rejects long quota windows; focused tests cover saved budgets, provider pacing, exhaustion, and excluded failure classes. (src/agents/embedded-agent-runner/run/failover-retry-controller.ts:160, 65c9f5d0e822)
  • Prior migration concern reassessed: The changed mirror call suppresses terminal ownership only for failed deferred attempts. Existing mirror identity, source fingerprint, run ID, partial text, and diagnostics remain; the existing optional runTerminal representation is reused. The added SQLite-backed test covers failed and successful attempts with deferred ownership both enabled and disabled. Existing chat grouping already excludes errored and nonterminal Codex rows from completed-answer ownership. No schema or historical-row rewrite is introduced. (extensions/codex/src/app-server/transcript-mirror.ts:153, 65c9f5d0e822)
  • Reconnect state is in memory: Gateway progress snapshots reside in the run map, and the UI startup reducer tracks existing agent event sequences. Retry status survives history hydration and clears on newer activity; the changed preamble helper does not alter a persisted format. The history regression exercises fresh hydration and delayed replay after live progress. (src/gateway/server-chat-state.ts:135, 65c9f5d0e822)

Likely related people:

  • steipete: 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-05T21:15:25.787Z sha 6a9fcf5 :: blocked before merge. :: none
  • reviewed 2026-09-05T21:49:47.036Z sha 7c297ce97d7a341f7aaddd996d452c06e91e4671 :: blocked before merge. :: none
  • reviewed 2026-09-05T22:01:33.095Z sha 19dd553 :: blocked before merge. :: none
  • reviewed 2026-09-05T22:11:43.632Z sha f55517c :: blocked before merge. :: none
  • reviewed 2026-09-05T22:38:55.890Z sha 65c9f5d :: blocked before merge. :: none

@steipete
steipete force-pushed the codex/rate-limit-continuation branch from 6a9fcf5 to 480187c Compare September 5, 2026 21:25
@steipete
steipete marked this pull request as ready for review September 5, 2026 21:26
@steipete
steipete requested a review from a team as a code owner September 5, 2026 21:42
@steipete
steipete force-pushed the codex/rate-limit-continuation branch from 7c297ce to 19dd553 Compare September 5, 2026 21:55
Resume the existing transcript with bounded backoff after transient provider failures, preserving completed work and keeping retries visible. Consolidate retry decisions and reserve final transcript ownership for the eventual answer. Verified with native Codex, browser recovery and cancellation, and live OpenAI fault injection. Closes #139312.
@steipete
steipete force-pushed the codex/rate-limit-continuation branch from f55517c to 3f2153a Compare September 5, 2026 22:19
@steipete
steipete merged commit a9e9dec into main Sep 5, 2026
327 of 331 checks passed
@steipete
steipete deleted the codex/rate-limit-continuation branch September 5, 2026 22:53
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
* fix: continue agent tasks after temporary rate limits

Resume the existing transcript with bounded backoff after transient provider failures, preserving completed work and keeping retries visible. Consolidate retry decisions and reserve final transcript ownership for the eventual answer. Verified with native Codex, browser recovery and cancellation, and live OpenAI fault injection. Closes openclaw#139312.

* test: align recovery fixtures with bounded continuation

* refactor(codex): keep retry status in event projection

* test: initialize the readonly retry counter in failover fixture
obviyus added a commit that referenced this pull request Sep 28, 2026
Closes #160534

## What Problem This Solves

Fixes repeated provider requests when an HTTP 400 response has an empty body, wasting rate limits and potentially hiding the original error behind subsequent throttling.

## User Impact

A deterministic bodyless client error now surfaces after one model request rather than four. Transient recovery, empty successful response repair, and normal replies retain their existing behavior. No configuration changes are required.

## Why This Change Was Made

The silent-error recovery path previously treated an unclassified bodyless HTTP 400 like a missing model response. It now checks the existing HTTP-status and transient-retry evidence owners before replaying a client error, without introducing another retryable-status list or reclassifying the failure as a format error.

The transport's existing retryable HTTP-status predicate is shared with the silent-error guard, preserving bodyless 409 conflict recovery without changing the transport's SDK wait cap or the transient retry budget.

The reasoning-only, replay-safe recovery introduced in #92191 remains intact, as does the separate transient recovery budget from #134281 and #139397.

Thanks to @bogdandragosvasile for the exact local reproduction. No overlap with Pash/Sarah changes.

## Evidence

Ran `pnpm openclaw --profile <isolated-profile> agent exec` against the issue's local empty-body fault server, using task-owned config, state, home, workspace, and ports. Baseline: `25d771cb8203f5afeea7b7c9dc8060210db8e43d`.

| Provider response | Baseline model requests | Fixed model requests | Observed result |
| --- | ---: | ---: | --- |
| Empty HTTP 400 | 4 | 1 | Original `400 status code (no body)` surfaces |
| Empty HTTP 409 | 4 | 4 | Existing silent-error retries, then original conflict error |
| Empty HTTP 429 | 10 | 10 | Existing transient retries, then rate-limit error |
| Empty HTTP 200 | 2 | 2 | Existing visible-answer retry, then incomplete-response error |
| Normal streamed HTTP 200 | 1 | 1 | `pong` |

Counts are `POST /v1/chat/completions` requests; unrelated `GET /` probes are excluded. Baseline controls were run with the production change reverted in the same worktree.

The new bodyless 400/422 owner regressions both failed before the fix (`retry` instead of `proceed`) and pass afterward. The focused run of `run.owner-policy.test.ts`, `failover/classify.test.ts`, and `provider-transport-fetch.test.ts` with `pnpm test ... --maxWorkers=1` passed all 133 tests in 40.6 seconds total wall time including worker compilation. This includes the new 409 preservation case, existing reasoning-only and replay-unsafe-tool cases, and existing SDK retry-cap tests.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
Closes openclaw#160534

## What Problem This Solves

Fixes repeated provider requests when an HTTP 400 response has an empty body, wasting rate limits and potentially hiding the original error behind subsequent throttling.

## User Impact

A deterministic bodyless client error now surfaces after one model request rather than four. Transient recovery, empty successful response repair, and normal replies retain their existing behavior. No configuration changes are required.

## Why This Change Was Made

The silent-error recovery path previously treated an unclassified bodyless HTTP 400 like a missing model response. It now checks the existing HTTP-status and transient-retry evidence owners before replaying a client error, without introducing another retryable-status list or reclassifying the failure as a format error.

The transport's existing retryable HTTP-status predicate is shared with the silent-error guard, preserving bodyless 409 conflict recovery without changing the transport's SDK wait cap or the transient retry budget.

The reasoning-only, replay-safe recovery introduced in openclaw#92191 remains intact, as does the separate transient recovery budget from openclaw#134281 and openclaw#139397.

Thanks to @bogdandragosvasile for the exact local reproduction. No overlap with Pash/Sarah changes.

## Evidence

Ran `pnpm openclaw --profile <isolated-profile> agent exec` against the issue's local empty-body fault server, using task-owned config, state, home, workspace, and ports. Baseline: `f6f301f702dfed02b63423237db57f96e8f4145a`.

| Provider response | Baseline model requests | Fixed model requests | Observed result |
| --- | ---: | ---: | --- |
| Empty HTTP 400 | 4 | 1 | Original `400 status code (no body)` surfaces |
| Empty HTTP 409 | 4 | 4 | Existing silent-error retries, then original conflict error |
| Empty HTTP 429 | 10 | 10 | Existing transient retries, then rate-limit error |
| Empty HTTP 200 | 2 | 2 | Existing visible-answer retry, then incomplete-response error |
| Normal streamed HTTP 200 | 1 | 1 | `pong` |

Counts are `POST /v1/chat/completions` requests; unrelated `GET /` probes are excluded. Baseline controls were run with the production change reverted in the same worktree.

The new bodyless 400/422 owner regressions both failed before the fix (`retry` instead of `proceed`) and pass afterward. The focused run of `run.owner-policy.test.ts`, `failover/classify.test.ts`, and `provider-transport-fetch.test.ts` with `pnpm test ... --maxWorkers=1` passed all 133 tests in 40.6 seconds total wall time including worker compilation. This includes the new 409 preservation case, existing reasoning-only and replay-unsafe-tool cases, and existing SDK retry-cap tests.

Co-authored-by: Ayaan Zaidi <[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 app: web-ui App: web-ui docs Improvements or additions to documentation extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

Agent tasks stop on temporary rate limits after completed work

1 participant