From 511a0c22b72eb3e67a5b5595dde4b1423b6063f3 Mon Sep 17 00:00:00 2001 From: Robby Date: Fri, 23 Jan 2026 21:41:56 +0000 Subject: [PATCH] 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 --- src/gateway/server-methods/sessions.ts | 4 ++++ src/tui/tui-command-handlers.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/gateway/server-methods/sessions.ts b/src/gateway/server-methods/sessions.ts index f31c726bb..df59a3f31 100644 --- a/src/gateway/server-methods/sessions.ts +++ b/src/gateway/server-methods/sessions.ts @@ -251,6 +251,10 @@ export const sessionsHandlers: GatewayRequestHandlers = { lastChannel: entry?.lastChannel, lastTo: entry?.lastTo, skillsSnapshot: entry?.skillsSnapshot, + // Reset token counts to 0 on session reset (#1523) + inputTokens: 0, + outputTokens: 0, + totalTokens: 0, }; store[primaryKey] = nextEntry; return nextEntry; diff --git a/src/tui/tui-command-handlers.ts b/src/tui/tui-command-handlers.ts index 7bedb4d62..a14172809 100644 --- a/src/tui/tui-command-handlers.ts +++ b/src/tui/tui-command-handlers.ts @@ -408,6 +408,12 @@ export function createCommandHandlers(context: CommandHandlerContext) { case "new": case "reset": 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); chatLog.addSystem(`session ${state.currentSessionKey} reset`); await loadHistory();