Skip to content

fix(kiro): bound non-streaming event collection - #1670

Merged
Wibias merged 1 commit into
lidge-jun:devfrom
luvs01:agent/bound-kiro-nonstream-events
Aug 14, 2026
Merged

Wibias merged 1 commit into
lidge-jun:devfrom
luvs01:agent/bound-kiro-nonstream-events

Conversation

@luvs01

@luvs01 luvs01 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Charge Kiro adapter events against the per-turn translator budget while a non-streaming Responses request collects the upstream event stream.
  • Preserve exact JSON-array ownership as the batch grows and as the response builder consumes events in order.
  • Propagate cancellation through nested Kiro generators and release response bodies, open tool calls, and partial thinking carries on overflow or early return.
  • Add regressions for bounded collection, duplicate event leases, cancellation cleanup, exact incremental accounting, and response-builder ownership transfer.

Verification

  • Base: dev at a1e5192b75edbf6dcacae51a30912fab93906f87; exact head: 21f7f88a046251fcd75a8240982c9548d994900e.
  • Bun 1.3.14: bun test --isolate tests/translator-budget.test.ts tests/kiro-stream.test.ts — 116 pass.
  • Bun 1.4.0-canary.1: the same focused files — 116 pass.
  • bun x tsc --noEmit passed on both runtimes.
  • bun run privacy:scan and git diff --check passed.
  • The Bun 1.3.14 full local suite ran for 267 seconds without an assertion failure, then the runtime crashed with an internal assertion at tests/api-storage-policy-run.test.ts. That unchanged test reproduced the Bun crash in isolation under 1.3.14 and passed 1/1 under Bun 1.4.0-canary.1.
  • Two independent resource/correctness reviews found no remaining actionable P0-P2 issue.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. No configuration, command, or public API behavior changed; code comments now describe the actual non-streaming Responses path.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. Independent review found no remaining actionable P0-P2 issue.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability when processing streamed and non-streamed responses.
    • Ensured tool calls and temporary response data are cleaned up after completion or errors.
    • Improved handling of parser cancellation and resource limits.
    • Preserved accurate context checkpoint reporting during response processing.
  • Tests

    • Expanded coverage for response parsing, cancellation, event limits, cleanup, and memory accounting.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

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

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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: 987592bd-5d30-4a30-a28a-5a2cf48d6372

📥 Commits

Reviewing files that changed from the base of the PR and between a1e5192 and 21f7f88.

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

📝 Walkthrough

Walkthrough

Kiro parsing now manages thinking-parser and tool-call cleanup, delegates async-generator attempts, and tracks translated-event ownership. Non-streaming responses use budget-aware event retention. Tests cover cancellation, overflow, cleanup, ownership transfer, and byte accounting.

Changes

Kiro retention lifecycle

Layer / File(s) Summary
Translated-event ownership
src/lib/translator-budget.ts, tests/translator-budget.test.ts
retainTranslatedEvent charges event bytes, validates ownership, transfers tail-byte ownership, and rejects duplicate retention. Tests verify accounting and release behavior.
Streaming parser cleanup
src/adapters/kiro.ts, src/adapters/kiro-thinking.ts
Kiro parsing delegates async-generator iteration, tracks open tool calls, closes calls on completion or failure, and disposes thinking-parser state during finalization.
Non-streaming event retention
src/adapters/kiro.ts, tests/kiro-stream.test.ts
parseResponse drains AWS event streams through budget-aware retention and releases events on failure. Tests cover cancellation, overflow, cleanup, and ownership transfer to buildResponseJSON.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 21f7f

This PR bounds non-streaming event collection and adds focused regression coverage; no actionable merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant KiroEventStream
  participant parseResponse
  participant TranslatorBudget
  participant buildResponseJSON
  KiroEventStream->>parseResponse: emit translated events
  parseResponse->>TranslatorBudget: retainTranslatedEvent(event)
  TranslatorBudget-->>parseResponse: retain event or report overflow
  parseResponse->>buildResponseJSON: pass retained events
  buildResponseJSON->>TranslatorBudget: releaseTransferredEvents()
Loading

Possibly related PRs

Suggested reviewers: lidge-jun, wibias, ingwannu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: bounding non-streaming Kiro event collection.
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 unit tests (beta)
  • Create PR with unit tests

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 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu @Wibias

Wibias commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Thanks for this — very useful hardening for Kiro’s non-streaming Responses path. Bounding the collected event stream and making cancellation/ownership cleanup explicit prevents a long upstream response from turning into unbounded memory growth, while keeping translator-budget accounting correct through the response builder.

@Wibias
Wibias merged commit 4a3c989 into lidge-jun:dev Aug 14, 2026
27 checks passed
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…eam-events

fix(kiro): bound non-streaming event collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants