Repository navigation
Fix provider retry for Claude rate limits - #1408
Conversation
|
🚨 SLOP COP 🚨 · I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior. |
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5: Claude tells bb when a usage limit blocks work. This change remembers the wait and restarts work after the reset.
I found these issues:
- High: A reconciliation can recreate a retry after a user cancels it.
- High: Automatic release does not confirm that the current candidate still permits automatic recovery.
- High: A later allowed limit does not clear the pending hard rejection.
- High: Cancellation reports success when durable storage cleanup fails.
- Medium: Deleted threads can leave permanent restore keys.
- Medium: Restore reads every key in sequence during plugin activation.
- Low: The built-in guide templates still describe memory-only timers and lost state after reload.
I left inline comments for each code issue. Please also update both guide templates and regenerate templates.generated.ts.
I found no duplicate retry implementation. The main architecture risk comes from state changes across plugin waits and server policy checks.
The focused exact-head suite passed 228 tests. Five affected package typechecks passed. All current GitHub checks passed.
Browser E2E does not fit this change because it adds no browser route. The review exercised the nearest CLI and server API paths.
This is a comment-only review. I did not approve the pull request or request changes.
e0a7ffb to
007c8fd
Compare
Two Codex runtime reliability fixes, split out of #1385 so they can be reviewed on their own. ## Bug 1: command output lost when Codex reorders events Codex app-server normally reports a shell command as `function_call` → `function_call_output` (the full stdout) → `item/completed`. Sometimes the `item/completed` event arrives **before** the raw record carrying the output. The adapter only repaired a completed item using output it had already captured. In the reordered case there was nothing captured yet, so it published the provider's truncated `aggregatedOutput` and the real output — which arrived a moment later — was dropped. Users saw a finished command with missing or partial output. **Fix:** when a completed command item arrives while its shell call is still awaiting raw output, hold it instead of publishing it. Repair and emit it as soon as the raw record lands. If the raw record never arrives, flush the held item at turn completion, so output is at worst delayed rather than lost. Unparseable raw output clears the pending shell call so the completed item is released unchanged. ## Bug 2: generated-title rename fails on a brand-new session A new Codex rollout file can exist briefly before its first record is written. A generated-title rename landing in that window fails with `rollout at <path> is empty`, and the thread keeps its placeholder title even though the same call would succeed moments later. **Fix:** retry only that exact transient error, and only for Codex, backing off 50 ms then 200 ms before a final attempt. Every other rename failure, and every other provider, still fails immediately. The backoff is only ever paid when the rename has *already* failed — the happy path returns on the first attempt — and the full 250 ms only when it fails for good, where the alternative was failing instantly and leaving the thread on a placeholder title. ## Protocol version Bug 1 changes what the host daemon sends the server, so `HOST_DAEMON_PROTOCOL_VERSION` goes 109 → **110** with its contract test and comment updated. Older daemons can publish a truncated completed item, so enrolled machines must update. Note for reviewers: #1408 bumped the constant to 109 and updated the assertion, but left the test name and comment describing 108. Rebasing onto it meant rewriting those exact lines, so this PR lands a correct 110 lineage and clears that stale wording as a side effect. These are product reliability changes only — **no database schema, migration, or Drizzle snapshot changes**, and no other behavior from #1385. ## Validation - `turbo run typecheck --filter=@bb/agent-runtime --filter=@bb/host-daemon-contract` — pass - `turbo run typecheck --filter=@bb/host-daemon --filter=@bb/server` (downstream protocol consumers) — pass - `turbo run test --filter=@bb/host-daemon-contract` — 49/49 pass - Rebased onto `3bd8e79a0` and fully re-validated - `turbo run test --filter=@bb/agent-runtime` — **921 pass, 0 failures** - Prettier clean on all changed files Three regression tests were each verified to **fail against current `main` and pass with the fix**: - adapter: repairs a completed item when the raw output arrives late - adapter: flushes the held item at turn end when raw output never arrives - runtime: retries the rename through one empty-rollout error and applies the title A fourth test pins the exhaustion path: a rollout that stays empty makes exactly 3 attempts and then propagates the error, so the retry can neither loop nor swallow a genuine failure. ## Previously-noted test failure is resolved upstream Earlier revisions of this description flagged `runtime.process-lifecycle.test.ts > bounds provider stderr while data arrives without a newline` as failing locally on macOS. #1402 landed that fix on `main` (the fixture used `process.exit()`, which discards Node's async-buffered pipe output on macOS). After rebasing onto it, **the full suite is green: 921/921 with zero failures.** > AGENT GENERATED: by Claude Opus 5 --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
#1408 (c934ec4) canonicalized Claude's hard subscription rejection into one terminal error inside the failed turn, and pins an automatic SDK retry as a retrying rate-limit error. Both invariants live in the shared translator but were covered only by claude-code/adapter.test.ts, which dies at graduation. Driven here through the canonical construction the bridge uses (per-session id prefix, synthesized item/started). All three cases verified red against a broken invariant. Co-Authored-By: Claude Fable 5 <[email protected]>
#1408 (c934ec4) canonicalized Claude's hard subscription rejection into one terminal error inside the failed turn, and pins an automatic SDK retry as a retrying rate-limit error. Both invariants live in the shared translator but were covered only by claude-code/adapter.test.ts, which dies at graduation. Driven here through the canonical construction the bridge uses (per-session id prefix, synthesized item/started). All three cases verified red against a broken invariant. Co-Authored-By: Claude Fable 5 <[email protected]>
Summary
Root cause
Claude Code reports a hard subscription limit before its synthetic assistant/result sequence. The adapter previously persisted the rate-limit state and an error before
turn/started, then persisted a second error when the result arrived. Recovery only inspected the failed turn range, so it missed the blocked state. An immediate manual continuation could then fail with a plain 429 and no new rate-limit state, which removed the plugin timer.The retry plugin also treated reconciliation, cancellation, supersession, deletion, and timer release as separate asynchronous operations. A reconciliation already in flight could therefore recreate an entry after cancellation. They now use one per-thread operation queue, while pending timers remain intentionally in memory and disappear on server/plugin restart.
Review follow-up
candidate.automatic; the server independently rejects automatic continuation of a manual-only candidateallowedupdate clears a pending hard rejectionValidation
allowedrate-limit stateThe Claude account's external limit had reset before final standalone QA, so the exact hard-limit path is covered deterministically by the real-message adapter and end-to-end server/plugin tests rather than claimed as a live rate-limited run.