[WRONG BRANCH] fix(web-search): bound xAI error response bodies - #328
[WRONG BRANCH] fix(web-search): bound xAI error response bodies#328luvs01 wants to merge 1 commit into
Conversation
|
✅ Deterministic PR hygiene checks passed. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⏳ DRAFT
What to do
Its title has been prefixed with |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4139d7dd3e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const bounded = await readBoundedResponseBytes(res, { | ||
| maxBytes: MAX_SIDECAR_RESPONSE_BYTES, | ||
| signal: linkedSignal.signal, | ||
| }); |
There was a problem hiding this comment.
Preserve HTTP status when bounded body reading fails
When xAI has already returned non-OK headers but its body stream subsequently rejects—for example, because the connection resets while reading—the new await propagates to the outer catch and replaces the known HTTP status and any 401/403 entitlement hint with a generic body-read/connect error. The previous res.text().catch(() => "") retained the status-only error in this scenario; catch read failures within the non-OK branch and fall back to that status-based representation while still propagating intentional aborts.
AGENTS.md reference: src/AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
Motivation
res.text(), which can materialize an arbitrarily large untrusted body and risk memory exhaustion.Description
res.text()read inrunXaiWebSearchwith the repository's bounded readerreadBoundedResponseBytesand cap the read atMAX_SIDECAR_RESPONSE_BYTESso oversized error bodies are not retained in memory.parseXaiResponsesSSEunchanged so normal streaming remains byte-bounded by the existing parser limits.tests/xai-web-search.test.tsthat simulates a large non-OK response stream and asserts the upstream is canceled and the returned error is the bounded message.Testing
node_modules/bun/bin/bun.exe test tests/xai-web-search.test.tsand the file's tests passed (14 passed, 0 failed).bun x tsc --noEmit(typecheck) andbun run privacy:scan, both succeeded.bun run test; unrelated pre-existing failures surfaced in other suites during that full run, but the focused xAI web-search tests and typecheck/privacy scan that verify this change are green.Files changed:
src/web-search/xai-executor.ts,tests/xai-web-search.test.ts.Codex Task