fix(sessions): reset token counts to 0 on /new (#1523)

- Set inputTokens, outputTokens, totalTokens to 0 in sessions.reset
- Clear TUI sessionInfo tokens immediately before async reset
- Prevents stale token display after session reset

Fixes #1523
This commit is contained in:
Robby
2026-01-23 21:41:56 +00:00
committed by Peter Steinberger
parent da3f2b4898
commit 511a0c22b7
2 changed files with 10 additions and 0 deletions

View File

@@ -251,6 +251,10 @@ export const sessionsHandlers: GatewayRequestHandlers = {
lastChannel: entry?.lastChannel, lastChannel: entry?.lastChannel,
lastTo: entry?.lastTo, lastTo: entry?.lastTo,
skillsSnapshot: entry?.skillsSnapshot, skillsSnapshot: entry?.skillsSnapshot,
// Reset token counts to 0 on session reset (#1523)
inputTokens: 0,
outputTokens: 0,
totalTokens: 0,
}; };
store[primaryKey] = nextEntry; store[primaryKey] = nextEntry;
return nextEntry; return nextEntry;

View File

@@ -408,6 +408,12 @@ export function createCommandHandlers(context: CommandHandlerContext) {
case "new": case "new":
case "reset": case "reset":
try { try {
// Clear token counts immediately to avoid stale display (#1523)
state.sessionInfo.inputTokens = null;
state.sessionInfo.outputTokens = null;
state.sessionInfo.totalTokens = null;
tui.requestRender();
await client.resetSession(state.currentSessionKey); await client.resetSession(state.currentSessionKey);
chatLog.addSystem(`session ${state.currentSessionKey} reset`); chatLog.addSystem(`session ${state.currentSessionKey} reset`);
await loadHistory(); await loadHistory();