Skip to content

mecatui: context and token counters are not restored on session resume #1822

Closed

Description

@danbarr

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

  1. Run a session long enough to build up significant context. Note the ctx reading in the status line, then /quit.
  2. Resume with mecatui --resume-latest.
  3. Look at the status line before sending anything: the ctx/usage area is empty.
  4. Send a prompt and look at the status line after the turn ends.

Observed

Before /quit:

Image

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:

Image

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.contextTokens is set from TurnEndMsg.Usage.InputTokens (cmd/mecatui/ui/update.go:1166-1168) and m.usage is summed from ResultMsg.Usage in applyResult (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.7K is not a stale or reset value. It is the provider-reported input size of the first turn after resume (↑45.7K matches 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

  1. added
    bugSomething isn't working
    tuimecatui terminal UI (rendering, keybindings, footer, panes, scrollback)
    on Sep 23, 2026
  2. danbarr commented on Sep 23, 2026

    @danbarr
    ContributorAuthor

    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 → first turn.end (45,679 input tokens). The default heuristic compactor 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.

  3. self-assigned this
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtuimecatui terminal UI (rendering, keybindings, footer, panes, scrollback)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions