Skip to content

fix(usage): retain Kiro prompt estimates in hosted tool paths (carry #7620) - #7744

Merged
lidge-jun merged 2 commits into
devfrom
fix/carry-7620-kiro-sidecar-usage
Oct 26, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/carry-7620-kiro-sidecar-usage

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Carries #7620 by @martinbcg onto current dev (the original is a 45-behind author draft). The Responses hosted web-search and image/video paths built adapter requests without recording the adapter's prompt estimate (usageLog.inputTokens), so for Kiro a request that merely declared web_search or image_generation logged only the new turn's few tokens instead of the full replayed prompt. Both onRequestBuilt callbacks in src/server/responses/sidecar-execution.ts now record it, matching ordinary adapter dispatch. Usage totals, per-model input, physical-attempt usage and daily activity are affected; client compaction accounting is not.

The adapter reference and the transport ownership row are updated. Source change is identical to #7620; only the base moved.

Verification

Windows, pinned Bun 1.4.4, on this exact tree:

  • Regression first: with sidecar-execution.ts reverted to origin/dev, tests/responses/responses-sidecar-usage.test.ts gives 1 pass / 2 fail (web-search and images undercount); with the fix, 3 pass.
  • bun test tests/responses/responses-sidecar-usage.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts: 32 pass, 0 fail.
  • bun x tsc --noEmit: exit 0. bun run structure:check: passed.

Full local suite NOT RUN (shared-host resource exception); hosted Ubuntu shards on this head cover the rest.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Supersedes #7620.

Co-authored-by: Martin Becerra 197874+martinbcg@users.noreply.github.com

Summary by CodeRabbit

  • Bug Fixes
    • Usage records and daily activity now include the estimated prompt tokens for requests using hosted search or image tools, even when those tools aren’t invoked. Estimates can include replayed conversation history and apply to both the request and its processing attempt.
  • Documentation
    • Clarified that token usage remains an estimate and credits aren’t inferred from token counts.

Carry of #7620 onto current dev. The hosted web-search and image/video
sidecar paths now record the adapter's usageLog.inputTokens estimate in
onRequestBuilt, matching ordinary adapter dispatch.

Co-authored-by: Martin Becerra <197874+martinbcg@users.noreply.github.com>
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 26, 2026 05:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T05:46:27.647358Z dcf99e5 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between dcf99e5 and 416075f.

Files selected for processing: 1
  • scripts/test-layout/layout-adapters.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The image and web-search sidecar callbacks now record numeric adapter input-token estimates in the usage log context. Regression tests check persisted and daily usage for requests with no sidecar, web search, and image tools. The Kiro usage documentation describes these estimates.

Changes: Kiro usage accounting

Layer / File(s) Summary
Capture sidecar prompt estimates
src/server/responses/sidecar-execution.ts, structure/transports/responses.md, docs-site/src/content/docs/reference/adapters.md
The image and web-search callbacks copy numeric input-token estimates from built requests into the usage log context. The ownership notes and Kiro usage documentation describe per-build prompt estimates.
Verify usage accounting
tests/responses/responses-sidecar-usage.test.ts, tests/fixtures/test-layout-expected.json, scripts/test-layout/layout-adapters.json
Tests cover requests without sidecars and with web-search or image tools. They check response success, one dispatch, estimated request and attempt usage above 20,000 input tokens, and matching daily totals. Test layout mappings register the test.

Priority: Normal

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

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to 41607

The reviewed change has no identified merge-blocking correctness, accounting, security, or availability issue.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving Kiro prompt usage estimates for hosted tool paths. It matches the implementation and test coverage.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 …
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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 github-actions Bot added the bug Something isn't working label Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

Avoid a new explicitShards entry that collides with #7635's layout-server shard.

Co-authored-by: Martin Becerra <197874+martinbcg@users.noreply.github.com>
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration decision for v2.93.0 (lane L-D1): merging into dev by squash.

  • Exact head 416075fa24d90285b0f3a9baec8654dc78b16c4c: PR CI 40291971200 passed (aggregate ci, four test shards, gates); Catalog async contracts passed. The change is a two-line logging callback plus docs and a test, with nothing platform-specific; no lane=all run was needed or dispatched.
  • Independent review round 1: PASS with zero findings. Both callbacks match ordinary dispatch, a rebuild replaces the estimate before sending, there is no double counting, and only Kiro supplies this metadata today. The one later commit only moved the test registration into the existing layout-adapters shard, so it no longer collides with fix(live): bound WebSocket close without releasing live ownership #7635's shard entry.
  • Regression first: with the fix reverted, responses-sidecar-usage.test.ts gives 1 pass / 2 fail (web-search and image paths undercount); with it, 3 pass.
  • Merged with current dev 3b4e04ae1 locally on Bun 1.4.4: tsc --noEmit exit 0, structure check passed, 41 sidecar-usage, layout and ratchet tests passed with 0 failures.

This carries #7620 by @martinbcg; the squash keeps the Co-authored-by trailer.

@lidge-jun
lidge-jun merged commit 2d8463a into dev Oct 26, 2026
29 of 30 checks passed
@lidge-jun
lidge-jun deleted the fix/carry-7620-kiro-sidecar-usage branch October 26, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant