Skip to content

fix(usage): repair zero-reported input_tokens on non-trivial requests (#10705) - #10757

Merged
diegosouzapw merged 1 commit into
release/v3.8.50from
fix/10705-zero-input-tokens
Aug 19, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.50from
fix/10705-zero-input-tokens

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Closes #10705

Root cause: sanitizeProviderUsageForRequest() in open-sse/utils/usageTracking.ts short-circuited on ANY reportedInput <= 0, treating a provider-reported input_tokens: 0 as automatically acceptable and skipping the local-estimate fallback — even for a real, non-trivial request body. A third-party Claude-compatible relay under-reporting to exactly 0 was passed straight through into stats/logging.

Fix: only treat reportedInput === 0 as plausible when the request body itself is trivial (no serialized body, or 0 bytes); otherwise repair with the existing local tokenizer estimate, same as the over-report path.

Regression test: tests/unit/usage-tracking-zero-input-tokens-10705.test.ts. Verified no regression against the existing over-report guard (tests/unit/stream-impossible-input-usage.test.ts, 8331-usage-buffer-inflation.test.ts, usage-token-buffer.test.ts — 49 tests, all green).

@diegosouzapw
diegosouzapw merged commit 65e1960 into release/v3.8.50 Aug 19, 2026
11 checks passed
@diegosouzapw
diegosouzapw deleted the fix/10705-zero-input-tokens branch August 19, 2026 15:02
giauphan pushed a commit to giauphan/OmniRoute that referenced this pull request Aug 20, 2026
backryun added a commit to backryun/OmniRoute that referenced this pull request Aug 21, 2026


diegosouzapw#10757 (65e1960) taught sanitizeProviderUsageForRequest to repair a
zero-reported input_tokens on non-trivial request bodies with the local
estimate, so an all-zero usage stub no longer reaches
applyClientUsageBuffer as zeros — it arrives repaired and flows through
the buffer path like real usage. The old expectation (estimate path)
predates that repair. Update the characterization to assert the
post-diegosouzapw#10757 flow: buffer → filter, never estimate.
backryun added a commit to backryun/OmniRoute that referenced this pull request Aug 21, 2026


diegosouzapw#10757 (65e1960) taught sanitizeProviderUsageForRequest to repair a
zero-reported input_tokens on non-trivial request bodies with the local
estimate, so an all-zero usage stub no longer reaches
applyClientUsageBuffer as zeros — it arrives repaired and flows through
the buffer path like real usage. The old expectation (estimate path)
predates that repair. Update the characterization to assert the
post-diegosouzapw#10757 flow: buffer → filter, never estimate.
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
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.

[BUG] The input token data statistics are incorrect.

2 participants