From dfca95e93f84309e7c5b5cedf275bc11a54ef230 Mon Sep 17 00:00:00 2001 From: Turtle Date: Wed, 29 Jul 2026 21:51:22 +0800 Subject: [PATCH] fix(tui): remove disposable query index on exit --- apps/cli/src/tui.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/cli/src/tui.ts b/apps/cli/src/tui.ts index e96f9b515e..9fcc3336d9 100644 --- a/apps/cli/src/tui.ts +++ b/apps/cli/src/tui.ts @@ -18,6 +18,7 @@ */ import { randomUUID } from 'node:crypto' +import { rm } from 'node:fs/promises' import { join, resolve } from 'node:path' import { tmpdir } from 'node:os' import { fileURLToPath } from 'node:url' @@ -226,6 +227,7 @@ export async function runTui( ? loadPersonalPatches(NAME) ?? [] : loadOverlayPatches(NAME, resolveConfigPath(resolve(config), undefined)), ] + const queryIndexPath = join(tmpdir(), SESSION_QUERY_DB) const ctx = await boot( NAME, replaceTree ? resolveConfigPath(resolve(configReplace), undefined) : BASE_CONFIG, @@ -246,7 +248,14 @@ export async function runTui( hostCtx.provide(CONFIGURED_AGENT_IDENTITIES_KEY, { [MAIN_AGENT_ID]: identity }) // The query database is a disposable derived index with single-process // ownership. Keep it process-local while it indexes the shared logs. - hostCtx.provide(SESSION_QUERY_SQLITE_PATH_KEY, join(tmpdir(), SESSION_QUERY_DB)) + hostCtx.provide(SESSION_QUERY_SQLITE_PATH_KEY, queryIndexPath) + hostCtx.effect(() => async () => { + await Promise.all([ + rm(queryIndexPath, { force: true }), + rm(`${queryIndexPath}-wal`, { force: true }), + rm(`${queryIndexPath}-shm`, { force: true }), + ]) + }, 'launcherSessionQueryPath.cleanup') if (resumeHost !== undefined) hostCtx.provide('tuiResumeHost', resumeHost) // Seed the first turn only for a fresh session, so resuming never // re-invokes the skill.