v1.3.155
v1.3.155
Fixes
Context usage display — baseline collapse & CacheRead semantics
TUI ctx indicator showed absurdly small numbers (e.g. ctx 76/358K instead of ctx 204/358K).
Root cause was three-fold:
-
RecordUsage ignored CacheRead for Anthropic protocol — Anthropic's SSE events split input tokens into
input_tokens(non-cached only) andcache_read_input_tokens(cached portion).RecordUsageonly usedinput_tokens, producing a baseline roughly 3–4× too small. Now detects Anthropic additive semantics viaPromptTokensTotal > InputTokensand addsCacheRead. OpenAI/GeminiInputTokensalready includes cached tokens (no double-counting). -
RecordUsage collapsed on InputTokens=0 — when a provider fallback path didn't fill
InputTokens, the old code setbaselineTokens = 0 + OutputTokens. Now skips the baseline update entirely whenInputTokens <= 0, preserving the previous estimate. -
Anthropic
message_deltaoverwrotemessage_startusage — themessage_deltaSSE event only carriesoutput_tokensreliably; itsinput_tokensfield is often 0 or partial. The old code unconditionally overwrote the correct values frommessage_start. Now only updates frommessage_deltawhen the value is non-zero andmessage_starthadn't already set it.
Session restore — all context messages lost on resume
Resuming a session after compaction loaded zero context messages, causing the agent to lose all conversation history.
store.gosetsCheckpointMessageCount = len(ContextMessages)(the full post-compaction message list).- The old restore code in
sessions.godidmsgs = msgs[CheckpointMessageCount:], producing an empty slice. - Fix: removed the obsolete slicing —
ContextMessagesis already the checkpoint-aware slice built byloadSession().
Anthropic provider fallback — missing InputTokens
When the stream completed without receiving usage events (e.g. retry fallback), the provider only set OutputTokens. Now estimates InputTokens via CountTokens, matching the OpenAI provider's behavior.