Skip to content

[WRONG BRANCH] fix(kiro): bound non-streaming event collection - #235

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-unbounded-buffer-in-kiro-parseresponse
Draft

[WRONG BRANCH] fix(kiro): bound non-streaming event collection#235
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-unbounded-buffer-in-kiro-parseresponse

Conversation

@luvs01

@luvs01 luvs01 commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The Kiro adapter exposed a new parseResponse path that drained the AWS eventstream into an in-memory AdapterEvent[] with no aggregate byte/event/time bound, creating a resource-exhaustion risk for large or malicious provider streams.
  • Non-streaming callers (web-search sidecar and the normal non-streaming Responses path) await parseResponse, so an unbounded Kiro stream could grow process memory before the request finishes.

Description

  • Add retainTranslatedEvent(event, budget, first) to src/lib/translator-budget.ts to charge retained adapter events incrementally against the shared per-turn TranslatorBudget (first event charged with array brackets sizing, subsequent events charged with comma delimiter sizing).
  • Update src/adapters/kiro.ts::parseResponse to call retainTranslatedEvent for each yielded AdapterEvent as it's collected and to call releaseTranslatedEvent for all retained events if parsing aborts or throws, preventing leaks on error paths.
  • Add a regression test in tests/kiro-stream.test.ts that exercises bounded non-streaming collection and expects a translation_buffer_limit error when the translator budget is exceeded.

Testing

  • Ran the focused Kiro suite with bun test tests/kiro-stream.test.ts, which passed the modified tests (targeted Kiro tests passed locally).
  • Ran type checking with bun run typecheck and bun run privacy:scan, both of which completed successfully.
  • Ran the repository test driver; the changed Kiro tests passed under the pinned Bun runner, while a full bun run test run encountered an unrelated timeout in an outbound-proxy test (not related to these changes).

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Improved Kiro response handling to enforce translation buffer limits consistently.
    • Prevented retained translation data from accumulating after parsing errors.
    • Added safeguards for non-streaming responses when the translation buffer limit is exceeded.
  • Tests

    • Added coverage confirming buffer-limit errors are reported correctly and temporary usage is released afterward.

@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 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 30e41f23-a322-44b8-b8a4-c84cd37c9845

📥 Commits

Reviewing files that changed from the base of the PR and between 121f1ad and f5b27eb.

📒 Files selected for processing (3)
  • src/adapters/kiro.ts
  • src/lib/translator-budget.ts
  • tests/kiro-stream.test.ts

📝 Walkthrough

Walkthrough

Kiro non-streaming response parsing now accounts for retained translated events against the translator budget and releases all retained events when parsing fails. Tests cover budget rejection and cleanup.

Changes

Kiro translator-budget retention

Layer / File(s) Summary
Translated event retention accounting
src/lib/translator-budget.ts
Adds retainTranslatedEvent, which charges serialized event bytes and array delimiters against the translator budget and records ownership for release.
Kiro response collection and cleanup
src/adapters/kiro.ts, tests/kiro-stream.test.ts
parseResponse retains collected events and releases them when parsing throws. Tests verify translation_buffer_limit and a zero budget after cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: lidge-jun, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: bounding Kiro non-streaming event collection to prevent unbounded growth.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-unbounded-buffer-in-kiro-parseresponse

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

@github-actions

github-actions Bot commented Aug 10, 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(kiro): bound non-streaming event collection [WRONG BRANCH] fix(kiro): bound non-streaming event collection Aug 10, 2026
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 02:10
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