[Bug][0.1.7-rc.2] Failed turn (HTTP 400/429) leaves all-zero usage samples; contextPressure projection permanently zeroed — ContextMeter shows 0% #7972
Phantomcyber-ai
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
When a turn fails with a provider error (HTTP 400/429), a placeholder all-zero usage chunk
(
{ inputTokens: 0, outputTokens: 0, totalTokens: 0 }) is written into theassistant/attemptstream. The
contextPressureprojection indsh-token-meterfolds this zero sample as if it werea valid measurement and overwrites the last good
pressureTokensvalue. Since theprojection-cache checkpoint sits at the session tail, the zero is never recomputed on later loads —
the UI
ContextMeterpermanently shows 0% for that session, even though the session dataitself is intact.
Reproduction
input 399 + cacheRead 274560→
pressureTokens = 274959(ContextMeter ≈ 27%).400: insufficient credits(singleattempt) and
429: token plan entitlement exhausted(retry loop, 5 attempts, one all-zerousage chunk per attempt,
turn/enderror).contextPressure: { pressureTokens: 0, sampledSurfaceTokens: <n> }; projected tokens evaluateto
max(0, …) = 0→ ContextMeter shows 0% permanently (checkpoint seq equals the sessiontail, so replay never recomputes it).
Current behavior
tokenUsage.lastis polluted with all-zerobuckets the same way (per-session totals unaffected because the turn ended with the error).
persisted event log (v4 JSONL) — e.g. a cache rebuild / version migration restores the 0%.
provider errors.
assistant/messageusage showstotalTokens = 275685), and offline replay of the same raw events through the real kernelpackages (
Session.create+ token-meter measure) returnstotalTokens = 277806, baselineusage— the meter computes correctly from events; only the persisted projection checkpointgot poisoned.
pressureTokensto the lastvalid value (input + cacheRead of the last valid sample), after which the meter displays
correctly again.
Expected behavior
Usage samples belonging to failed attempts (HTTP 4xx/5xx, turn ended with error) must not be
folded into
contextPressure. Defensively, an all-zero sample (totalTokens === 0 && inputTokens === 0 && outputTokens === 0) should be ignored whenever a previous valid sampleexists.
Environment
0.1.7-rc.2(exe FileVersion0.1.7-rc.2), Windows 11 (build 26200)@deepseek-ai/*all0.1.7-rc.2; affected package@deepseek-ai/dsh-token-meter(repo path
packages/llm/token-meter)All reactions