Skip to content

Commit 3fa027d

Browse files
committed
fix(metadata-protocol): a new compile bucket retires the overlay row cache (#34206)
Answers L1 6933589708 M1 and contract review 6933631137 S4 on #34494: a bucket opened by a counter move compiled from row-cache rows up to a bound old, so a peer's write could stay unseen for two bounds. Opening a bucket now retires the row cache and rebases its stamp, as a confirmation does, with no store reading. Pinned. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5oyZgRX9Qc1ZHsMRQp
1 parent b775133 commit 3fa027d

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎packages/metadata-protocol/src/meta-compile-cache.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,17 @@ describe('[#34206, ADR-0156 D5] at the bound the cache confirms before it recomp
634634
mark.restore();
635635
});
636636

637+
it('a counter move retires the row cache: a peer\'s write the row cache predates is in the new bucket\'s answer', async () => {
638+
vi.stubEnv('OS_METADATA_OVERLAY_CACHE_TTL_MS', '600000'); // the row cache outlives every bound here
639+
atBound();
640+
const rows = [storedObject('Widget')];
641+
const h = harness(rows);
642+
expect((await read(h)).item.label).toBe('Widget'); // the row cache is warm
643+
rows[0] = storedObject('Gadget', '2026-11-16T01:00:00.000Z'); // a peer replica with no bridge
644+
(h.registry.revision as number)++; // a local counter move opens a new bucket
645+
expect((await read(h)).item.label).toBe('Gadget');
646+
});
647+
637648
it('a counter move costs no store read: the new bucket takes its reading at its first bound', async () => {
638649
const clock = atBound();
639650
const h = harness([storedObject('Widget')]);

‎packages/metadata-protocol/src/meta-compile-cache.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
* bound while it runs wait for it, and its failure reaches all of them. A
8080
* bucket opened by a counter move takes no reading: its first bound ends at
8181
* a confirmation that drops its entries and takes the reading later bounds
82-
* renew on, so a local change costs no store read.
82+
* renew on, so a local change costs no store read. Opening it retires the
83+
* overlay row cache, as a confirmation does, so its entries never carry
84+
* rows older than the bucket.
8385
*
8486
* ⛔ A renewal is a claim about what was looked at (ADR-0156 D5). When the
8587
* confirmation cannot read one of those (the store cannot be read, the
@@ -415,10 +417,14 @@ export async function readThroughMetaCompileCache<T>(
415417

416418
let bucket = buckets.get(engine);
417419
if (bucket === undefined || !sameStamp(bucket.stamp, stamp)) {
418-
// A new bucket opens its first bound without a reading: its entries
419-
// live one bound, as the row cache's do, and the first confirmation
420-
// drops them and takes the reading later bounds are renewed on. So a
421-
// counter move costs no store read.
420+
// A new bucket opens its first bound without a reading: the first
421+
// confirmation drops its entries and takes the reading later bounds
422+
// are renewed on, so a counter move costs no store read. It retires
423+
// the overlay row cache first, as a confirmation does: what it
424+
// compiles reads rows from now on, never rows that cache filled
425+
// before a peer's write, so its entries are at most one bound old.
426+
const overlay = retireMetaOverlayCache(engine);
427+
if (overlay !== undefined) stamp = { ...stamp, overlay };
422428
bucket = { stamp, mark: undefined, confirmedUntil: Date.now() + ttlMs, confirming: undefined, entries: new Map() };
423429
buckets.set(engine, bucket);
424430
}

0 commit comments

Comments
 (0)