From 8778c9d92031cbb1f0f0571b915c29305bc1ced6 Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 5 Nov 2026 17:02:16 +0100 Subject: [PATCH] fix(memory): known line rematches on live entries after the status read --- mods/memory/hooks/register.test.ts | 13 +++++++++++++ mods/memory/hooks/register.ts | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mods/memory/hooks/register.test.ts b/mods/memory/hooks/register.test.ts index 09057d0..0ed33ce 100644 --- a/mods/memory/hooks/register.test.ts +++ b/mods/memory/hooks/register.test.ts @@ -2671,6 +2671,19 @@ test('TE7: the status reader runs only for a candidate', async ( expect(w.runs.length - known).toBe(1) }) +test('TE7b: a live successor sharing the span of a dead entry wins', async ( + $, on, +) => { + const older = entryText('BLK-001', 'old remote access', 'Solution', + 'Old fix.') + `seen: \`${KN_SPAN}\`\n` + const w = await bootKnown($, on, { files: { [BLK]: older + KN_ENTRY } }) + w.proc = { stdout: [ + '| BLK-001 | 2026-01-01 | old remote access | superseded |', + '| BLK-002 | 2026-02-01 | remote access | open |'].join('\n') } + const out = await failing($, w, EXIT1 + KN_SPAN) + expect(out).toEqual({ ...(w.answer as object), context: [KN_LINE] }) +}) + test('TE4b: two concurrent failing calls inject one line', async ( $, on, ) => { diff --git a/mods/memory/hooks/register.ts b/mods/memory/hooks/register.ts index ce008e1..d157a98 100644 --- a/mods/memory/hooks/register.ts +++ b/mods/memory/hooks/register.ts @@ -1185,7 +1185,7 @@ export function onContextStart(st: State, session: string): void { /** * Takes the IDs not yet seen in the context whose line costs (`chars`, * parallel to `ids`) still fit RECALL_CAP, and records them. Synchronous: - * called after the last await, so two racing callers never both claim. + * called after the reads, so two racing callers never both claim. */ export function claim( st: State, @@ -1401,8 +1401,8 @@ async function captureMilestones( } /** - * The live BLK or LRN entry `key` matches. The match runs on every entry - * first: the status reader is spawned only for a candidate ID. + * The live BLK or LRN entry `key` matches. A match on every entry gates + * the status reader; the live entry is then rematched on the statuses. */ async function liveCandidate( $: Api, @@ -1415,8 +1415,11 @@ async function liveCandidate( const id = matchOf(buildIndex(failing, undefined), key) if (id === undefined) return undefined const status = await statusMap($, root) - if (status === undefined || !isLive(status, id)) return undefined - return assembleEntries(texts, status).find(e => e.id === id) + if (status === undefined) return undefined + const entries = assembleEntries(texts, status) + const kept = entries.filter(e => FAILURE_KINDS.has(e.kind)) + const liveId = matchOf(buildIndex(kept, status), key) + return entries.find(e => e.id === liveId) } /**