Commit 623003e
authored
fix(providers): name the failing phase of a stalled OpenAI call, and reject a failed generation (#6283)
* fix(providers): name the failing phase of a stalled OpenAI call, and reject a failed generation
An agent block hung ~4.5 minutes with an empty trace and surfaced only the
runtime's own `TimeoutError: The operation timed out.` The cause was a runaway
generation: the model repeated one tool call until it consumed the whole
128,000-token output budget, which takes minutes, and `/v1/responses` withholds
its 200 until generation finishes — so the client waited, bounded only by an
undocumented runtime socket deadline, and gave up before the response existed.
Nothing in the trace could distinguish that from a request the provider never
answered, or from one whose body never arrived.
- Name the phase a transport failure died in — `awaiting-response-headers` vs
`reading-response-body` — with status, ttfb, content-length and
`x-request-id`. undici draws the same line as two error types
(UND_ERR_HEADERS_TIMEOUT / UND_ERR_BODY_TIMEOUT); the OpenAI SDK captures
`x-request-id` for the same reason. It rides the error message because that
reaches the trace span, which survives when a task stops shipping logs.
- Carry the cause through `ProviderError` so a transport timeout still
classifies after wrapping overwrites `name`.
- Reject a 200 that reports a failed or unusable generation instead of
returning empty content with billed tokens, and stop truncated tool calls
from executing. Matches `streamResponsesTurn`, which already did this, and
`@ai-sdk/openai`, which throws on the same condition.
- Bound non-JSON error bodies so a gateway error page cannot become the
user-facing block error.
Deliberately not included: a response-body deadline (the observed failure is in
the headers phase, and the body transfers in ~1ms) and status-based retries
(worth doing, unrelated to this, and separable).
* test(providers): pin that a structured provider error survives the error-body bound
* chore(providers): trim comments to the non-obvious why
* fix(providers): let a deadline while reading an error body propagate
* fix(providers): name the body phase when an error body read fails1 parent 5718def commit 623003e
8 files changed
Lines changed: 811 additions & 21 deletions
File tree
- .claude/rules
- .cursor/rules
- apps/sim
- executor/handlers/agent
- providers
- openai
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
979 | 979 | | |
980 | 980 | | |
981 | 981 | | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
982 | 1025 | | |
983 | 1026 | | |
984 | 1027 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
74 | 90 | | |
75 | 91 | | |
76 | 92 | | |
| |||
1299 | 1315 | | |
1300 | 1316 | | |
1301 | 1317 | | |
1302 | | - | |
1303 | | - | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
1304 | 1327 | | |
1305 | 1328 | | |
1306 | 1329 | | |
| |||
0 commit comments