Skip to content

[WRONG BRANCH] fix(responses): enforce aggregate UTF-16 backlog budget for adapter event queue - #376

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

[WRONG BRANCH] fix(responses): enforce aggregate UTF-16 backlog budget for adapter event queue#376
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-memory-exhaustion-vulnerability

Conversation

@luvs01

@luvs01 luvs01 commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Motivation

  • A recent coalescing change let adjacent deltas merge before the single maxBacklog check, which permitted 1,024 coalesced slots to each grow to 64 Ki UTF-16 code units and amplified per-turn retained payload far beyond the intended safety valve.
  • That regression makes a malicious or verbose upstream able to hold many megabytes per turn and, with many concurrent turns, amplify to process-wide memory exhaustion.

Description

  • Add an aggregate UTF-16 code-unit backlog budget (DEFAULT_MAX_BACKLOG_CODE_UNITS) and per-queue tracking to account for retained string payloads, including nested string fields. 【F:src/adapters/run-turn-queue.ts†L12-L31】
  • Introduce retainedStringCodeUnits and retainedEventStringCodeUnits helpers and a maxBacklogCodeUnits queue option to compute and cap retained string payload before insertion. 【F:src/adapters/run-turn-queue.ts†L16-L31】【F:src/adapters/run-turn-queue.ts†L84-L93】
  • Enforce the aggregate payload budget before coalescing or pushing an event, preserve the existing item-count maxBacklog cap, abort the producer via the configured onBacklogExceeded callback on breach, and deduct retained code units when events are consumed. 【F:src/adapters/run-turn-queue.ts†L123-L160】【F:src/adapters/run-turn-queue.ts†L156-L164】
  • Add focused regression tests that exercise (1) coalesced-delta overflow against the aggregate budget, (2) rejection of an oversized individual event, and (3) budget recovery when buffered events are consumed. 【F:tests/run-turn-queue.test.ts†L116-L164】

Testing

  • ✅ Ran the focused queue tests with bun test tests/run-turn-queue.test.ts, and all tests passed.【F:tests/run-turn-queue.test.ts†L1-L10】
  • ✅ Ran type checking with bun run typecheck and the code compiles cleanly.
  • ✅ Ran repository privacy checks with bun run privacy:scan and they passed.
  • ⚠️ Attempted a full bun run test of the entire suite but the repository-wide parallel run exposed unrelated pre-existing Lab/auth test failures and timeouts; the focused queue tests and typecheck passed and validate the added behavior.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 30, 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-08-30T05:43:57.061109Z e0d02dd 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

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@coderabbitai

coderabbitai Bot commented Aug 30, 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: fbd8ed09-dffa-490d-9044-353d2e1b35b1


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 added the bug Something isn't working label Aug 30, 2026
@github-actions

github-actions Bot commented Aug 30, 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 fix(responses): enforce aggregate UTF-16 backlog budget for adapter event queue [WRONG BRANCH] fix(responses): enforce aggregate UTF-16 backlog budget for adapter event queue Aug 30, 2026
@github-actions
github-actions Bot marked this pull request as draft August 30, 2026 05:43

@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: e0d02dd81a

ℹ️ 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 +137 to 138
backlogCodeUnits += eventCodeUnits;
if (coalesceIntoTail(event)) return;

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 Track only strings retained after delta coalescing

When Kiro emits adjacent phased text_delta events, backlogCodeUnits counts the repeated phase string on every push before coalescing, even though the merged queue item retains that field only once. Dequeueing consequently subtracts only one copy and leaves phantom backlog units, so a long stream of commentary or final_answer deltas can eventually abort despite the actual buffered payload remaining below the limit; with maxBacklogCodeUnits: 12, for example, two one-character commentary deltas should merge into a 12-unit event but the second is rejected. Update the accounting from the post-coalescing retained value, or remove the duplicated phase charge when replacing the tail.

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

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