Skip to content

Metadata compile cache: replace the content digest with a write-moved column on sys_metadata #34522

Closed as not planned

Description

@objectstack-fleet

repo:objectstack#1 · os-project-manager · session_01FEkQ5oyZgRX9Qc1ZHsMRQp

Follow-up to #34206 (PR #34494, ADR-0156 D5).

What

The compile cache in packages/metadata-protocol/src/meta-compile-cache.ts confirms at each bound (OS_METADATA_COMPILE_CACHE_TTL_MS, default 30 s) with readStoreMark. That reading is a sha1 digest of every sys_metadata row's id, state, version, checksum, updated_at and stored metadata. It reads the whole table, bodies included, because no column on sys_metadata moves on every write regardless of the writer's clock. The row count plus the newest updated_at missed a peer's write stamped at or before the newest row, an engine-bypassing write that leaves updated_at alone, and a timestamp-preserving import (L1 6931948189 M2, contract review 6932160915 S1 on #34494).

Cost measured

Comment 6933083314 on #34494 has the numbers. The showcase store holds 0 rows, so the bundle readings there do not show this cost. A synthetic run of the same reading through better-sqlite3 (SELECT of the six columns, sort, sha1, without the engine's own per-row work) took:

rows body ≈ median
100 4 kB 2.4 ms
1 000 4 kB 23 ms
10 000 4 kB 252 ms

The cost is linear in the store's size and paid once per bound per engine, on the request that crosses the bound. The seat accepted it for #34494.

Wanted

A column (or a store-side counter) on sys_metadata that every write moves, whatever path it takes and whatever its clock says, so the confirmation can read a small value instead of every body. One shape is a monotonic change sequence bumped by the store on insert, update and delete, including a delete's tombstone, and read as max plus count. It has to hold for writes that bypass the engine, which is the class the digest exists for. The current D7 pins in meta-compile-cache.test.ts (bookkeeping-preserving bypass, skewed clock, outage, unprovisioned store) must stay green on the new reading.

Out of scope

The compile cache's counters, stamp rebase, overlay retire and 10-bound age cap stay as #34494 landed them.

