You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4ec9cc2
Browse filesBrowse the repository at this point in the historyBrowse files
fix(metadata-protocol): a compile-cache bucket opened by a counter move keeps the row sets read within the last bound (#34592)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9D7K4emLL9dNcp4rQPn22Dw)_Fixes#34554
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么:** 元数据编译缓存(#34494 加的)在注册表计数器变动、开新桶时,不再一律清掉 `sys_metadata`
行缓存;只要这批行是在一个周期(默认 30 秒)内读到的就留着,新桶第一个周期在「这批行读到后满一个周期」时结束。行更旧才照旧清掉。
- **为什么改:** 契约复审 S5 怀疑的情况实测成立:会把存储行注册回注册表的内核上,每次列表读都会推动
`registry.revision`,哪怕注册的东西没变。每次推动都清掉行缓存,于是列表读和其后的单项读全回到数据库。「列表 +
单项」交替时,缓存开着每轮 3 次库读,关着 1 次;三个单项时 7 对 3。
- **风险与回滚:**
新鲜度上限不变:任何答案里的行都不超过一个周期旧,同一进程内的写入照旧立即清缓存。修后同样的交替读与关缓存时一样多。回滚 = revert 本
PR。
- **先看:** `packages/metadata-protocol/src/meta-compile-cache.ts`
里开新桶的那段(`readThroughMetaCompileCache`),再看 `meta-overlay-cache.ts` 新增的
`readOverlayCacheGenerationSince`。
- **两分钟验证:** `pnpm --filter @objectstack/metadata-protocol exec vitest
run src/meta-compile-cache.test.ts`,预期 40 个全过。
- **需要你做的:** 不需要。区线程审核后合入。
## What changes
- `meta-overlay-cache.ts`: the per-engine generation state now records
`since`, the wall-clock time the current generation began (set wherever
the generation moves: a `sys_metadata` write at the middleware seam, a
non-`write` epoch bump, `retireMetaOverlayCache`). Every row set held
under the current generation was read at or after it, because an entry
is stamped with the generation its read started under. New export
`readOverlayCacheGenerationSince(engine)`.
- `meta-compile-cache.ts`: a bucket opened by a counter move
(`registry.revision`, `objectRevision`, the metadata service's
`revision`) no longer always retires the row cache. When the row cache's
generation began less than one bound ago, the rows are kept and the
bucket's first bound ends at `since + ttl`, so no answer carries a row
more than one bound old, which is the bound the retirement was there to
give. When it began a bound or more ago, the bucket retires the rows as
before and its first bound is a full one. Confirmations are unchanged:
each still retires the row cache. The module header says the same.
## Tests
- New group in `meta-compile-cache.test.ts`, on a harness option
`hydrationMovesRevision` (the double's `registerItem` and
`registerObject` move the registry's counters, as every public write of
the real `SchemaRegistry` does through `registry-revision.ts`): a list
read of three stored objects, then 1 or 3 item reads, four rounds. Store
reads per round with the cache on equal the cache-off reads, and after
the first round they are only the item count. Each round asserts the
list read moved `registry.revision` (non-vacuity).
- **Forced test edit, named:** the existing pin "a counter move retires
the row cache: a peer's write the row cache predates is in the new
bucket's answer" asserted the old rule. It is replaced by two pins: (1)
within one bound of the rows' read, a counter move keeps them (no row
read from the store, the earlier answer served) and the peer's write is
in the answer once that bound ends; (2) once the rows are more than a
bound old, a counter move retires them and the peer's write is in the
new bucket's answer with no confirmation reading (the old pin's
assertion, at the age the rule now names).
- [L1 R1, rework 1] `the bucket a counter move opens ends its first
bound one bound after the kept rows were read, not one bound after the
move`: rows read at T, a peer's write and a counter move at T + 20 s,
the earlier answer still served with no row read, and the peer's write
in the answer at T + 30.001 s, less than one bound after the move.
Ablation of the mutant L1 named (`confirmedUntil = now + ttlMs` in the
keep arm): this pin red, `expected 'Widget' to be 'Gadget'`, 1 of 40;
restored, 40 of 40.
- Ablation (one-off, not kept): the keep branch disabled (`if (false &&
…)`), 3 of 39 red: the keep pin (`expected 'Gadget' to be 'Widget'`) and
both alternation pins (`[3,3,3,3]` against `[3,1,1,1]`, `[7,7,7,7]`
against `[7,3,3,3]`); restored, all green.
## Reading (the card's acceptance)
The double's store, three stored `object` rows, `getMetaItems({ type:
'object' })` then N `getMetaItem` reads, per round, store reads counted
at the engine:
| | round 1 | rounds 2 to 5 |
|:--|:--|:--|
| before, cache on, N=1 | 3 | 3 each (list rows, the item's rows, one
`findOne`) |
| before, cache off (`OS_METADATA_COMPILE_CACHE_TTL_MS=0`), N=1 | 3 | 1
each (the `findOne`) |
| before, cache on, N=3 | 7 | 7 each |
| before, cache off, N=3 | 7 | 3 each |
| after, cache on, N=1 / N=3 | 3 / 7 | 1 / 3 each |
"Cache off" is the uncached path the compile cache's own `0` setting
gives (ADR-0156 D6), not a build of `main` before #34494; the one
`findOne` per item read is the same in every row and is not this
cache's.
## Verification
Rework 1 (head a6661f5, one test added, no source change):
`src/meta-compile-cache.test.ts` 40 of 40, `pnpm --filter
@objectstack/metadata-protocol typecheck` exit 0.
At head e62453c:
- `pnpm --filter @objectstack/metadata-protocol exec vitest run
--maxWorkers=2`: exit 0, `Test Files 347 passed | 9 skipped (356)`,
`Tests 23014 passed | 45 skipped (23059)`.
- `pnpm --filter @objectstack/metadata-protocol typecheck`: exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands` derived 67 families;
all 67 run with `< /dev/null`, exit codes captured before any pipe.
`--ran`: `67 derived famil(ies) accounted for — 65 run, 2 NOT-MEASURED
(2 DERIVED from a recorded exit 3)`: `check:dual-build-cjs-loads` and
`check:lean-entry-closure` need a whole-workspace build; CI runs them.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmRfW5u1LRmhWwaYHRp
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmRfW5u1LRmhWwaYHRp -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(metadata-protocol): a list read that registers stored rows no longer sends the reads after it to the store
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
On a kernel whose list read (`getMetaItems`) registers the stored rows back into the schema registry, every list read moves `registry.revision`, even when it registers what is already there. Each move opened a new compile-cache bucket, and opening a bucket retired the `sys_metadata` row cache. So the list read and the item reads after it all went to the store. Measured with a list read of three stored objects followed by item reads, in alternation: 3 store reads per round with the compile cache on against 1 with it off (one item read), and 7 against 3 (three item reads).
11
+
12
+
A bucket opened by a counter move now keeps the row cache when its rows were read within the last bound, and its first bound ends one bound after they were read, so no answer carries a row more than one bound old. When the rows are older than that, opening the bucket retires them, as before. The same alternation now costs what it costs with the compile cache off.
expect((awaitread(h)).item.label).toBe('Widget');// kept: the rows are less than a bound old
681
+
expect(rowReads()).toBe(before);
682
+
now=1_000_000+30_001;// one bound after the rows were read, less than one after the move
645
683
expect((awaitread(h)).item.label).toBe('Gadget');
646
684
});
647
685
686
+
it('a counter move retires the row cache once its rows are more than a bound old: a peer\'s write the row cache predates is in the new bucket\'s answer',async()=>{
687
+
vi.stubEnv('OS_METADATA_OVERLAY_CACHE_TTL_MS','600000');// the row cache outlives every bound here
688
+
constclock=atBound();
689
+
constrows=[storedObject('Widget')];
690
+
consth=harness(rows);
691
+
expect((awaitread(h)).item.label).toBe('Widget');// the row cache is warm
692
+
rows[0]=storedObject('Gadget','2026-11-16T01:00:00.000Z');// a peer replica with no bridge
693
+
clock.pass();
694
+
constmark=onStoreMark(h,async(real)=>real());
695
+
(h.registry.revisionasnumber)++;// a local counter move opens a new bucket
696
+
expect((awaitread(h)).item.label).toBe('Gadget');
697
+
expect(mark.calls).toBe(0);// the new bucket retired the rows: no confirmation was needed
698
+
mark.restore();
699
+
});
700
+
648
701
it('a counter move costs no store read: the new bucket takes its reading at its first bound',async()=>{
649
702
constclock=atBound();
650
703
consth=harness([storedObject('Widget')]);
@@ -674,3 +727,46 @@ describe('[#34206, ADR-0156 D5] at the bound the cache confirms before it recomp
674
727
}
675
728
});
676
729
});
730
+
731
+
describe('[#34554] a list read that hydrates moves a counter, and the reads after it are no dearer than with the cache off',()=>{
732
+
// review#2 S5 on #34494: on a kernel whose list read registers the stored
733
+
// rows back into the registry, every list read moves `registry.revision`
734
+
// with nothing changed. Each move opened a bucket that retired the row
735
+
// cache, so the list read and the item reads after it all went to the
736
+
// store. Measured before the fix: 3 store reads per round with the cache
737
+
// on against 1 with it off (one item), 7 against 3 (three items).
0 commit comments