Skip to content

fix: replies show "Reply operation stalled" and rerun when provider rate limits outlast the watchdog - #183545

Merged
steipete merged 3 commits into
mainfrom
fix/rate-limit-watchdog-notice
Oct 25, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/rate-limit-watchdog-notice

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: a reply shows "Reply operation stalled" and is automatically rerun when provider rate limits (sustained HTTP 429s) outlast the session watchdog.

User Impact

User impact: when a turn is stopped because the model provider keeps rate-limiting it, people now see "Rate-limit recovery stopped after N automatic retries without a completed model response. Check completed work before trying again." instead of "Reply operation stalled". The turn is no longer automatically rerun into the same rate limit, which previously repeated the six-minute wait and added more 429 pressure. Channel users get a rate-limit notice instead of "This turn was interrupted because it stopped making progress". Stalls that are not rate limits behave exactly as before.

Why This Change Was Made

The rate-limit retry loop allows 15 retries with backoff up to 60 s, which is longer than the watchdog's six-minute window without progress. Retry waits are intentionally capped at that window. So under sustained 429s, the watchdog always stopped the turn in the middle of a backoff, labeled it a stall, and stalled-turn recovery immediately queued a rerun that hit the same limit.

The retry wait now tells the watchdog how many rate-limit retries have completed. When the watchdog stops a turn while that backoff is open, it reports rate-limit copy and marks the stop rate_limited. Stalled-turn recovery skips rate_limited stops, and the last-resort notice uses rate-limit text. Watchdog timing, retry allowances, and abort handling are unchanged: the abort is still an AbortError with code OPENCLAW_SESSION_WATCHDOG, and only its message differs.

Accepted edge: if a retry request is in flight at the exact moment of the stop, no backoff is open and the stop still reports as a stall. That case is rare and still visible to the user.

Shape of the change
  • failover-retry-controller.ts renders renderRateLimitRecoveryStopped(retryCount) → onRetryWait(..., { rateLimitStopMessage }) → deferred lifecycle owner → beginDiagnosticRetryWait → watchdog beginWait({ kind: "retry", rateLimitStopMessage }).
  • New watchdog describeStop() returns the stale reason and abort error from the open retry wait; abortForStall reads it before aborting (the abort closes the wait).
  • continueStalledReplyTurn returns early for rate_limited; resolveStalledTurnNoticeText picks the notice at the three last-resort notice sites.
  • renderRateLimitRecoveryStopped keeps the existing exhaustion copy, and for zero completed retries uses wording that does not claim recovery is disabled.

Evidence

End to end, real product path. An isolated Gateway (own state dir and port) with one custom openai-responses provider pointed at a local server that answers every request with an OpenAI-shaped TPM 429 (rate_limit_exceeded, type: tokens, retry-after-ms: 826). One Control UI-style chat.send turn:

03:59:11 transient same-model retry 1/15 for ratelimited/rl-model reason=rate_limit: delayMs=1000
...
04:02:00 reply watchdog: sessionKey=agent:main:main action=warn reason=no_semantic_progress
04:02:49 transient same-model retry 10/15 ... delayMs=60000
04:05:10 lane task error: lane=main durationMs=360358 error="Rate-limit recovery stopped after 11 automatic retries without a completed model response. Check completed work before trying again." errorName=AbortError taskKind=turn sessionKey=agent:main:main

chat.history afterwards contains only the user message and run-failed-before-reply: "Your request couldn't be completed: Rate-limit recovery stopped after 11 automatic retries without a completed model response. …". There was no second main-session run and no stalled-turn recovery in the two minutes after the stop. The one later provider request came from the post-turn background skill-workshop review lane, not the turn. On the parent commit, the same stop is reported as "Reply operation stalled" and queues a recovery run. The regression tests below pin that, and it matches the incident that prompted this fix.

The same rig, with fresh state, was rerun on each later revision: 765d3274, and the final head 81e80a9e. Each time the result was identical. On 81e80a9e:

04:47:48 lane task error: lane=main durationMs=361006 error="Rate-limit recovery stopped after 11 automatic retries without a completed model response. Check completed work before trying again." errorName=AbortError taskKind=turn sessionKey=agent:main:main runId=e2e-429-head81e8

The transcript held only the user message and that notice, and the whole Gateway log showed exactly one main-session run ID. Of the 13 provider requests, 12 were the turn (1 initial plus 11 retries) and 1 was the background skill-workshop lane.

The second commit fixes a static import cycle that CI's check-guards-architecture flagged on the first revision (watchdog → failover user copy). The retry controller now renders the stop copy and hands it to the watchdog on the retry wait, so src/sessions no longer imports failover copy. Locally, check:madge-import-cycles and check:import-cycles both report 0 cycles.