Activity

  1. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#1 · os-project-manager · session_01FEkQ5oyZgRX9Qc1ZHsMRQp

    An update to the description above. Since #34494 b7751333 (contract review 6933112344 S3), the reading no longer digests the stored bodies. It digests id, type, name, namespace, package_id, bundle_member, extends, strategy, state, version, checksum and updated_at. The class this card exists to close is now narrower: a writer that bypasses the engine and rewrites a body while leaving version, checksum and updated_at exactly as they were. Today that class is bounded only by the compile cache's 10-bound age cap.

    The same synthetic run on the bookkeeping-only reading took 0.3, 2.2 and 21 ms at 100, 1 000 and 10 000 rows. On a showcase store seeded with 5 000 rows, a renewed bundle reload took 150–192 ms with 42 queries, against a 491 ms recompile (delta 6933554702 on #34494). The column this card asks for would let the reading drop to one small value and close the bypass class without the cap.

  2. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: first touch → domain:server · p2 · theme: performance · 2026-11-17T00:47Z

    ⛔ Not a claim.

    The compile cache confirms freshness every 30 s by hashing every sys_metadata row, bodies included, which reads the whole table. A write-moved column would make that check one indexed read. This is a performance follow-up of #34206, which the maintainer raised to p1: p2.

  3. added
    domain:server
    enhancement
    pm:queue
    priority:p2
    on Nov 17, 2026
  4. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA

    Premise corrected · written at 2026-11-17T03:55Z · ⛔ not a claim

    Area o2-G measured this card on origin/main, and the seat accepts the reading. The premise holds, but on narrower ground than the body states. Since #34494 (b7751333), readStoreMark in meta-compile-cache.ts (around line 318) digests only id, type, name, namespace, package_id, bundle_member, extends, strategy, state, version, checksum and updated_at. It does not read body. That is already noted in this card's 00:27Z update and in #34494 comments 6933083314 and 6933554702. So the "bodies included" wording in the body and in the triage note is out of date.

    What remains to close: a write that bypasses the engine and changes body without moving version, checksum or updated_at. Today only the age cap on the ten bounded entries covers that case. The card's route stands: a write-moved mark on sys_metadata (a column, or a store-side counter) that also moves on writes that bypass the engine, with a migration for existing stores. That makes it a large card (L, cross-driver, likely Metadata-protocol other than none), so it gets its own card thread under area o2-G. It starts from main after PR #34592 merges, because both touch meta-compile-cache.ts.

    Acceptance, narrowed: a write that bypasses the engine and changes only body invalidates the cached compile on the next read, with no age cap needed for it, and the digest no longer has to cover the fields the mark replaces.

  5. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmRfW5u1LRmhWwaYHRp

    Claim: PM loop round 1 (area o2-G, card thread)
    Session: session_01ADHkmRfW5u1LRmhWwaYHRp (area)
    Thread session: session_01ADHkmPquc84xN6v16Lhehb
    Account: os-steve
    Branch: claude/project-thread-vnis1f
    Domain: domain:server
    Seat: repo:objectstack#2
    File surface: a store-moved write sequence on sys_metadata (packages/metadata-core/src/objects/sys-metadata.object.ts and the store paths that write it, including engine-bypassing writes and deletes), the confirmation reading in packages/metadata-protocol/src/meta-compile-cache.ts (readStoreMark) and its tests, a root .changeset/; the #34494 counters, stamp rebase, overlay retire and 10-bound age cap are out of scope
    Container & model: L, mode:thread (card thread cmsg_01FdL1XeUyvVNxLreh3F4Qi92F7s3B2v8sj3AFvaJ1ChC4, reporting to area o2-G), model: default judgment tier, effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack: the confirmation reading digests every sys_metadata row's bookkeeping columns, and a bypass write that keeps version, checksum and updated_at is caught only by the 10-bound age cap | none: no reading taken | every engine with the compile cache on; follow-up of #34206 / ADR-0156 D5
    Thread-read: 6937759089
    Premise: corrected 6937759089
    Serial constraints cleared: #34592 (card #34554, area o2-G) touches meta-compile-cache.ts, meta-compile-cache.test.ts and meta-overlay-cache.ts and is in the merge queue; this card branches from main after it merges. No other of the 47 open PRs touches packages/metadata-protocol/src/meta-* or sys-metadata.object.ts (files read at claim).
    Pre-claim lane: packages/metadata-protocol + packages/metadata-core → domain:server; routed to area o2-G by the seat, card thread opened by the seat (large: L, store-side mechanism across drivers)
    Pre-claim deps: no Blocked-by: on the card; #34494 is merged; serial after #34592 as above
    Prior rulings read: metadata,compile,cache,replace,content,digest,write-moved,column,sys_metadata → 205 hits; ADR-0127 D6, ADR-0131 D7, ADR-0139 D4, ADR-0143 D3, ADR-0156 D6, ADR-0005 Decision §8, ADR-0029 D9.7, ADR-0045 Decision §2, ADR-0045 Decision §6, ADR-0059 Decision §2; thread: none; repo: objectstack-ai/objectstack. ADR-0156 D5 (the cache's confirmation) is the governing text and the card is its execution; the Clause-② and Metadata-protocol lines are re-derived by the card thread on the final file list, and an unsettled store-mechanism fork goes back as needs_decision.

  6. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 17, 2026
  7. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA

    Release: needs a maintainer decision · 2026-11-17T04:00Z
    The card thread of area o2-G stopped before code with needs_decision. It wrote no code and pushed nothing, and its analysis was read on origin/main 31096af83. The claim 6937793361 is released: pm:dispatched → needs-user-decision, and lease:o2-G and the assignee are removed. Resume-from: none (no produce).

    维护者速读 · 待裁

    一句话问题: 元数据编译缓存要能发现「绕过平台、直接用 SQL 只改了正文」的写。能做到这一点的只有数据库自己,也就是平台第一次引入数据库触发器。现行 ADR-0156 D1(b) 把这类写交给时间上限兜底(最长约 5 分钟可见)。

    现状(读码加一次 SQLite 探针): 缓存确认时摘 sys_metadata 十二列记账字段,不读正文。平台自己的写会动这些列,所以 30 秒内可见。只有仓外的裸 SQL 只改正文、不动记账列时,要等 10 个周期的年龄上限(默认约 5 分钟)。仓里今天没有任何平台自建的数据库触发器。

    Governing text: ADR-0156 D1(b)(绕过引擎的写由时间界覆盖)、D2(计数器在进程内,不上线路)。

    选项 做什么 客户可感知后果 工作量
    A SQL 类数据库用触发器维护一个写计数,确认时读这一个值;读不到就退回今天的摘要。MongoDB、OData 不变 运维用 SQL 只改元数据正文,30 秒内生效,不再等约 5 分钟;读取成本从约 21 ms 降到约 0.004 ms(1 万行) L/XL:四种 SQL 方言的触发器和迁移;托管 MySQL 常缺建触发器的权限,要降级告警;若做成驱动契约,还要改 spec(交你审批)
    B 在平台写入路径上加一列写序号,不用触发器 关不掉裸 SQL 这一类,和现状差不多 M;不推荐
    C 不做,维持 ADR-0156 D1(b) 的时间上限,关卡 裸 SQL 只改正文最长约 5 分钟才可见;平台自己的写不受影响 0

    os-decision-facets
    ① 项目长远合理性:A 是唯一能关掉这一类的形状,但要引入平台的第一个数据库触发器,四种方言各一套 DDL,权限不足时还要降级;C 沿用已裁的时间界。
    ② 实际业务拉动:仓内找不到绕过平台、用 SQL 改元数据正文的写者;仓外只有运维 SQL 和导入工具这类假设场景,没有客户撞上的记录。零实测拉动。
    ③ 防 AI 犯错:AI 写元数据走平台写入路径,记账列一定会动,不落在这一类;A 和 C 对 AI 写应用没有差别。
    ④ 创业阶段不扩散:C 最省;A 引入一整套新的存储侧机制。
    Prior rulings read: ADR-0156 D1(b)、D2;cluster.mdx §6.1(跨节点元数据版本已退役。卡线程读为各节点读自己存储里的一个值,不算线路版本,席位同意这个读法);#34494 评论 6933083314、6933554702。
    Analysis-tier: seat default.

    推荐:C(卡线程的推荐是「如果要做就选 A,否则选 C」;席位推荐 C)。只看①会倾向 A;②④ 翻转了它:零实测拉动,而 A 是一整套新的存储机制。如果你认为运维用 SQL 改元数据必须 30 秒内可见,选 A,并同时定两件事:做成驱动契约(spec,交你审批)还是由元数据层按方言另建;建不了触发器时是降级告警还是拒绝启动。
    裁后执行: 选 C ⇒ 席位按 not planned 关卡,理由引 ADR-0156 D1(b)。选 A ⇒ 卡回 pm:queue,按你定的两个子项开卡线程(区 o2-G)。选 B ⇒ 不推荐;若选,回 pm:queue 并写明它关不掉的那一类。

  8. added
    needs-user-decision
    and removed
    pm:dispatched
    on Nov 17, 2026
  9. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA

    Ruled: C · written at 2026-11-17T04:02Z
    Ruling-ref: the maintainer's words in the fleet project at 2026-11-17T04:02Z, answering the decision analysis 6937838431: 「有人绕过平台直接用 SQL 改元数据正文,不考虑这种情况」.

    Closed as not planned. A write that bypasses the platform and changes only the metadata body stays covered by ADR-0156 D1(b)'s time bound (10 × TTL), as it is today. No database trigger, no write-moved column. The pin the stored body is not read at the bound in meta-compile-cache.test.ts keeps holding that behaviour. needs-user-decision comes off in this stroke.

  10. removed
    needs-user-decision
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain:serverenhancementpriority:p2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions