Skip to content

Kiro: log the usage Kiro reports on every wire, and forward combo child usage after commit - #7433

Draft
hedging8563 wants to merge 2 commits into
lidge-jun:devfrom
hedging8563:kiro-usage-log
Draft

hedging8563 wants to merge 2 commits into
lidge-jun:devfrom
hedging8563:kiro-usage-log

Conversation

@hedging8563

@hedging8563 hedging8563 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem: A combo child logs into its own context and the request log re-reads the bridged Responses wire, which has no providerCredits, zero-fills cache detail and derives input from the context checkpoint. Every Kiro row was also marked estimated and raised to the local input estimate, even when Kiro sent tokenUsage.

Fix:

  • The combo passes each child onBridgeUsageBound; after the child commits it sets usageFromBridge and usage on its own context. A binding that arrives before the commit waits; a target that fails or never commits forwards nothing.
  • The Kiro parser marks tokenUsage-derived usage as upstreamReported (a two-leg turn keeps the mark only if both legs have it); usageForFinalLog and finalizedUsage skip the estimated mark and input floor for marked usage.
  • The client-visible wire is unchanged.

Tests: new tests/server/server-kiro-usage-log-e2e.test.ts (direct and combo route; /v1/responses, /v1/messages stream and non-stream, /v1/chat/completions), tests/responses/responses-combo-bridge-usage.test.ts, new cases in request-log-estimate-cap.test.ts. tsc --noEmit clean. Related suites pass: tests/server/server-kiro*, tests/responses/responses-combo*, tests/combos, tests/usage (1303 pass, 0 fail), kiro-metering-usage and kiro-stream, test-layout (27 pass).
Overlap check against #7389 and later dev commits: none (#7389 touches core-combo.ts for failedAdapter only; cherry-picks applied cleanly).

Review readiness checklist

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

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

bylinelog-bot and others added 2 commits October 20, 2026 14:38
Problem 1. A combo child logs into its own context. The combo copies
that context into the request context once, when the child commits.
The bridge binds the adapter usage later, at the terminal frame, so the
request context never learned that usage came from the bridge. The
request log then re-read the bridged Responses wire. That wire has no
providerCredits, zero-fills the cache detail, and derives the input
count from the context checkpoint. The log row showed a high input
count, zero cache and no credits on /v1/messages, /v1/responses and
/v1/chat/completions alike.

Problem 2. Every Kiro row was marked estimated and raised to the local
input estimate, even when Kiro sent a tokenUsage block.

Fix 1. The combo passes each child onBridgeUsageBound. The transport
calls it when it binds bridge usage. After the child commits, the combo
sets usageFromBridge and usage on its own context.

Fix 2. The Kiro parser marks usage read from tokenUsage as
upstreamReported. A two-leg turn keeps the mark only when both legs have
it. usageForFinalLog and finalizedUsage skip the provider-wide estimated
mark and the input floor for marked usage. Usage without the mark, and
usage read off a wire, stays estimated.

The wire that the client receives is unchanged.

Tests: new tests/server/server-kiro-usage-log-e2e.test.ts replays one
Kiro stream (metering and tokenUsage, then no tokenUsage, then two legs
with tools) through /v1/responses, /v1/messages (stream and non-stream)
and /v1/chat/completions, on a direct route and on a combo route. A unit
test in request-log-estimate-cap.test.ts covers the mark. The Kiro
stream test now expects the mark. 15 of the 21 new cases fail without
the fix.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The combo forwarded bridge usage to the request context when the child
set childCommitted. The flag was set before callbackGate.commit(). If
the commit threw, a later usage binding of that child still reached the
request context.

The combo now keeps two flags for each target: childCommitted, set after
the commit, and childUsageBound, set by the callback. It forwards only
when both are true. A binding that comes before the commit waits for the
commit. A target that fails or never commits forwards nothing. The
callback takes no argument now, because the combo already holds the
child context.

Tests: new tests/responses/responses-combo-bridge-usage.test.ts drives
executeComboResponses with a fake dispatcher. It covers a binding after
the commit, a binding before the commit, a refused first target with a
committed second target, and a commit that throws. A new case in
request-log-estimate-cap.test.ts pins the aggregate rule: the
upstreamReported mark needs usage on every attempt, and an empty list or
attempts without usage give no mark.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@Ingwannu

Copy link
Copy Markdown
Owner

Follow-up intake at 47e966b5bfff653378e79b538025a50a5993df9c against dev 12025981e5a304cdb6b1b54f525ba8554f623977. This PR and #7436 have the identical head 47e966b5bfff653378e79b538025a50a5993df9c, target dev, and identical changed-file lists/patches. Please retain one canonical review PR (the newer #7436 can carry this discussion) and close the other as duplicate, rather than validating/integrating both. The substantive usage review is recorded on #7436. No contribution has been discarded or merged by this comment.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants