Repository navigation
mecatui: context and token counters are not restored on session resume #1822
Description
Summary
When resuming a session with mecatui --resume-latest, the status line's context meter and token counters start empty and only reappear after the first prompt. When they come back, they only reflect the new run, not the resumed session. In one case the context reading after resume was much lower than before quitting, which suggests the counters (and possibly the context sent to the model) don't match the session being resumed.
Steps to reproduce
- Run a session long enough to build up significant context. Note the
ctxreading in the status line, then/quit. - Resume with
mecatui --resume-latest. - Look at the status line before sending anything: the ctx/usage area is empty.
- Send a prompt and look at the status line after the turn ends.
Observed
Before /quit:
ctx 100% ⚠ · 135.2K/128K (the reading above 100% comes from our gateway misreporting the model's context window and isn't related to this issue)
After resume, no counters until the first prompt. After the first prompt:
ctx 35% · 45.7K/128K · ↑45.7K ↓163 ⊕45.7K cache 0%
No compaction seemed to happen on resume. There was none of the usual compaction delay.
Expected
- On resume, the status line shows the resumed session's context occupancy and cumulative token usage (and the context window) right away, before any new prompt.
- After the first post-resume turn, cumulative totals continue from the session's prior totals instead of restarting from zero.
Notes from the code
- Both counters are populated only from live stream events.
m.contextTokensis set fromTurnEndMsg.Usage.InputTokens(cmd/mecatui/ui/update.go:1166-1168) andm.usageis summed fromResultMsg.UsageinapplyResult(cmd/mecatui/ui/update.go:1637). Nothing on the resume path (applySessionReady/finishStartupResume) seeds them from the stored session, so they start at zero until a turn completes. - The post-resume
45.7Kis not a stale or reset value. It is the provider-reported input size of the first turn after resume (↑45.7Kmatches it). So that turn really sent ~46K input tokens, against ~135K reported for the last turn before quitting. Open question: is the resumed session's request history smaller than before/quit(something dropped or trimmed on reload), or was the pre-quit figure inflated?cache 0%on that turn also suggests the prompt prefix didn't match what was cached before. That could be a changed history or just an expired cache.
Related
Separately, the counters only update when a run ends, not during it. Live updates mid-run would be a nice follow-up but are out of scope here.
Activity
danbarr commentedon Sep 23, 2026
Follow-up on the open question above. The smaller context after resume came from a normal automatic compaction; resume itself dropped nothing.
The session's event log shows the resumed run went
user_prompt→compaction→compaction.archive→ firstturn.end(45,679 input tokens). The defaultheuristiccompactor makes no model call, so it finishes almost instantly. That's why there was no visible delay. It does leave a "history compacted" notice in the scrollback.Compaction happened to fire on the first prompt after resume because that prompt pushed the heuristic estimate over the 0.8 trigger. It fired that late, with provider-reported input already at ~153K against a 128K window, because of a separate problem with the trigger. Filed as #1823.
This issue is still valid as scoped: counters aren't seeded on resume, so they start empty and then only reflect the new run.