Repository navigation
Commit fb045a0
Report provider errors on thread.failed and stop workflow retries after provider retry gives up (#8149)
## 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:
```sh
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](https://claude.com/claude-code)
> AGENT GENERATED
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>1 parent 52d1197 commit fb045a0
9 files changed
Lines changed: 259 additions & 26 deletions
File tree
- apps/server
- src/services/threads
- test/services/plugins
- packages/db
- scripts/query-costs
- src/data
- plugins/workflows
- skills/workflows/references
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
221 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
222 | 226 | | |
223 | 227 | | |
224 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
225 | 245 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
317 | 318 | | |
318 | 319 | | |
319 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
320 | 439 | | |
321 | 440 | | |
322 | 441 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
1333 | 1333 | | |
1334 | 1334 | | |
1335 | 1335 | | |
1336 | | - | |
| 1336 | + | |
1337 | 1337 | | |
1338 | | - | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1339 | 1342 | | |
1340 | 1343 | | |
1341 | 1344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1562 | 1562 | | |
1563 | 1563 | | |
1564 | 1564 | | |
1565 | | - | |
| 1565 | + | |
| 1566 | + | |
1566 | 1567 | | |
1567 | 1568 | | |
1568 | 1569 | | |
| |||
4332 | 4333 | | |
4333 | 4334 | | |
4334 | 4335 | | |
4335 | | - | |
| 4336 | + | |
4336 | 4337 | | |
4337 | | - | |
| 4338 | + | |
4338 | 4339 | | |
4339 | 4340 | | |
4340 | 4341 | | |
4341 | | - | |
4342 | | - | |
| 4342 | + | |
| 4343 | + | |
4343 | 4344 | | |
4344 | 4345 | | |
4345 | 4346 | | |
4346 | | - | |
| 4347 | + | |
| 4348 | + | |
4347 | 4349 | | |
4348 | 4350 | | |
4349 | 4351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
| |||
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
33 | | - | |
34 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
| |||
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
44 | | - | |
| 56 | + | |
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
| |||
97 | 109 | | |
98 | 110 | | |
99 | 111 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
106 | 120 | | |
107 | 121 | | |
108 | 122 | | |
| |||
0 commit comments