fix(kiro): report context pressure for compaction - #439
Conversation
|
✅ Target branch corrected This pull request now targets The |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughKiro now estimates and propagates absolute context totals through streaming and bounded fallback parsing. The Responses bridge serializes those totals without double-counting output tokens, with coverage for metadata, history, SSE output, and request logging. ChangesContext total token accounting
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Request as Kiro request
participant Adapter as createKiroAdapter
participant Parser as parseKiroStream
participant Attempt as parseKiroAttempt
participant Bridge as responsesUsage
participant Log as RequestLogEntry
Request->>Adapter: Build request and estimate context input
Adapter->>Parser: Pass contextInputEstimate
Parser->>Attempt: Parse initial stream attempt
Parser->>Attempt: Parse bounded fallback attempt
Attempt-->>Parser: Return contextTotalTokens
Parser-->>Bridge: Provide merged usage
Bridge-->>Request: Emit input_tokens and total_tokens
Bridge-->>Log: Preserve absolute context checkpoint
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/kiro-stream.test.ts (1)
827-841: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a bounded-retry context-pressure regression test.
These tests cover metadata, percentage floors, history, and request-log estimates, but not the fallback request whose context grows after assistant continuation. Add a test that forces the retry and verifies that per-turn usage is summed while
contextInputTokensis the maximum across both attempts.As per path instructions, behavior changes in
src/should have a focused regression test near the existing subsystem tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/kiro-stream.test.ts` around lines 827 - 841, Add a focused test near the existing Kiro stream usage tests that triggers the bounded retry after assistant continuation, then assert per-turn input/output usage is summed across both attempts while contextInputTokens equals the maximum context usage observed. Use the existing adapter, request-building, event-frame, and doneUsage helpers, and preserve the established estimated-usage assertions where applicable.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adapters/kiro.ts`:
- Line 1062: Update the fallback result and second parse flow so the retry’s
computed contextInputTokens is returned from the fallback and passed to the
retry parse instead of the original estimate. Adjust the relevant fallback
result shape and the parse call near contextInputTokens, preserving the existing
retry estimate calculation and ensuring mergeKiroUsage receives the larger retry
context pressure.
---
Outside diff comments:
In `@tests/kiro-stream.test.ts`:
- Around line 827-841: Add a focused test near the existing Kiro stream usage
tests that triggers the bounded retry after assistant continuation, then assert
per-turn input/output usage is summed across both attempts while
contextInputTokens equals the maximum context usage observed. Use the existing
adapter, request-building, event-frame, and doneUsage helpers, and preserve the
established estimated-usage assertions where applicable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 57ab3ac0-50d7-4287-81d9-a57a803927f6
📒 Files selected for processing (5)
src/adapters/kiro.tssrc/bridge.tssrc/types.tstests/bridge.test.tstests/kiro-stream.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46e3745556
ℹ️ 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".
…/kiro-context-usage-reporting
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/request-log.test.ts`:
- Around line 755-782: Update responseWithDeferredRequestLog and its deferred
persistence path to carry raw OcxUsage separately from the Responses compaction
projection. Keep the SSE input_tokens value at 49,900, but persist and bill the
upstream current-turn inputTokens value of 58 instead of the projected
context-pressure value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d2d4eec0-5ead-42ca-ab60-7b32cea2245e
📒 Files selected for processing (6)
src/adapters/kiro.tssrc/bridge.tssrc/types.tstests/bridge.test.tstests/kiro-stream.test.tstests/request-log.test.ts
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c0b4f89da
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aec4df8339
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f44da01a95
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f1dd35c87
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adapters/kiro.ts`:
- Around line 1145-1162: Preserve checkpoint growth for reasoning-only fallback
attempts by deriving one carried-growth flag from firstResult.assistantText or
firstResult.sawReasoning, then passing it to all three mergeKiroUsage calls in
the fallback handling of src/adapters/kiro.ts lines 1145-1162. Add an upstream
context-percentage frame and assert the exact checkpoint equals 50,000 plus
finalOutputTokens in tests/kiro-stream.test.ts lines 391-407.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: a3b03513-3dc8-4e2b-b707-f8e1d34d0e28
📒 Files selected for processing (2)
src/adapters/kiro.tstests/kiro-stream.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e21e64016
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🔒 Maintainer integration in progress — please hold off on merging@lidge-jun (maintainer) is actively integrating this PR into What is happening This PR is being integrated on the maintainer branch What this means for you
This PR will be closed with a merge receipt (integration commit SHA, verification output, Integration tracker: |
PR #439 (head e78e846, author coseung2)를 통합하고 활성화 공백을 메우는 회귀 2건을 추가한다. Kiro는 attempt별 usage만 보고해서 클라이언트가 실제 컨텍스트 점유를 알 수 없었고 compaction 시점을 판단할 수 없었다. 이제 payload estimate, upstream 사용률, authoritative turn usage 중 최댓값을 절대 checkpoint로 삼아 streaming, fallback, bridge 직렬화, cache-detail clamping, deferred logging 전 경로로 전달한다. 추가한 회귀 2건: - 첫 attempt progress가 클수록 rebuilt fallback checkpoint도 커진다 (기존 assertion은 mergeKiroUsage의 floor만으로 만족되어 stale estimate 퇴행을 잡지 못했다) - non-stream parseResponse가 buildRequest로 설치된 contextInputEstimate closure를 실제로 활성화하고 절대 checkpoint를 전달한다 Co-authored-by: coseung2 <coseung2@users.noreply.github.com>
✅ Integrated into
|
|
Closing: integrated into |
Summary - preserve Kiro current-turn provider usage and cache fields internally - expose active context pressure as an explicit absolute
contextTotalTokenscheckpoint - serialize Responses usage without double-counting output - propagate rebuilt context estimates through the bounded completion retry - keep Kiro request-log rows estimated and based on the full request context ## Problem Kiro can report current-turn token usage separately from whole-conversation occupancy. OCX also reconstructs the complete Codex history locally, but the Responses usage sent back to Codex previously contained only the current-turn estimate. A conversation with roughly 226k active tokens could therefore report only a few dozen input tokens to Codex, preventing automatic compaction until Kiro rejected the request as over its context limit. ## Approach Kiro now keeps two distinct concepts: -inputTokens/outputTokens: provider per-attempt usage, including any reported cache split -contextTotalTokens: absolute active-context size after the response The absolute checkpoint is the maximum of: - the normalized Kiro payload estimate, including conservative image cost, plus response output - authoritative provider input plus output usage -contextUsagePercentagedecoded against the native Kiro model window, including the concrete response model selected bykiro-autoResponses serialization uses:input_tokens = max(0, contextTotalTokens - output_tokens) output_tokens = output_tokens total_tokens = contextTotalTokensThis prevents output from being added twice while allowing Codex latestlast_token_usage.total_tokensvalue to reflect active context pressure. Cache-read and cache-write detail fields are clamped to remain subsets of the derived absolute input. Bounded retries sum per-attempt usage, preserve definite growth from visible text carried into the retry, and retain the maximum absolute checkpoint without re-adding dropped private reasoning. Kiro request logs intentionally remain estimated. Existing request-log behavior floors input usage at the adapter full-request estimate; the bridged absolute checkpoint is likewise persisted as estimated request usage. Cache values remain absent when Kiro does not provide them. ## Verification -bun run typecheck-bun test tests/kiro-stream.test.ts tests/bridge.test.ts tests/request-log.test.ts— 141 pass, 0 fail - regressions cover Kiro GPT token ratios, authoritative usage floors, native-window and auto-route percentage decoding, normalized image estimates, cache-detail clamping, fallback context growth, merged usage identity, nonzero-output percentages, consecutive absolute checkpoints, bounded-retry estimate propagation, normalized-payload reasoning exclusion, and deferred Kiro request logging - the Windows full-suite process did not terminate after more than five minutes; no failure summary was produced, so cross-platform CI remains the full-suite authority ## Summary by CodeRabbit * Bug Fixes * Improved token usage reporting for Kiro requests, including absolute context totals and output token accounting. * Prevented token totals from accumulating incorrectly across streaming updates or retries. * Improved cache-related usage details and image token estimation. * Preserved accurate usage information in Responses output and deferred request logs. * Tests * Added coverage for context growth, fallback responses, streaming checkpoints, caching, images, and request-log consistency.