Regression tests, red on the parent commit and green with the fix:

  • src/logging/diagnostic-controller-recovery.integration.test.ts: a real controller watchdog stop with a rate-limit retry wait open. On the parent: expected 'no_activity' to be 'rate_limited'.
  • src/auto-reply/reply/agent-runner.stalled-turn.test.ts: a rate_limited stall queues no recovery run, does not claim or annotate a queued same-sender request, and selects the rate-limit notice. On the parent: continueStalledTurn returned true.

Other checks:

  • Neighboring tests of every touched production file (22 files) pass.
  • A producer-side test in failover-retry-controller.test.ts pins the copy each rate-limit backoff hands the watchdog, including the zero-retry wording.
  • tsgo:core and tsgo:core:test pass, format and line-cap ratchet pass, git diff --check is clean.
  • Codex autoreview (P1 and above) is scoped-clean on the whole PR at 81e80a9e, including earlier passes with the stop-path owners attached as context.

Known unrelated local check failures on main:

…koff

When provider 429s outlast the reply watchdog's six-minute progress
horizon, the watchdog stopped the turn mid-backoff and reported it as
"Reply operation stalled". Stalled-turn recovery then immediately reran
the request into the same saturated quota, where it stalled again.

The rate-limit retry wait now carries its completed retry count to the
session watchdog. A watchdog stop that finds an open rate-limit backoff
reports rate-limit copy, marks the operation `rate_limited`, skips the
stalled-turn recovery rerun, and sends a rate-limit last-resort notice
instead of the "stopped making progress" notice. Watchdog timing and
abort handling are unchanged; other stalls behave as before.

Release note: turns stopped by sustained provider rate limits now say so
instead of "Reply operation stalled", and are no longer automatically
rerun into the same rate limit.
@clawsweeper

clawsweeper Bot commented Oct 25, 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 labels Oct 25, 2026
@steipete
steipete marked this pull request as ready for review October 25, 2026 11:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T12:00:31.141880Z 2cd0d8d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Distinguish watchdog stops during provider rate-limit backoff from ordinary stalls, show rate-limit feedback, and skip automatic stall recovery.

Example: An isolated Gateway receives sustained HTTP 429 responses until its six-minute watchdog stops the turn after 11 retries.

  • Before: The turn reports “Reply operation stalled” and automatically queues another recovery run.
  • After: The turn reports that rate-limit recovery stopped after 11 retries and does not automatically rerun.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and supported by shipped Gateway evidence, with one definite import-cycle repair required before merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied final-head logs exercise the changed retry and watchdog owners through an isolated Gateway’s shipped chat.send entry point with real HTTP 429 responses; terminal history shows rate-limit feedback and the recorded run IDs establish that no recovery rerun started.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A turn stopped during sustained provider rate limiting reports a generic stall and automatically repeats work against the same saturated quota.
Reason: The maintainer-authored direction gives users accurate feedback and avoids redundant recovery pressure without changing watchdog timing, configuration, or retry allowances.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This PR addresses a real rate-limit recovery failure, but its new watchdog dependency creates an import cycle that blocks CI.

Priority: P2
Reviewed head: 765d32740bf63b01144fd658dcba72c4d282e758

Before merge

  • Extract the rate-limit formatter before importing it into the watchdog (P2) - This import closes a static dependency cycle: watchdog → failover/user-copy → process/command-error → process/exec → process/exec-spawn → process/spawn-diagnostics → infra/diagnostic-events → infra/diagnostic-model-request-provenance → watchdog. Although some edges are type-only, check-madge-import-cycles includes static type imports. The exact-head architecture job reports “madge-import-cycles failed (exit 1)”, so this is a diff-caused required-check failure. Extract the shared rate-limit formatting into a dependency-free leaf and consume it from both modules rather than weakening the checker.

Findings

  • [P2] Extract the rate-limit formatter before importing it into the watchdog — src/sessions/session-controller.watchdog.ts:2
Agent review details

How this fits together

The embedded runner records bounded retry waits on the session watchdog; reply dispatch and follow-up delivery consume the watchdog’s terminal classification to choose feedback and recovery.

flowchart TD
  A[Provider HTTP 429] --> B[Failover retry controller]
  B --> C[Deferred lifecycle owner]
  C --> D[Session watchdog]
  D --> E[Operation stop classification]
  E --> F[Reply feedback]
  E --> G[Recovery queue decision]
Loading

Technical review

Best possible solution:

Keep the existing watchdog classification and recovery changes while extracting the shared rate-limit formatting into a dependency-free leaf consumed by both owners.

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

Current-main source shows generic stall classification followed by automatic continuation, and the PR supplies a matching Gateway reproduction with sustained HTTP 429 responses.

Is this the best way to solve the issue?

