Skip to content

fix: keep rate-limit retries transient and prevent split chat replies - #139465

Merged
steipete merged 4 commits into
mainfrom
codex/team-run-error-attempts
Sep 6, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/team-run-error-attempts

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Transient provider failures could leave permanent assistant error rows and split a recovered Control UI reply into partial messages. This PR keeps recovery within one logical run while preserving tool calls and media needed by later transcript replay.

Why This Change Was Made

The logical-run owner buffers failed partial text and diagnostics, preserves tool/media facts through the canonical fenced append, and persists the final diagnostic only when recovery fails. Tool calls remain ordered before their results, successful recovery discards failed plain-text fragments, and terminal failure retains its last partial text without duplicating facts or usage.

Rate limits allow at most ten total attempts, honoring smaller explicit retry.provider.maxRetries settings. Other transient failures retain the existing eight-retry/90-second policy. Shared Retry-After parsing preserves SDK headers and the greatest valid timing floor; unrepresentable positive floors remain non-retryable through provider-error projection. Cancellation remains effective during long waits.

Gateway sends transient working status instead of attempt terminals. Rate limits include bounded retry counters; overload, server-error, and timeout recovery retain ordinary working status. The client only reopens a diagnostic-only error after a strictly newer valid run-event sequence, so delayed, equal, or unsequenced deltas cannot erase a genuine terminal failure. Repeated terminals retain the latest ordering evidence.

The rebase reuses main's run-aware history recovery: attributed failures retire only after a successful answer from the same run. Main's newer replay fixtures, cleanup ownership, and widget-authoring parameter flow are retained. Duplicate history-state tests were consolidated into main's projection and SSE coverage. Stored transcripts are not rewritten.

User Impact

Recovered replies remain one reply, failed attempts do not leave stray text/error rows, and tools and attachments survive recovery and replay. Terminal errors remain visible when stale output arrives afterward.

The protocol addition remains optional: state: "status" may carry a retry object with integer attempt/maxAttempts in 1–10 and reason: "rate_limit". Existing clients can continue showing ordinary working status. There is no configuration addition, SQLite schema change, or protocol version bump.

Evidence

Current head: defbe03b984aa4b3a1b5076def8a575de0e4d220, rebased onto main 5579546f18c89b97d2fe3002cd7641504659eda4. The three functional commits were patch-identical across the final rebase (git range-diff); subsequent mechanical lint cleanup was reviewed separately. The PR remains open and unmerged.

  • Requested focused suites on the final base: 1,322 tests across 44 files, passed. The nonexistent assistant-error-transcript test selector was replaced by its existing session-tool-result-guard.transcript-events coverage.
  • Review-fix proof: 445 tests for provider parsing, recovery, and Gateway status; 1,015 tests for gateway-client/UI/TUI sequence behavior; final UI stale-delta/resumption proof: 189 tests. These overlap the focused suites and are not additive distinct-test counts.
  • Oversized raw/projected retry floors, dropped non-rate status, and stale/equal/unsequenced error resumption each failed before their corrections.
  • The full candidate and subsequent mechanical cleanup both passed Codex autoreview scoped-clean through P2. The cleanup passed another 500 focused tests. git diff --check passed.
  • Full unfiltered changed-file gate: passed, including all typechecks, lint, repository guards, and 1,121 native/tooling/boundary tests.
  • Exact-head GitHub CI: GREEN, zero pending checks; CI run 34016757139 completed successfully. The repository watcher exited 0.

The first rebase exposed main's stale history fixture at session-history-state.test.ts:398. That unrelated failure was repaired independently by #139794; the final rebase includes its fix.

LOC against origin/main...HEAD at the recorded base; production includes generated protocol and ratchet files:

Scope Added Removed Net
Production 783 559 +224
Tests and support 1662 338 +1324
Docs 26 12 +14

Existing synthetic UI evidence:

Before: ordinary working indicator

One transient retry indicator

Recovered final reply

Release-note: Keep rate-limit retries transient, preserve tool/media facts across recovery, prevent split live replies, and hide recovered historical attempt errors.

@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 size: XL maintainer Maintainer-authored PR labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 6, 2026, 3:18 AM ET / 07:18 UTC.

ClawSweeper review

What this changes

The PR keeps provider retries within one chat reply, defers failed-attempt text and diagnostics, preserves tool and media facts, and displays transient retry progress.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains useful work beyond current main. The prior budget, cancellation, and partial-content findings are addressed; inspected persistence and legacy-replay coverage also resolves the generic migration warning. No new blocking defect was found.

