Skip to content

[WRONG BRANCH] claude: avoid retaining streamed reasoning fallback to prevent aggregate OOM - #450

Closed
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-memory-exhaustion-vulnerability-e5oem2
Closed

[WRONG BRANCH] claude: avoid retaining streamed reasoning fallback to prevent aggregate OOM#450
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-memory-exhaustion-vulnerability-e5oem2

Conversation

@luvs01

@luvs01 luvs01 commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Motivation

  • A previous change accumulated untrusted response.reasoning_*_text.delta into a per-turn thinkingBuf and encoded the whole retained text on block closure, allowing a malicious upstream to inflate process memory across concurrent turns and cause an aggregate denial-of-service.

Description

  • Stop retaining whole-stream reasoning text by removing the thinkingBuf/thinkingBufBytes retain/release path and the replacement of transient reasoning deltas with a large fallback envelope. Streamed deltas are still forwarded as thinking_delta events.
  • When no genuine upstream signature is present, emit a constant-size bounded fallback via encodeReasoningEnvelope({ txt: "" }) instead of re-encoding the entire retained text.
  • Remove the translator-budget reservations and retained-charge bookkeeping that previously tracked the whole retained reasoning block.
  • Update tests in tests/claude-integration/claude-outbound.test.ts to assert that streamed reasoning does not create retained reasoning budget allocations and that fallback signatures remain bounded and empty when appropriate.

Testing

  • Ran the focused suite bun test tests/claude-integration/claude-outbound.test.ts and it passed (50 tests) validating streaming behavior, part separators, and bounded fallback signatures.
  • Ran bun run typecheck and bun run privacy:scan, both of which passed.
  • Performed git diff --check (no whitespace errors) and local test iterations; the repository-wide bun run test was executed but reported a large set of unrelated/environment-sensitive failures while the focused change and its targeted tests passed.
  • The change is intentionally minimal and focused on removing retained reasoning buffers while preserving the streaming contract and existing non-streaming behavior.

Codex Task

@coderabbitai

coderabbitai Bot commented Sep 7, 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: Team

Run ID: f252fb8b-9710-499a-b04d-499855dd7b09


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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-07T06:08:44.802095Z 71fb4c6 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 7, 2026

@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: 71fb4c6678

ℹ️ 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 thread src/claude/outbound.ts
const signature = open.reasoningSig ?? encodeReasoningEnvelope({ txt: open.thinkingBuf ?? "" });
// Streamed thinking has already been delivered to the client. Keep the fallback
// signature bounded instead of retaining and re-encoding the entire untrusted block.
const signature = open.reasoningSig ?? encodeReasoningEnvelope({ txt: "" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve streamed thinking when replaying the bounded fallback

When a streamed reasoning block has no genuine upstream signature and Claude Code later replays that assistant block with a tool result, src/claude/inbound.ts preserves the visible thinking in summary alongside this envelope, but src/responses/parser.ts:284 evaluates envelope?.txt ?? text; because the envelope explicitly contains txt: "", it selects the empty value and then drops the reasoning item at line 300. This removes the reasoning_content preceding the replayed function call, so strict providers such as DeepSeek can reject the continuation instead of completing the tool loop. Keep the fallback bounded without setting an overriding empty txt, or make the parser fall back to the visible summary when this marker is empty.

AGENTS.md reference: src/AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented Sep 7, 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 changed the title claude: avoid retaining streamed reasoning fallback to prevent aggregate OOM [WRONG BRANCH] claude: avoid retaining streamed reasoning fallback to prevent aggregate OOM Sep 7, 2026
@github-actions
github-actions Bot marked this pull request as draft September 7, 2026 06:09
@luvs01 luvs01 closed this Sep 7, 2026

luvs01 commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

Closed as a duplicate of #449. Comparing the two heads with git diff --name-only reports zero differing files, so both PRs carry the same change and only one can be upstreamed. #449 is the surviving copy.

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