fix: reset session tokens on /new (#1542) (thanks @robbyczgw-cla)

This commit is contained in:
Peter Steinberger 2026-01-24 00:15:12 +00:00
parent 78d9f5baff
commit e2065e8d96
3 changed files with 16 additions and 6 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

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

@ -408,15 +408,16 @@ 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;
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();
await client.resetSession(state.currentSessionKey);
chatLog.addSystem(`session ${state.currentSessionKey} reset`);
await loadHistory();
await refreshSessionInfo();
} catch (err) {
chatLog.addSystem(`reset failed: ${String(err)}`);
}