Repository navigation
fix(bridge): keep the adapter's usage on a translator-overflow terminal - #7322
vadymhimself wants to merge 1 commit into
Conversation
When an adapter raised `translation_buffer_limit` as an error event, the bridge handed it to `terminateForTranslatorOverflow`, which ignored its argument and synthesized a usage-less `response.failed`. A turn the provider had already billed was therefore logged with zero usage and cost. The overflow terminal now reports the event's usage through `onUsage` and on the `response.failed` frame, as the ordinary error terminal already does. The client-facing error is unchanged. Co-Authored-By: Claude Code <[email protected]>
|
✅ Deterministic PR hygiene checks passed. |
✅ READY
Review readiness checklist
✅ 4/4 boxes ticked. This pull request has been marked Ready for Review. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
Intake/scoped review at The translator-overflow terminal now forwards an adapter-provided usage snapshot to both the wire and onUsage, rather than logging an already-billed turn as zero. Preserve the no-usage/local-overflow case and exactly-once terminal cleanup. The new fixture is focused evidence; it does not establish every usage/cancellation path. Current-head functional workflows are awaiting fork approval; that is pending execution, not a passing test result. No local suite was run for this branch in this intake. No workflow approval, new scan, live configuration change or merge was performed. Required review/readiness gates remain in force. |
|
Thank you @vadymhimself! This fix is carried into #7352 as a cherry-pick with your authorship intact (commit "fix(bridge): keep the adapter's usage on a translator-overflow terminal"). I checked it against current |
Summary
translation_buffer_limitas anerrorevent,bridgeToResponsesSSEhands that event toterminateForTranslatorOverflow, which ignored its argument and synthesized a usage-lessresponse.failed. A turn the provider had already billed was therefore logged with zero usage and zero cost, which is exactly the oversized traffic worth seeing in a usage report.onUsageand on theresponse.failedframe, the same way the ordinaryerrorterminal a few lines below already does. Overflows detected by the bridge itself (a thrown budget error, which carries no usage) are unchanged.upstream_error/translation_buffer_limit) is unchanged; onlysrc/bridge/sse.tschanges.Verification
an adapter-raised translator overflow keeps the usage the turn already consumedintests/adapters/translator-budget.test.ts, run before the src change:bun test tests/adapters/translator-budget.test.ts-> 20 pass, 1 fail (Expected to contain: "\"input_tokens\":120"; the frame had"usage":null). After the change:bun test tests/adapters/translator-budget.test.ts tests/adapters/bridge.test.ts-> 123 pass, 0 fail. The test also assertsonUsagereceives the usage exactly once.bun x tsc --noEmit-> exit 0.bun scripts/file-size-ratchet.ts-> passed.bun run test:changed(Bun 1.4.3 viaOCX_TEST_RUNNER_BUN) -> 29319 pass, 37 skip, 1 fail across 1266 files. The single failure,tests/cli/cli-connect-readiness.test.ts"a rejected preferred runtime falls back without rewriting the saved selection", fails identically on an unmodifiedupstream/dev8640c2f checkout on this machine (local-environment dependent) and is unrelated to the bridge.bun run testwas not run locally:test:changedalready covered 1266 files through the changed module's import graph; the remainder is left to CI.Checklist
Source: carried from the vadymhimself fork build (
bridge/sse.tshunk of commit 8fb1bbb), re-authored smaller: the fork also replaced the client error with the adapter's own event; this PR keeps the existing error and carries only the usage.🤖 Generated with Claude Code
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.
Summary by CodeRabbit