Skip to content

Conversation

@dnouri
Copy link
Owner

@dnouri dnouri commented Jan 10, 2026

After resuming or branching a session, context usage showed 0% because pi-coding-agent--last-usage wasn't populated from the loaded messages.

Root cause: pi-coding-agent--load-session-history displayed messages but didn't extract the usage data from the last assistant message.

Fix:

  • Add pi-coding-agent--extract-last-usage helper to find usage from the last non-aborted assistant message
  • Call this helper after displaying session history

Tests: Integration tests with mock Fortnite conversation + unit tests for edge cases (empty, no assistant, aborted messages).

After resuming or branching a session, context usage showed 0% because
pi-coding-agent--last-usage wasn't populated from the loaded messages.

The fix:
- Add pi-coding-agent--extract-last-usage helper to find usage from the
  last non-aborted assistant message in a messages vector
- Call this helper in pi-coding-agent--load-session-history after
  displaying the history, setting pi-coding-agent--last-usage

The helper follows the existing pattern from message_end event handling:
skips aborted messages (which may have incomplete usage data) and only
extracts usage from valid assistant messages.

Tests added:
- load-session-history-restores-context-usage: Integration test with
  mock Fortnite tips conversation verifying usage is extracted
- load-session-history-skips-aborted-usage: Verifies aborted messages
  are skipped when extracting usage
- extract-last-usage-*: Unit tests for the helper function edge cases
@dnouri dnouri merged commit a65f240 into master Jan 10, 2026
6 checks passed
@dnouri dnouri deleted the fix/context-usage-after-resume branch January 10, 2026 16:02
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.

2 participants