xonecas.io
64875
Mc

mini-coder / commit 4b62adb

fix: preserve status bar context tokens on interrupt, skip redundant auto-title DB calls

Status bar: only update lastContextTokens when the new value is
non-zero. On ESC interrupt the turn-error event reports 0 context
tokens (no step finished), which was overwriting the previous valid
value and hiding the ctx segment from the status bar.

Auto-title: add a `titled` boolean to ActiveSession so
autoTitleSession is called only on the first turn. Previously every
turn hit the DB with a no-op UPDATE (WHERE title = "").

xonecas2026-03-21 4b62adba554c43908e7eb11a6f7aa120e35b3c46 parent bfda23b

2 files changed

src/agent/session-runner.ts+5−2
@@ -233,9 +233,12 @@ export class SessionRunner {
233233 lastAssistantText = extractAssistantText(historyMessages);
234234 this.totalIn += inputTokens;
235235 this.totalOut += outputTokens;
236- this.lastContextTokens = contextTokens;
236+ if (contextTokens > 0) this.lastContextTokens = contextTokens;
237237 touchActiveSession(this.session);
238- autoTitleSession(this.session.id, text);
238+ if (!this.session.titled) {
239+ autoTitleSession(this.session.id, text);
240+ this.session.titled = true;
241+ }
239242
240243 // Prune coreHistory after each turn so the next turn starts lean.
241244 // The DB retains the full history; this only affects in-memory context.
src/session/manager.ts+9−2
@@ -19,19 +19,26 @@ export interface ActiveSession {
1919 model: string;
2020 messages: CoreMessage[];
2121 createdAt: number;
22+ titled: boolean;
2223 }
2324
2425 export function newSession(model: string, cwd: string): ActiveSession {
2526 const id = generateSessionId();
2627 const row = createSession({ id, cwd, model });
27- return { id, model, messages: [], createdAt: row.created_at };
28+ return { id, model, messages: [], createdAt: row.created_at, titled: false };
2829 }
2930
3031 export function resumeSession(id: string): ActiveSession | null {
3132 const row = getSession(id);
3233 if (!row) return null;
3334 const messages = loadMessages(id);
34- return { id: row.id, model: row.model, messages, createdAt: row.created_at };
35+ return {
36+ id: row.id,
37+ model: row.model,
38+ messages,
39+ createdAt: row.created_at,
40+ titled: row.title !== "",
41+ };
3542 }
3643
3744 export function touchActiveSession(session: ActiveSession): void {