Priority: P2
Reviewed head: defbe03b984aa4b3a1b5076def8a575de0e4d220

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with substantial relevant regression coverage and no remaining supported correctness blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply. Source and boundary tests cover deferred settlement and retired-writer rejection; supplied synthetic UI captures were unavailable for visual inspection.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply. Source and boundary tests cover deferred settlement and retired-writer rejection; supplied synthetic UI captures were unavailable for visual inspection.
Evidence reviewed 9 items Pinned review scope and policy: The checkout is the supplied original head, defbe03. Root and applicable agents, embedded-runner, Gateway, UI, and docs AGENTS.md files were read fully. No maintainer-notes directory exists. The introduced merge-base comparison was used rather than endpoint drift.
Current main still differs materially: The fetched main retry controller still uses the previous retry budget, long-window exclusion, and caller-signal sleep. Main lacks the new deferred assistant-error owner. The related merged fixture repair, #139794, changes test fields only and does not replace this runtime work.
Earlier retry findings addressed: The retry controller honors smaller explicit retry budgets, caps rate-limit recovery at nine retries, and preserves the non-rate time window. run-loop passes the lane abort signal. The lifecycle test exercises an hour-long provider wait interrupted by lane expiry without aborting the caller.
Findings None None.
Security None None.

How this fits together

The agent runner turns provider responses into stored conversation history and live Gateway events. The Gateway and shared client projection translate those events into Control UI replies and retry indicators.

flowchart TD
  A[Provider response or failure] --> B[Agent retry controller]
  B --> C{Recover or finish}
  C -->|Retry| D[Transient working status]
  C -->|Finish| E[Logical run settlement]
  E --> F[Conversation transcript]
  D --> G[Gateway and client projection]
  F --> G
  G --> H[Control UI reply]
Loading

Before merge

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

Security

None.

PR surface

Source +220, Tests +1324, Docs +14, Other +4. Total +1562 across 74 files.

View PR surface stats
Area Files Added Removed Net
Source 46 775 555 +220
Tests 23 1662 338 +1324
Docs 3 26 12 +14
Config 0 0 0 0
Generated 0 0 0 0
Other 2 8 4 +4
Total 74 2471 909 +1562

Review metrics

Metric Value Why it matters
Retry policy 10 total rate-limit attempts; 0 new configuration options Smaller explicit retry budgets remain effective, while cancellation bounds longer provider-directed waits.
Production versus test growth Production net +224; tests/support net +1324 Production growth establishes deferred error ownership and shared projection logic; the larger test delta covers persistence, replay, cancellation, and ordering.

Stored data model

Persistent data-model change detected: serialized state: src/agents/embedded-agent-runner/run/run-attempt-dispatch.ts. Confirm migration or upgrade compatibility proof before merge.

Mantis proof suggestion

Optional web UI chat evidence would directly demonstrate the transient retry indicator and single recovered reply. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis verify Control UI chat during repeated provider rate limits followed by recovery, and capture redacted screenshots, transcript, and event logs showing one transient retry indicator and one final reply without stray attempt errors.

Technical review

Best possible solution:

Keep recovery under one logical-run owner, preserve durable tool/media facts, and publish only the final outcome through the existing transcript and Gateway contracts.

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

Yes, from source: repeated transient provider failures exercise the existing immediate error persistence and terminal projection paths. The supplied regression coverage targets those boundaries; no runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes. The patch repairs logical-run ownership and reuses canonical persistence and client projection rather than adding a competing recovery path; existing-row, legacy-history, and reopen coverage supports compatibility without a schema migration.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs confusing retry and recovered-reply behavior with a bounded agent/Gateway scope and no demonstrated emergency.
  • 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: Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply. Source and boundary tests cover deferred settlement and retired-writer rejection; supplied synthetic UI captures were unavailable for visual inspection.

Evidence

