Skip to content

fix(bridge): keep the adapter's usage on a translator-overflow terminal - #7322

Closed
vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
AgentRadarLabs:fix/bridge-translation-overflow-usage
Closed

vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
AgentRadarLabs:fix/bridge-translation-overflow-usage

Conversation

@vadymhimself

@vadymhimself vadymhimself commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • When an adapter raises translation_buffer_limit as an error event, bridgeToResponsesSSE hands that event 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 zero cost, which is exactly the oversized traffic worth seeing in a usage report.
  • The overflow terminal now reports the event's usage through onUsage and on the response.failed frame, the same way the ordinary error terminal a few lines below already does. Overflows detected by the bridge itself (a thrown budget error, which carries no usage) are unchanged.
  • The client-facing error object (upstream_error / translation_buffer_limit) is unchanged; only src/bridge/sse.ts changes.

Verification

  • New test an adapter-raised translator overflow keeps the usage the turn already consumed in tests/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 asserts onUsage receives 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 via OCX_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 unmodified upstream/dev 8640c2f checkout on this machine (local-environment dependent) and is unrelated to the bridge.
  • Full bun run test was not run locally: test:changed already covered 1266 files through the changed module's import graph; the remainder is left to CI.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (No docs change needed: usage accounting only.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (No secrets or auth behaviour touched.)

Source: carried from the vadymhimself fork build (bridge/sse.ts hunk 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

  • Bug Fixes
    • Translation buffer limit failures now include available token-usage information in the failure response.
    • Usage from adapter-reported errors is also delivered to usage reporting, while other overflow failures continue without usage details.

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]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

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.

✅ 4/4 boxes ticked.

This pull request has been marked Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers notified: @lidge-jun @Ingwannu

@github-actions
github-actions Bot marked this pull request as draft October 18, 2026 15:32
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 435fd661-70f8-4016-b748-3b5d502bca7b
📥 Commits

Reviewing files that changed from the base of the PR and between 8640c2f and 1fa32a8.

📒 Files selected for processing: 2
  • src/bridge/sse.ts
  • tests/adapters/translator-budget.test.ts

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

📝 Walkthrough

When an adapter error event causes translator-buffer overflow, the SSE bridge reports supplied usage through onUsage and includes normalized usage in the response.failed snapshot. The bridge test checks both outputs.

Changes: Translator overflow usage

Layer / File(s) Summary
Handle overflow usage
src/bridge/sse.ts, tests/adapters/translator-budget.test.ts
The overflow handler reads usage from adapter error events, reports it through onUsage, and adds normalized usage to the failure snapshot when present. The test checks the failure code, input-token usage, and callback value.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 1fa32

Adapter-raised translator overflow now preserves supplied usage in the callback and failure response without changing the client-facing error. No concrete merge-blocking risk is established.

Pre-merge checks: Passed 5
Check name Status Explanation
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 1 functions across 2 files.
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.
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 adapter usage on translator-overflow terminal responses.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • 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 marked this pull request as ready for review October 18, 2026 15:39
@Ingwannu

Copy link
Copy Markdown
Owner

Intake/scoped review at 1fa32a8534a9b11f7398aab09d2d4de58b48fd56.

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.

@lidge-jun

Copy link
Copy Markdown
Owner

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 dev: the overflow branch returns before the ordinary error terminal's onUsage, so the usage is reported once, and your regression test pins that. It rides with the sidecar overflow fix for #7316, and structure/transports/responses.md now documents the usage preservation. Leaving this open for the maintainer to close when #7352 merges.

@lidge-jun

Copy link
Copy Markdown
Owner

Thank you for this fix! It has been absorbed into #7352 (merged into dev as 0a995db), with you credited there. Closing this one in favor of that PR.

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

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants