Commit 3456009
translator: guard nil response body in OpenAI ResponseBody (#2240)
**Description**
A JSON `null` response body decodes into a nil `*ChatCompletionResponse`
without
an error, because the decode target is a `**ChatCompletionResponse`
(`Decode(&resp)`).
Some OpenAI-compatible backends return a `null` body with a 200 status
(e.g. an
upstream that aborts the response after committing headers under load).
In the
non-streaming path `ResponseBody` then dereferenced the nil response at
`resp.Usage.PromptTokens`, panicking the ext-proc with a SIGSEGV (addr
0x80).
`RedactBody` already guards `resp == nil`, so the nil case is known; the
main path
just missed it. This treats a nil response as an empty response: report
zero token
usage and fall back to the request model, mirroring the streaming path's
behavior
when no usage is present, rather than crashing.
A regression test feeds a literal `null` body and asserts no panic and
zero usage.
Per the project's generative-AI policy: this change was prepared with
the
assistance of an AI coding tool (Claude Code). The submitter understands
and takes
full ownership of the change.
**Related Issues/PRs (if applicable)**
Fixes #2273
**Special notes for reviewers (if applicable)**
N/A
Signed-off-by: Kunwar Srivastav <kshivamsrivastav@gmail.com>
Co-authored-by: Ignasi Barrera <ignasi@tetrate.io>1 parent 5a8584a commit 3456009
2 files changed
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
150 | 158 | | |
151 | 159 | | |
152 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
353 | 363 | | |
354 | 364 | | |
355 | 365 | | |
| |||
0 commit comments