Skip to content

Report provider errors on thread.failed and stop workflow retries after provider retry gives up - #8149

Merged
ymichael merged 2 commits into
mainfrom
bb/1914-a-rate-limited-workflow-call-reports-only-w-thr_92kcbujujj
Nov 25, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/1914-a-rate-limited-workflow-call-reports-only-w-thr_92kcbujujj

Conversation

@ymichael

@ymichael ymichael commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

When a workflow worker failed on a provider 429, bb workflows status and history reported only Workflow worker failed. The server built the thread.failed (and experimental_thread.settled) error from system/error rows alone (getLastThreadErrorMessage → getLatestThreadSystemErrorEventRow). Providers record their failures as provider/error, so plugins got error: null and the workflows plugin fell back to its generic string. The workflows plugin decides whether to retry by classifying that text (isRetryableProviderFailure), so the empty error also turned off its two transient retries. That is the second effect in gaodes' 0.50.1 Pi report: provider-retry declines a Pi 429 that has no reset time (no-rate-limit-state), and the workflow's own retry never matched either. The lookup also covered the whole thread rather than the failed turn, so a failure could report an older turn's system/error.

What changed

  • packages/db/src/data/events.ts: getLatestThreadSystemErrorEventRow becomes getLatestThreadErrorEventRow. It returns the newest system/error or provider/error after a given sequence and uses the existing events_thread_type_sequence_idx index, so there is no new index or migration. The query-cost case in packages/db/scripts/query-costs/events-cases.ts is updated to match.
  • apps/server/src/services/threads/thread-data.ts: getLastThreadErrorMessage only looks at errors recorded since the failed turn's request (getLastStoredTurnRequestEvent). A provider/error is formatted as its detail (or message if there is no detail), followed by its errorInfo category, HTTP status and provider code, e.g. 429: {"code":"1302","message":"Rate limit reached for requests"} (rate-limit, HTTP 429). A system/error still returns its message.
  • The workflows classifier needs no change: the real error text now contains rate-limit / HTTP 429, which it already treats as retryable.
  • plugins/workflows/src/retry-handoff.ts, service.ts: with its own retry now working, the workflow would also retry failures provider-retry had deliberately given up on. Each replacement worker is a new thread with a fresh provider-retry budget, so retries multiplied (persistent overloads: 3 workers × 5 turns). The handoff now reads provider-retry's decline reason. attempts-exhausted, beyond-maximum-wait and pool-unavailable return give-up, and the call fails without a replacement. Other declines, such as no-rate-limit-state (this issue's Pi 429), still fall back to the workflow's own retries. The README and the workflows skill's runs.md describe this.
  • The thread.failed payload is still { thread, error: string | null }. There is no SDK or plugin API change and no HOST_DAEMON_PROTOCOL_VERSION bump.

Not in this PR:

  • When the workflows plugin restarts, it reconciles a worker that already failed as Workflow worker is in an error state, without the cause. Fixing that needs a way for plugins to read a thread's last error.
  • Whether provider-retry should retry a structured 429 that has no reset time. That is a policy choice, and the workflow's bounded 1 s / 4 s retries now cover the case.

How you verified

New tests, both of which fail on main:

  • apps/server/test/services/plugins/plugin-thread-events.test.ts
    • delivers thread.failed with the failed turn's provider/error and its classification: a Pi-shaped sequence of 429s marked willRetry, then a final 429, after an older turn's system/error. On main it received "earlier turn".
    • does not report an earlier turn's error for a failure without one: expects null. On main it received "earlier turn".
  • plugins/workflows/src/service-policy.test.ts:
    • asserts that the server's detail-less format Provider error (rate-limit, HTTP 429) is classed as retryable.
    • fails the call without a replacement when provider retry declined it as %s, for attempts-exhausted, beyond-maximum-wait and pool-unavailable. All three fail without the handoff change: the workflow started a second worker.
    • a handoff case for a no-rate-limit-state decline, which still starts a replacement.

Live end-to-end run on pnpm start:worktree, built once without and once with this change. Setup: Pi with a sandboxed PI_CODING_AGENT_DIR whose provider points at a local endpoint that returns 429 {"code":"1302","message":"Rate limit reached for requests"}, and a one-call workflow agent(..., { provider: "pi", model: "fakezai/glm-fake" }). The worker's events matched the report: three 429s marked willRetry, a final 429, then turn/completed failed. bb provider-retry explain returned decline / no-rate-limit-state in both runs.

before after
run and call error Workflow worker failed 429: {"code":"1302","message":"Rate limit reached for requests"} (rate-limit, HTTP 429)
providerRetryAttempts 0 (one worker) 2 (three workers, then the real error)

Live check of the give-up path, on the same setup with the endpoint returning 529 {"type":"overloaded_error"}: provider-retry retried the turn 4 times inside the one worker (5 turns, 24 provider requests), then recorded decline / attempts-exhausted. The call failed after 244 s with 529: {"type":"overloaded_error","message":"Overloaded"} (overloaded, HTTP 529), providerRetryAttempts 0 and no second worker. The server log shows Agent call 1 is not retried: provider retry declined it (attempts-exhausted). Re-running the Pi 429 case on this build still gave providerRetryAttempts 2 and the 429 error.

Commands:

pnpm exec turbo run typecheck --filter=@bb/db --filter=@bb/server --filter=./plugins/workflows
pnpm exec turbo run test --filter=@bb/db --filter=./plugins/workflows   # db 762, workflows 292 passed
pnpm exec turbo run test --filter=@bb/server -- --run test/services/plugins test/threads   # 1408 passed

Fixes #1914

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 2 commits November 24, 2026 16:42
A workflow worker that died on a provider 429 reported only
"Workflow worker failed": thread.failed read its error from system/error
rows alone, while provider failures are stored as provider/error. The
empty error also stopped the workflows plugin's transient retry, which
classifies the error text.

getLastThreadErrorMessage now reads the newest system/error or
provider/error since the failed turn's request, and formats a
provider/error as its detail (else message) followed by its category,
HTTP status and provider code. Errors from earlier turns no longer leak
into a later failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When provider retry declines a failed worker turn as attempts-exhausted,
beyond-maximum-wait, or pool-unavailable, a replacement worker would hit
the same limit, and each replacement thread brings a fresh provider retry
budget. The retry handoff now reads the decline reason and returns
give-up for those, and runAgentCall fails the call instead of using its
own retries. Other declines, such as a rate limit with no reset time,
still fall back to the workflow's retries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael ymichael changed the title Report the failed turn's provider error on thread.failed Report provider errors on thread.failed and stop workflow retries after provider retry gives up Nov 25, 2026
@ymichael
ymichael merged commit fb045a0 into main Nov 25, 2026
38 checks passed
@ymichael
ymichael deleted the bb/1914-a-rate-limited-workflow-call-reports-only-w-thr_92kcbujujj branch November 25, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A rate-limited workflow call reports only 'Workflow worker failed' — the 429 is hidden in a child thread

1 participant