The behavioral fix uses the existing retry and watchdog owners appropriately; the shared formatter needs a leaf dependency to preserve the repository’s acyclic static import contract.

Full review comments:

  • [P2] Extract the rate-limit formatter before importing it into the watchdog — src/sessions/session-controller.watchdog.ts:2
    This import closes a static dependency cycle: watchdog → failover/user-copy → process/command-error → process/exec → process/exec-spawn → process/spawn-diagnostics → infra/diagnostic-events → infra/diagnostic-model-request-provenance → watchdog. Although some edges are type-only, check-madge-import-cycles includes static type imports. The exact-head architecture job reports “madge-import-cycles failed (exit 1)”, so this is a diff-caused required-check failure. Extract the shared rate-limit formatting into a dependency-free leaf and consume it from both modules rather than weakening the checker.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Lifecycle-owned provider retry waits keeps the original intent (fa5f8b1: Keep bounded provider backoff with its logical run owner while preserving cancellation, deadlines, and genuine stall recovery.)
  • Session watchdog stop classification keeps the original intent (36e277d: Give each session one controller for turns, queues, Stop, and watchdog recovery.)
  • Automatic stalled-turn continuation changes intended behavior with a stated reason (872c9ba: Answer unanswered stalled requests from their persisted transcript instead of requiring users to repeat them.)
  • Follow-up terminal error presentation keeps the original intent (d70a89a: Surface watchdog-stopped recovery failures through source finalization instead of hiding them as deliberate cancellation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm check:madge-import-cycles
  • pnpm test src/logging/diagnostic-controller-recovery.integration.test.ts src/auto-reply/reply/agent-runner.stalled-turn.test.ts src/agents/failover/user-copy.test.ts --maxWorkers=1
  • pnpm tsgo:core
  • pnpm tsgo:core:test
  • git diff --check

What I checked:

PR surface

Source +55, Tests +58. Total +113 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 13 74 19 +55
Tests 3 65 7 +58
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 139 26 +113

Labels

Label changes:

  • add P2: Sustained provider rate limits cause misleading terminal feedback and an unnecessary recovery run; the repair has a focused dependency-boundary blocker.
  • add merge-risk: 🚨 automation: The introduced static dependency cycle fails the architecture check and would keep that check failing after merge.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Sustained provider rate limits cause misleading terminal feedback and an unnecessary recovery run; the repair has a focused dependency-boundary blocker.
  • merge-risk: 🚨 automation: The introduced static dependency cycle fails the architecture check and would keep that check failing after merge.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 25, 2026, 7:34 AM ET / 11:34 UTC.

…pens

Importing the failover user copy into the session watchdog pulled
`session-controller.watchdog.ts` into a large static import cycle
(madge `check-guards-architecture`). The retry controller, which already
owns the rate-limit exhaustion copy, now renders the stop message and
hands it to the watchdog on the retry wait it opens. The watchdog only
uses the open wait's explanation, so `src/sessions` no longer imports
failover copy. Behavior is unchanged.
…og-notice

# Conflicts:
#	src/agents/embedded-agent-runner/run/failover-retry-controller.test.ts
@steipete
steipete enabled auto-merge (squash) October 25, 2026 12:08
@steipete
steipete merged commit 9fa3f5a into main Oct 25, 2026
125 checks passed
@steipete
steipete deleted the fix/rate-limit-watchdog-notice branch October 25, 2026 12:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…ate limits outlast the watchdog (openclaw#183545)

* fix(sessions): report rate limits when the watchdog stops a retry backoff

When provider 429s outlast the reply watchdog's six-minute progress
horizon, the watchdog stopped the turn mid-backoff and reported it as
"Reply operation stalled". Stalled-turn recovery then immediately reran
the request into the same saturated quota, where it stalled again.

The rate-limit retry wait now carries its completed retry count to the
session watchdog. A watchdog stop that finds an open rate-limit backoff
reports rate-limit copy, marks the operation `rate_limited`, skips the
stalled-turn recovery rerun, and sends a rate-limit last-resort notice
instead of the "stopped making progress" notice. Watchdog timing and
abort handling are unchanged; other stalls behave as before.

Release note: turns stopped by sustained provider rate limits now say so
instead of "Reply operation stalled", and are no longer automatically
rerun into the same rate limit.

* fix(sessions): render the rate-limit stop copy where the retry wait opens

Importing the failover user copy into the session watchdog pulled
`session-controller.watchdog.ts` into a large static import cycle
(madge `check-guards-architecture`). The retry controller, which already
owns the rate-limit exhaustion copy, now renders the stop message and
hands it to the watchdog on the retry wait it opens. The watchdog only
uses the open wait's explanation, so `src/sessions` no longer imports
failover copy. Behavior is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant