fix(copilot): journal-scope shutdown keys without a fingerprint bump

Extra High HOLD on #1054: timestamp-only keys still collided across
journals, and the provider-wide rollup-ts-v1 bump dropped present
OTel sources, erasing conversations already pruned from the DB.
Identity is now (session, model, timestamp, journal basename).
Legacy :n keys migrate on that JSONL file only.
This commit is contained in:
Aditya Vikram Singh 2026-08-20 09:52:56 +05:30
parent a5ed4535cd
commit a3ea24859e
5 changed files with 177 additions and 25 deletions

View file

@ -2822,6 +2822,24 @@ function getOrCreateProviderSection(cache: SessionCache, provider: string): Prov
return section
}
function isLegacyCopilotShutdownKey(key: string, journalId: string): boolean {
return key.includes(':shutdown:') && !key.endsWith(`:${journalId}`)
}
// Drop occurrence-index / timestamp-only shutdown calls from one JSONL cache
// entry so the durable union does not keep `:n` next to the new journal-keyed
// calls (double count). OTel / JetBrains / transcript keys do not include
// `:shutdown:` and are left alone.
function stripLegacyCopilotShutdownCalls(entry: CachedFile, journalId: string): void {
const next: CachedTurn[] = []
for (const turn of entry.turns) {
const calls = turn.calls.filter(call => !isLegacyCopilotShutdownKey(call.deduplicationKey, journalId))
if (calls.length === 0) continue
next.push(calls.length === turn.calls.length ? turn : { ...turn, calls })
}
entry.turns = next
}
function cachedFileNeedsProviderReparse(providerName: string, sourcePath: string, cached: CachedFile): boolean {
// Antigravity data comes from the live server, not from the conversation file.
// A 0-turn cache entry may just mean the server was unavailable last run.
@ -2832,6 +2850,16 @@ function cachedFileNeedsProviderReparse(providerName: string, sourcePath: string
// title, model, and timestamp changes.
if (providerName === 'devin') return true
// #1051: migrate old Copilot CLI shutdown keys (`:n` or timestamp-only)
// without a provider-wide fingerprint bump. A bump would drop the present
// OTel DB source and erase conversations already pruned from that DB.
if (providerName === 'copilot') {
const journalId = basename(sourcePath)
return cached.turns.some(turn =>
turn.calls.some(call => isLegacyCopilotShutdownKey(call.deduplicationKey, journalId)),
)
}
if (providerName !== 'gemini') return false
return cached.turns.some(turn =>
@ -3208,6 +3236,9 @@ async function parseProviderSources(
if (provider.durableSources) {
const existingEntry = section.files[source.path]
if (existingEntry) {
if (providerName === 'copilot') {
stripLegacyCopilotShutdownCalls(existingEntry, basename(source.path))
}
const existingKeys = new Set(
existingEntry.turns.flatMap(t => t.calls.map(c => c.deduplicationKey))
)