From d1b16169ace6792d744cb0dbb7ee4a94ce084192 Mon Sep 17 00:00:00 2001 From: Resham Joshi <65915470+iamtoruk@users.noreply.github.com> Date: Fri, 6 Nov 2026 04:59:31 -0800 Subject: [PATCH] fix(grokbot): make only the mirror slices durable, not the import source Marking the whole provider durable also kept a removed usage import's rows, so removing an import no longer restored the local figures. Durability is now a per-source override (SessionSource.durable, which replaces the snapshot flag from the Quick Desktop fix): Grok Bot's mirror slices merge, Quick Desktop's sessions.db replaces, and orphan handling stays with the provider. --- src/parser.ts | 4 ++-- src/providers/grokbot.ts | 6 +++--- src/providers/quickdesk.ts | 2 +- src/providers/types.ts | 10 ++++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index a6d3c48b..80c397fc 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -3982,7 +3982,7 @@ export async function parseProviderSources( // Durable providers (e.g. copilot OTel) never clear existing entries so // that pruned-away data is preserved for monotonic monthly totals. const priorEntry = section.files[source.path] - if ((!provider.durableSources || source.snapshot) && !clearedPaths.has(source.path)) { + if (!(source.durable ?? provider.durableSources) && !clearedPaths.has(source.path)) { delete section.files[source.path] markCacheDirty(diskCache, providerName, source.path) clearedPaths.add(source.path) @@ -4056,7 +4056,7 @@ export async function parseProviderSources( // migrated cache with an anchor the virgin cache had - dropping the // post-compaction residual (#946 validation round 6, see (c6)). // Non-durable providers keep the original overwrite-or-append behaviour. - if (provider.durableSources && !source.snapshot) { + if (source.durable ?? provider.durableSources) { const existingEntry = section.files[source.path] if (existingEntry) { const freshByKey = new Map(turns.flatMap(t => t.calls).map(c => [c.deduplicationKey, c])) diff --git a/src/providers/grokbot.ts b/src/providers/grokbot.ts index 31d754be..c6468472 100644 --- a/src/providers/grokbot.ts +++ b/src/providers/grokbot.ts @@ -266,6 +266,9 @@ async function discoverSessions(dir: string): Promise { project: botName ?? agentId, provider: 'grokbot', sourceId: agentId, + // The mirror is a sliding window: requests that slid out of it stay + // cached, or the bot's history would shrink as it works. + durable: true, ...(botName ? { sourceLabel: botName, agentName: botName } : {}), }) } @@ -280,9 +283,6 @@ export function createGrokbotProvider(persistenceDir?: string): Provider { return { name: 'grokbot', displayName: 'Grok Bot', - // The mirror is a sliding window: requests that slide out of it are kept - // from the cache, or the bot's history would shrink as it works. - durableSources: true, async probeRoots(): Promise { return [{ path: resolveDir(), label: 'client persistence' }] diff --git a/src/providers/quickdesk.ts b/src/providers/quickdesk.ts index 96866f50..2e8925d0 100644 --- a/src/providers/quickdesk.ts +++ b/src/providers/quickdesk.ts @@ -176,7 +176,7 @@ async function discoverSources(): Promise { provider: 'quickdesk', sourceId: 'sessions-db', sourcePath: base.path, - snapshot: true, + durable: false, }) } } diff --git a/src/providers/types.ts b/src/providers/types.ts index 3bdb6df6..51d053a8 100644 --- a/src/providers/types.ts +++ b/src/providers/types.ts @@ -23,10 +23,12 @@ export type SessionSource = { // #992 that exemption is redundant (only ORPHANS age out) — kept as the // explicit statement of intent, not as the thing enforcing it. retainWhilePresent?: boolean - // This source is a projection of a store's current state, not a record, so - // a re-parse replaces its cached calls even under a durableSources provider - // (Quick Desktop's sessions.db estimates, superseded once metrics land). - snapshot?: boolean + // Overrides the provider's durableSources for how a re-parse lands in the + // cache: true merges into the cached calls (Grok Bot's sliding mirror keeps + // requests that slid out), false replaces them (Quick Desktop's sessions.db + // estimates are superseded once metrics land). Orphan handling still + // follows the provider. + durable?: boolean } // Thrown by a parser whose source is temporarily unreadable (a network fetch