Skip to content

[WRONG BRANCH] fix(web-search): bound xAI error response bodies - #328

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-unbounded-memory-read-in-xai-executor
Draft

[WRONG BRANCH] fix(web-search): bound xAI error response bodies#328
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-unbounded-memory-read-in-xai-executor

Conversation

@luvs01

@luvs01 luvs01 commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The xAI sidecar executor read non-OK upstream response bodies with res.text(), which can materialize an arbitrarily large untrusted body and risk memory exhaustion.

Description

  • Replace the unbounded res.text() read in runXaiWebSearch with the repository's bounded reader readBoundedResponseBytes and cap the read at MAX_SIDECAR_RESPONSE_BYTES so oversized error bodies are not retained in memory.
  • On an oversized non-OK body the code now cancels the upstream stream and returns a safe, short error detail rather than decoding the full payload, while preserving entitlement/status messaging and existing timeout/abort behaviour.
  • Preserve the successful-path SSE parsing in parseXaiResponsesSSE unchanged so normal streaming remains byte-bounded by the existing parser limits.
  • Add a focused regression in tests/xai-web-search.test.ts that simulates a large non-OK response stream and asserts the upstream is canceled and the returned error is the bounded message.

Testing

  • Ran the focused suite with node_modules/bun/bin/bun.exe test tests/xai-web-search.test.ts and the file's tests passed (14 passed, 0 failed).
  • Ran bun x tsc --noEmit (typecheck) and bun run privacy:scan, both succeeded.
  • Ran a broader 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

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 23, 2026
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f2a9dc94-e1b8-4d46-aab9-ecbd1e31cbd6


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot changed the title fix(web-search): bound xAI error response bodies [WRONG BRANCH] fix(web-search): bound xAI error response bodies Aug 23, 2026
@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions
github-actions Bot marked this pull request as draft August 23, 2026 01:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +119 to +122
const bounded = await readBoundedResponseBytes(res, {
maxBytes: MAX_SIDECAR_RESPONSE_BYTES,
signal: linkedSignal.signal,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant