-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
After aborting a streaming response with C-c C-k, the context percentage in the header line resets to 0%, even though context was consumed before the abort.
Reference behavior
The TUI skips aborted messages when tracking usage:
// compaction.ts, line 91
function getAssistantUsage(msg: AgentMessage): Usage | undefined {
if (msg.role === "assistant" && "usage" in msg) {
const assistantMsg = msg as AssistantMessage;
if (assistantMsg.stopReason !== "aborted" && assistantMsg.stopReason !== "error" && assistantMsg.usage) {
return assistantMsg.usage;
}
}
return undefined;
}Only successful completions (end_turn, tool_use) update the context display.
Current behavior
Usage is captured from any assistant message, including aborted ones:
("message_end"
(let ((message (plist-get event :message)))
(when (equal (plist-get message :role) "assistant")
(setq pi--last-usage (plist-get message :usage))))) ; captures even abortedWhen aborted, usage may be nil or incomplete, causing the header to show 0%.
Suggested fix
Only update pi--last-usage for successful completions:
(when (and (equal (plist-get message :role) "assistant")
(member (plist-get message :stopReason) '("end_turn" "tool_use"))
(plist-get message :usage))
(setq pi--last-usage (plist-get message :usage)))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working