Skip to content
PidebugCLI & tooling

Debug 0.0% context footer on error termination in pi CLI

Session from pi-mono-sessions on Hugging Face by thomasmustier · MIT · condensed by Coders Talk

5msession
0interventions
GOAL

Investigate why the context percentage in the footer shows 0.0% after a session terminates on error, using session and debug logs to trace the cause.

  1. Prompt · +0
    On error terminated, the context % footer displays 0.0%. Why? See attached session log.
  2. Agent did · +0m
    Read footer.ts and session log; found footer ignores assistant messages with stopReason==='error' and falls back to state.model?.contextWindow||0, causing 0.0%
  3. Prompt · +1m
    Also added a debug log here /pi-debug.log
  4. Agent did · +1m
    Parsed debug log confirming '0.0%/272k' output; traced it to the estimation path using state.messages which is empty after termination, so contextTokens computes to 0
  5. Prompt · +3m
    But the context was not 0% right before the error happened...
  6. Agent did · +4m
    Explained the discrepancy: footer's totals come from sessionManager.getEntries() while the percentage estimate comes from state.messages, which is cleared on error, causing non-zero totals alongside a 0.0% percentage
  7. Prompt · +4m
    Would our fixes in this branch resolve this?
  8. Agent did · +4m
    Checked branch fixes; confirmed they address compaction/new-session estimation but not the error-termination case, since the code still skips stopReason==='error' and still estimates from state.messages
  9. Prompt · +5m
    What tweaks would be needed to do this? Don't write any code, but show me a diff
  10. Outcome · +5m
    Produced a proposed (unapplied) diff for footer.ts to use sessionManager entries when state.messages is empty and to keep last known usage on error, without making any code changes
VERDICT

I'd start by asking it to trace the footer percentage calculation against the debug log directly instead of reading the code first — that got to the root cause faster. Comparing the session log's non-zero totals against the 0.0% render was the key step that exposed the real bug: the estimate path uses in-memory state.messages, which is empty after an error, unlike the totals path which reads from sessionManager entries. I stopped short of applying any code and just wanted a diff to review before deciding on the fix.

I tried this · 0

Discussion · 0

How Builds work