Skip to content

fix(session): restore persisted stats when resuming a session#876

Open
abhay-codes07 wants to merge 1 commit into
mistralai:mainfrom
abhay-codes07:fix/resume-restore-stats
Open

fix(session): restore persisted stats when resuming a session#876
abhay-codes07 wants to merge 1 commit into
mistralai:mainfrom
abhay-codes07:fix/resume-restore-stats

Conversation

@abhay-codes07

Copy link
Copy Markdown

Fixes #712
Fixes #713

After resuming a session the context indicator in the bottom right shows 0% (and the session totals reset) until the first new completion arrives. The messages restore fine; only the stats are lost.

Root cause: stats.context_tokens is only ever set from live LLM usage in the agent loop. The values are already persisted in the session metadata on every interaction (save_interaction writes stats.model_dump()), but none of the resume paths read them back.

Change:

  • New AgentStats.restore_from_session(data): validates the persisted payload and copies the values onto the live stats object field by field, in place, so listeners registered on the object (like the context progress meter) fire and existing references stay valid. Invalid or missing payloads are ignored silently, matching how the rest of the metadata is read defensively.
  • Called from all three resume paths: vibe --resume / --continue at startup, the in-app session picker, and the ACP loadSession handler. The ACP path also sends a usage update right after loading, which previously reported zeros.

Testing:

  • Unit tests for the new method: field restoration, listener firing, invalid payloads ignored
  • Integration tests for the CLI resume path against a session directory on disk, with and without a stats block in the metadata
  • tests/agent_loop/test_agent_stats.py, tests/cli/test_ui_session_resume.py and the ACP session tests pass on Linux, ruff and pyright clean

@elGrogz two long-standing duplicate reports close with this one.

Resuming a session showed the context indicator at 0% (and zeroed
session totals) until the first new completion arrived, because
stats.context_tokens is only updated from live LLM usage. The values
are already persisted in the session metadata on every interaction;
none of the resume paths read them back.

Add AgentStats.restore_from_session, which validates the persisted
payload and copies the values onto the live stats object in place so
registered listeners fire and existing references stay valid, and call
it from all three resume paths: vibe --resume/--continue at startup,
the in-app session picker, and the ACP loadSession handler (which also
sends its usage update from these stats). Invalid or missing stats
payloads are ignored.

Fixes mistralai#712
Fixes mistralai#713
Copilot AI review requested due to automatic review settings July 3, 2026 09:36
@abhay-codes07
abhay-codes07 requested a review from a team as a code owner July 3, 2026 09:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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: When I resume the session context show 0 and no previous message visible bug: when I resume a session context always shows 0%

2 participants