Compare commits

...

2 Commits

Author SHA1 Message Date
Peter Steinberger
e2065e8d96 fix: reset session tokens on /new (#1542) (thanks @robbyczgw-cla) 2026-01-24 00:15:12 +00:00
Robby
78d9f5baff 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
2026-01-24 00:09:33 +00:00
4 changed files with 21 additions and 1 deletions

View File

@ -19,6 +19,7 @@ Docs: https://docs.clawd.bot
- CLI: suppress diagnostic session/run noise during auth probes.
- Linux: include env-configured user bin roots in systemd PATH and align PATH audits. (#1512) Thanks @robbyczgw-cla.
- TUI: render Gateway slash-command replies as system output (for example, `/context`).
- TUI/Gateway: reset session token counters on `/new` and refresh the footer immediately. (#1542) Thanks @robbyczgw-cla.
- Media: preserve PNG alpha when possible; fall back to JPEG when still over size cap. (#1491) Thanks @robbyczgw-cla.
- Agents: treat plugin-only tool allowlists as opt-ins; keep core tools enabled. (#1467)
- Exec approvals: persist allowlist entry ids to keep macOS allowlist rows stable. (#1521) Thanks @ngutman.

View File

@ -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;

View File

@ -345,11 +345,19 @@ describe("gateway server sessions", () => {
const reset = await rpcReq<{
ok: true;
key: string;
entry: { sessionId: string };
entry: {
sessionId: string;
inputTokens?: number;
outputTokens?: number;
totalTokens?: number;
};
}>(ws, "sessions.reset", { key: "agent:main:main" });
expect(reset.ok).toBe(true);
expect(reset.payload?.key).toBe("agent:main:main");
expect(reset.payload?.entry.sessionId).not.toBe("sess-main");
expect(reset.payload?.entry.inputTokens).toBe(0);
expect(reset.payload?.entry.outputTokens).toBe(0);
expect(reset.payload?.entry.totalTokens).toBe(0);
const badThinking = await rpcReq(ws, "sessions.patch", {
key: "agent:main:main",

View File

@ -409,8 +409,15 @@ export function createCommandHandlers(context: CommandHandlerContext) {
case "reset":
try {
await client.resetSession(state.currentSessionKey);
// Clear token counts after reset to avoid stale display while refreshing. (#1523)
state.sessionInfo.inputTokens = 0;
state.sessionInfo.outputTokens = 0;
state.sessionInfo.totalTokens = 0;
tui.requestRender();
chatLog.addSystem(`session ${state.currentSessionKey} reset`);
await loadHistory();
await refreshSessionInfo();
} catch (err) {
chatLog.addSystem(`reset failed: ${String(err)}`);
}