What I checked:

  • Pinned review scope and policy: The checkout is the supplied original head, defbe03. Root and applicable agents, embedded-runner, Gateway, UI, and docs AGENTS.md files were read fully. No maintainer-notes directory exists. The introduced merge-base comparison was used rather than endpoint drift. (AGENTS.md:1, defbe03b984a)
  • Current main still differs materially: The fetched main retry controller still uses the previous retry budget, long-window exclusion, and caller-signal sleep. Main lacks the new deferred assistant-error owner. The related merged fixture repair, fix(gateway): align history test fixture with projection state #139794, changes test fields only and does not replace this runtime work. (src/agents/embedded-agent-runner/run/failover-retry-controller.ts:242, 0c74e5e040d1)
  • Earlier retry findings addressed: The retry controller honors smaller explicit retry budgets, caps rate-limit recovery at nine retries, and preserves the non-rate time window. run-loop passes the lane abort signal. The lifecycle test exercises an hour-long provider wait interrupted by lane expiry without aborting the caller. (src/agents/embedded-agent-runner/run.retry-lifecycle.test-support.ts:35, defbe03b984a)
  • Persistence and replay compatibility: The new owner uses existing assistant-row shapes and the canonical append path. Tests reopen persisted sessions, retain tool calls before results, preserve attachments and display overrides, avoid duplicate usage, and retain the final partial text on failure. Separate lifecycle cases cover fresh and existing sessions after attempt teardown; replay fixtures cover legacy empty and fallback-placeholder errors. (src/agents/session-tool-result-guard.transcript-events.test.ts:734, defbe03b984a)
  • Deferred write authority remains enforced: The pending error captures its original writer assertion and fence. Settlement reinstalls that assertion in the canonical write context; the synchronous storage guard rechecks authority and current session ownership before committing. A retired-writer case verifies rejection with no persisted row. The private owner is excluded from plugin harness parameters. (src/agents/assistant-error-transcript.ts:90, defbe03b984a)
  • History and live ordering safeguards: Historical recovery remains run-scoped and leaves raw input unchanged. Client resumption requires a strictly newer valid event sequence and a diagnostic-only previous error. Tests cover repeated terminals, stale/equal/unsequenced deltas, retained useful content, and one recovered reply. (packages/gateway-client/src/session-projection.ts:546, defbe03b984a)

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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-06T01:08:44.588Z sha cee7d82 :: blocked before merge. :: [P1] Preserve explicitly configured rate-limit retry budgets | [P2] Cancel long retry sleeps when the lane times out
  • reviewed 2026-09-06T02:39:18.150Z sha 6401907 :: blocked before merge. :: [P1] Preserve explicitly configured rate-limit retry budgets | [P1] Preserve useful partial content before discarding attempt errors
  • reviewed 2026-09-06T03:54:18.566Z sha a6b7f8dafe68faed861694a39b6a92924773cdad :: blocked before merge. :: [P1] Preserve useful partial content before discarding attempt errors
  • reviewed 2026-09-06T04:31:46.173Z sha a6b7f8dafe68faed861694a39b6a92924773cdad :: blocked before merge. :: [P1] Preserve useful partial content before discarding attempt errors
  • reviewed 2026-09-06T04:58:51.578Z sha a6b7f8dafe68faed861694a39b6a92924773cdad :: blocked before merge. :: [P1] Preserve useful partial content before discarding attempt errors
  • reviewed 2026-09-06T05:23:07.418Z sha 3ed330423b8cf5defd05848e5e2fd1590124f654 :: blocked before merge. :: none
  • reviewed 2026-09-06T06:39:32.030Z sha defbe03 :: blocked before merge. :: none
  • reviewed 2026-09-06T07:12:49.667Z sha defbe03 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot closed this Sep 5, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 5, 2026
@openclaw-barnacle openclaw-barnacle Bot closed this Sep 6, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 6, 2026
@steipete
steipete force-pushed the codex/team-run-error-attempts branch 2 times, most recently from 40d21a1 to 6401907 Compare September 6, 2026 02:32
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 6, 2026
@steipete
steipete force-pushed the codex/team-run-error-attempts branch from 6401907 to a6b7f8d Compare September 6, 2026 03:43
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 6, 2026
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 6, 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:

@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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 6, 2026
Persist failed-attempt facts before dependent results while deferring partial text and terminal diagnostics. Keep display overrides and code-source ownership consistent without duplicating tool facts or billing.
Reuse run-aware Gateway history recovery and consolidate its repeated-attempt coverage. Preserve oversized provider retry floors through error projection, keep non-rate retry status visible, and require newer run-event order before resuming terminal error projections.
Re-export the existing Gateway run-event normalizer and types through the public session projection module. Remove the redundant forwarding wrapper and fix test lint after the history recovery consolidation.
@steipete
steipete force-pushed the codex/team-run-error-attempts branch from 3ed3304 to defbe03 Compare September 6, 2026 06:32
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 6, 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 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper approve

@clawsweeper

clawsweeper Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit b6ca24c into main Sep 6, 2026
196 checks passed
@steipete
steipete deleted the codex/team-run-error-attempts branch September 6, 2026 07:22
@steipete

steipete commented Sep 6, 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 7, 2026
…openclaw#139465)

* fix: keep rate-limit retries transient in chat

* fix(agents): retain tool and media facts across retries

Persist failed-attempt facts before dependent results while deferring partial text and terminal diagnostics. Keep display overrides and code-source ownership consistent without duplicating tool facts or billing.

* fix: preserve retry recovery ordering after rebase

Reuse run-aware Gateway history recovery and consolidate its repeated-attempt coverage. Preserve oversized provider retry floors through error projection, keep non-rate retry status visible, and require newer run-event order before resuming terminal error projections.

* refactor(client): keep run event normalization in its owner

Re-export the existing Gateway run-event normalizer and types through the public session projection module. Remove the redundant forwarding wrapper and fix test lint after the history recovery consolidation.
steipete added a commit that referenced this pull request Sep 7, 2026
…141238)

Honor the documented #139465 continuation budget for subscription limits.
Keep rotation-only fixtures explicit about disabling transient retries.

Proof: auth-profile rotation E2E (31), failover (881), retry owner (61),
node scripts/check-changed.mjs, pnpm build; independent review clean.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
…penclaw#141238)

Honor the documented openclaw#139465 continuation budget for subscription limits.
Keep rotation-only fixtures explicit about disabling transient retries.

Proof: auth-profile rotation E2E (31), failover (881), retry owner (61),
node scripts/check-changed.mjs, pnpm build; independent review clean.
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 gateway Gateway runtime 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: 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.

1 participant