From e28c98b0694aa23bb919ca3038af05a54e0d7832 Mon Sep 17 00:00:00 2001 From: efiten Date: Sat, 31 Oct 2026 11:58:19 +0100 Subject: [PATCH 1/2] fix(web): date a registry slice from when it was asked for (#764) The slice was stamped with now() after the answer landed, so a slow answer counted as fresh for a minute from then and kept names off the rows. An older answer that lands after a newer slice no longer replaces it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TDXX3ZV8LEdZgVTNFYFvZi --- web/rowattribution.js | 5 ++++- web/rowattribution.test.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/web/rowattribution.js b/web/rowattribution.js index 610c7e68..45464b83 100644 --- a/web/rowattribution.js +++ b/web/rowattribution.js @@ -64,10 +64,13 @@ export function createRowAttributor({ fetchRegistry, allowed = () => true, now = if (fresh && covers(slice.bounds, bounds)) return slice.index if (failedAt != null && now() - failedAt < RETRY_MS) return null const want = fresh ? union(slice.bounds, bounds) : bounds + // Dated from the question (#764): a slow answer is as old as the moment it + // was asked for, and one that lands after a newer slice does not replace it. + const askedAt = now() const answer = await fetchRegistry(want) if (!answer || answer.status !== 'ok' || answer.truncated) { failedAt = now(); return null } failedAt = null - slice = { bounds: want, at: now(), index: registryIndex(answer.nodes) } + if (!slice || slice.at <= askedAt) slice = { bounds: want, at: askedAt, index: registryIndex(answer.nodes) } return slice.index } return { diff --git a/web/rowattribution.test.js b/web/rowattribution.test.js index 86dea430..5b138d75 100644 --- a/web/rowattribution.test.js +++ b/web/rowattribution.test.js @@ -102,4 +102,35 @@ describe('createRowAttributor (#663)', () => { await a.attribute([{ ...ROW }]) expect(fetchRegistry).toHaveBeenCalledTimes(2) }) + // #764: a slice is as old as the question, not the answer. Stamped when the + // answer landed, a slow answer counted as fresh for a minute from then, and + // the names it lacked stayed off the rows that long. + it('dates a slice from when it was asked for, not from when the answer landed', async () => { + let now = 1000 + const fetchRegistry = vi.fn(async () => { now += 61000; return ok([]) }) + const a = createRowAttributor({ fetchRegistry, allowed: () => true, now: () => now }) + await a.attribute([{ ...ROW }]) + fetchRegistry.mockImplementation(async () => ok([NODE])) + const rows = [{ ...ROW }] + await a.attribute(rows) + expect(fetchRegistry).toHaveBeenCalledTimes(2) + expect(rows[0]._attr).toEqual({ rule: 'node', node: NODE }) + }) + it('does not let an older answer that lands late replace a newer slice', async () => { + let now = 1000 + let answerFirst + const fetchRegistry = vi.fn() + .mockImplementationOnce(() => new Promise((res) => { answerFirst = () => res(ok([])) })) + .mockImplementation(async () => ok([NODE])) + const a = createRowAttributor({ fetchRegistry, allowed: () => true, now: () => now }) + const first = a.attribute([{ ...ROW }]) + now += 61000 + await a.attribute([{ ...ROW }]) + answerFirst() + await first + const rows = [{ ...ROW }] + await a.attribute(rows) + expect(fetchRegistry).toHaveBeenCalledTimes(2) + expect(rows[0]._attr).toEqual({ rule: 'node', node: NODE }) + }) }) From 27e18f28186a0d3ea23b03d60eabeb7f4755fa75 Mon Sep 17 00:00:00 2001 From: efiten Date: Sat, 31 Oct 2026 12:04:29 +0100 Subject: [PATCH 2/2] fix(web): a late registry answer still attributes its own rows (#764) When an older answer lost to a newer slice, the call returned the newer slice's index, which need not cover its rows: a row the registry named read as unnamed. The call now uses its own answer; only the stored slice follows the newer question. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TDXX3ZV8LEdZgVTNFYFvZi --- web/rowattribution.js | 6 ++++-- web/rowattribution.test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/web/rowattribution.js b/web/rowattribution.js index 45464b83..a11b0bd8 100644 --- a/web/rowattribution.js +++ b/web/rowattribution.js @@ -66,12 +66,14 @@ export function createRowAttributor({ fetchRegistry, allowed = () => true, now = const want = fresh ? union(slice.bounds, bounds) : bounds // Dated from the question (#764): a slow answer is as old as the moment it // was asked for, and one that lands after a newer slice does not replace it. + // Its own rows still read by it: the newer slice need not cover them. const askedAt = now() const answer = await fetchRegistry(want) if (!answer || answer.status !== 'ok' || answer.truncated) { failedAt = now(); return null } failedAt = null - if (!slice || slice.at <= askedAt) slice = { bounds: want, at: askedAt, index: registryIndex(answer.nodes) } - return slice.index + const index = registryIndex(answer.nodes) + if (!slice || slice.at <= askedAt) slice = { bounds: want, at: askedAt, index } + return index } return { async attribute(rows) { diff --git a/web/rowattribution.test.js b/web/rowattribution.test.js index 5b138d75..c7d0a1db 100644 --- a/web/rowattribution.test.js +++ b/web/rowattribution.test.js @@ -133,4 +133,19 @@ describe('createRowAttributor (#663)', () => { expect(fetchRegistry).toHaveBeenCalledTimes(2) expect(rows[0]._attr).toEqual({ rule: 'node', node: NODE }) }) + it('still attributes the late answer\'s own rows by that answer, which covers them', async () => { + let now = 1000 + let answerFirst + const fetchRegistry = vi.fn() + .mockImplementationOnce(() => new Promise((res) => { answerFirst = () => res(ok([NODE])) })) + .mockImplementation(async () => ok([])) + const a = createRowAttributor({ fetchRegistry, allowed: () => true, now: () => now }) + const rows = [{ ...ROW }] + const first = a.attribute(rows) + now += 10 + await a.attribute([{ ...ROW, lat: 45, lon: 10 }]) // newer, elsewhere + answerFirst() + await first + expect(rows[0]._attr).toEqual({ rule: 'node', node: NODE }) + }) })