[WRONG BRANCH] fix(responses): enforce aggregate UTF-16 backlog budget for adapter event queue - #376
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ 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: 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".
| backlogCodeUnits += eventCodeUnits; | ||
| if (coalesceIntoTail(event)) return; |
There was a problem hiding this comment.
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 👍 / 👎.
Motivation
maxBacklogcheck, 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.Description
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】retainedStringCodeUnitsandretainedEventStringCodeUnitshelpers and amaxBacklogCodeUnitsqueue 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】maxBacklogcap, abort the producer via the configuredonBacklogExceededcallback 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】Testing
bun test tests/run-turn-queue.test.ts, and all tests passed.【F:tests/run-turn-queue.test.ts†L1-L10】bun run typecheckand the code compiles cleanly.bun run privacy:scanand they passed.bun run testof 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