Repository navigation
fix(acp): bill AcpClient credits read between turns on the next turn - #22228
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: every caller of Notes
[DESIGN-REVIEWED] d5e88a9 Description read[DESCRIPTION-READ] 94f702e899880725e241a72639e2d3e55bb97ca9d6ff14534e72b76e6b94afde That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix is backed by issue #22171 and by tests that fail on base. It covers every What this change shipsInventory (5 items) — 5 justifiedIntent: make sure kiro credits spent on a compaction between turns show up in the usage ledger. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] d5e88a9 Description read[DESCRIPTION-READ] f27e664b5e1e099a02183e1f71f07017b70f0bac0ed4cc63246c5582b8807a93 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
[operator: bolichen97] Fast Gate's Harness Parity Gate fails here with |
|
|
c758f3b to
bb31427
Compare
|
|
bb31427 to
d5e88a9
Compare
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (7 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: ACP client bills credits reported between turns on the next turn instead of dropping them, with tests. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/acp-client.md.
Problem / Motivation
Goal: On the
AcpClientpath, credits kiro reports while a compaction is waited on between turns are billed once, on the next turn.AcpClient.wait_for_compactionand its post-compaction grace drain (src/kiro_crew/acp/client_usage.py) addmeteringUsagecredits tolast_prompt_stats. They run after the turn that asked for the compaction already billed itsEVENT_COMPLETE, and the next turn'scarry_over()starts its credit counter at zero. So those credits are never billed. The shared-runtime path had the same loss and was fixed in #22155.Why it matters
Every session on the non-shared runtime that compacts between turns under-reports its spend: the compaction's credits never reach a turn's usage row, so the usage ledger and spend views read low.
Not a goal
AcpSessionHandle); fix(acp): bill credits reported between turns on the next turn #22155 covers it.What changed (motivation → approach → change)
Credits read between turns had no turn to land on. Now they wait on the client and the next turn picks them up.
wait_for_compaction,_drain_post_compaction_metadata_between_turn_creditsstream_events/stream_command,send_message,send_message_stream)carry_over(), then zeroes itrekey()(a pooled client claimed by another session)_track_metadatatakes a keyword-onlybetween_turnsflag that the two between-turn readers pass. The caller says which window it reads for, rather than_turn_doneas in #22155, becausestream_command(the autocompact path) never clears_turn_done; reading turn state would move a slash command's own credits to the turn after it. The_track_metadatasignature row intest/test_client_bindings.pyis updated for the new keyword, anddocs/system-specs/modules/acp-client.mddescribes the hold.Backwards compatibility
Compatible:
between_turnsis keyword-only with aFalsedefault, so every existing caller of_track_metadatabills exactly as before; only the two between-turn readers pass it.Removes nothing: no key, field, path or caller is taken away; the change adds one held counter and one keyword.
Tests
test/test_acp_client_between_turn_credits.py, all through real turns on anAcpClientwith a scripted read stream:wait_for_compaction(metering aftercompleted, beforecompleted, and carrying the pct itself) bill 0.5 on the next turn and 0.0 on the one after, for each ofstream_events,send_messageandsend_message_stream;AcpProvider.wait_for_compactiontakes) bill the next turn once;stream_command("/compact"), stay on that turn;rekey(), the claiming session's first turn bills 0.0.Red on
origin/main(10 of 15 fail,Obtained: 0.0, Expected: 0.5);prove.py --base origin/mainreports PROVEN. Determinism: 20/20 repeated runs and 5/5 shuffled-order runs pass.Manual verification
N/A — unit coverage sufficient: the change is internal accounting, driven end to end through the client's own turn entry points with a scripted kiro stream.
Screenshots / video
N/A — no frontend change.
Related Issues
Fixes #22171
Pattern harvest
Rule candidate: review-prompt
Pattern: a counter written outside the window that resets it (a reader that runs between turns adding to per-turn stats) loses whatever it adds.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)