Skip to content

Commit e350186

Browse files
committed
fix(metadata-protocol): the compile cache confirms on the rows' content and retires the row cache (#34206)
Answers L1 6931948189 and contract review 6932160915 on #34494. - The store reading is a digest of every sys_metadata row's content, so a write that leaves updated_at alone, a timestamp-preserving import or a peer with a slow clock still moves it. - Every confirmation retires the overlay row cache and rebases the bucket's stamp: a recompile reads rows at least as new as the reading, and a compile in flight across a confirmation is not stored. - No entry is renewed past 10 bounds, the backstop for what no reading sees. - FilesystemLoader caps the probed type directories at 1000. - Clause-② yes in the changeset; docs, env row and comments follow. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5oyZgRX9Qc1ZHsMRQp
1 parent 00fef25 commit e350186

10 files changed

Lines changed: 297 additions & 64 deletions

File tree

‎.changeset/34206-shared-compile-cache.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
perf(metadata-protocol): the served item read caches its caller-independent compiled answer (ADR-0156)
88

9-
Clause-②: no
9+
Clause-②: yes
1010
Metadata-protocol: none
1111

1212
`getMetaItem` (the served face of `GET /api/v1/meta/:type/:name`, and the per-item read an app bundle makes for every app, object, view, page and dashboard it names) no longer recompiles an item whose sources have not changed. Every caller gets the same answer it got before, the response body and ETag included: only the server's work per request moves.
1313

1414
- **What is cached.** The compiled envelope of a by-name read of `app`, `object`, `view`, `page` and `dashboard` items, per engine. A read for a package, a state, a member or a draft preview is never cached. The per-caller gate, field mask, translation and ETag stay computed on every request, and the live trailers (`registration`, `disabledActions`, `cascadeDeleteObjects`) are read on every hit.
1515
- **What retires it.** Each source counts its own changes at its own mutation point: the `sys_metadata` overlay generation, the schema registry's `objectRevision` and a new `revision` that every public write of `SchemaRegistry` moves (the classification of its public methods is exhaustive by type), and a new `revision` on `MetadataManager`. Any move drops every entry. A source without its counter makes the cache decline.
16-
- **What another process can change.** After a bound (`OS_METADATA_COMPILE_CACHE_TTL_MS`, default 30000 ms) the cache confirms before it recompiles: a reading of the stored rows (count and latest change) and of each loader's backing store (`FilesystemLoader` stats the type directories and files its reads touched). If nothing moved, the entries stand for another bound. A loader that keeps no change mark makes every entry recompile at its bound, never renewed.
16+
- **What another process can change.** After a bound (`OS_METADATA_COMPILE_CACHE_TTL_MS`, default 30000 ms) the cache confirms before it recompiles: a digest of every stored row's content (so a write that leaves `updated_at` alone, or stamps it from a clock that is behind, still moves it) and each loader's reading of its backing store (`FilesystemLoader` stats the type directories and files its reads touched). If nothing moved, the entries stand for another bound, up to 10 bounds from when each was compiled. Every confirmation also retires the overlay row cache, so a recompile reads rows at least as new as the reading, and a read in flight across a confirmation is not stored. A loader that keeps no change mark makes every entry recompile at its bound, never renewed.
17+
- **New public members (additive).** `SchemaRegistry#revision`, `MetadataManager#revision`, `MetadataManager#loaderChangeMark()`, the optional `MetadataLoader#changeMark()` and `FilesystemLoader#changeMark()`.
1718
- `OS_METADATA_COMPILE_CACHE_TTL_MS=0` is the uncached read, the same reads in the same order.
1819

1920
On a showcase Setup bundle, an immediate repeat made 213 database reads before and 9 after.

‎content/docs/concepts/metadata-lifecycle.mdx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ The hash is `sha256:` + 64-hex of a canonical JSON serialization of the body, wi
313313
> the in-process `memory` driver, with no distributed driver behind it — does
314314
> a peer's overlay re-read still lag a remote publish by up to that TTL. See
315315
> [Environment variables](/docs/deployment/environment-variables).
316+
>
317+
> The served by-name read also caches its **compiled** answer for an `app`,
318+
> `object`, `view`, `page` or `dashboard` (ADR-0156), the part that does not
319+
> depend on the caller; the per-caller gate, field mask, translation and
320+
> `ETag` still run on every request. It adds no lag of its own on top of the
321+
> bound above: the same write epoch retires it, as do the schema registry's and
322+
> the metadata service's own change counters. A peer's write that reaches no
323+
> epoch is seen at its own bound, `OS_METADATA_COMPILE_CACHE_TTL_MS` (default
324+
> 30s, `0` disables it), where it reads every `sys_metadata` row's content
325+
> and the metadata files it read, and recompiles if any of them moved, also
326+
> when a write left `updated_at` alone. Each such check also drops the cached
327+
> rows, so the recompile reads the store as it is then, and no compiled answer
328+
> is kept past ten bounds.
316329
317330
---
318331

‎content/docs/deployment/environment-variables.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ With several replicas declared over the Redis cluster driver (`OS_CLUSTER_REPLIC
430430
| `OS_SANDBOX_WALL_CEILING_MS` | number | `30000` | Wall-clock ceiling (ADR-0102) — the backstop that cuts a hook/action body stuck on a host call that never settles (which burns no CPU, so the CPU budget alone would never fire). The effective ceiling is `max(this, cpuBudget)`, so it can never cut a body still inside its CPU budget. Positive integer only; unset keeps 30s. |
431431
| `OS_LOCALIZATION_CACHE_TTL_MS` | number | `30000` | Staleness bound, in milliseconds, for the cross-request cache of a workspace's reference localization (`timezone` / `locale` / `currency`, read from `sys_setting`) — leg C of #11633. `0` means **off**, a real path that restores the uncached query pattern exactly. Unlike `OS_AUTHZ_GRANTS_CACHE_TTL_MS` (which is off by default) this one ships **on**, because its invalidation is synchronous and in-process rather than TTL-bound: a `localization` settings change, a write to `sys_setting` or `sys_platform_setting` (the tables the answer is read from), and a non-`write` bump of the engine write epoch each retire a cached answer immediately. A write to any other object does not. So the TTL only bounds what none of these seams can see — a write made on another replica with no cluster bridge attached at all: neither the `metadata.mutated` channel's receipt path (`applyRemoteMetadataMutation` calls `bumpWriteEpoch`, #13609) nor the `authz.invalidated` bridge, both of which bump this same epoch when attached. ⚠️ A malformed value reads as `0` (off), the opposite arm from the grants variable and deliberately so: there `0` is also the default, whereas here folding `3OOO` (letter O) into the default would hand you a **longer** window than the one you were setting. Deployment config only — never a settings row, because `sys_setting` is the table this cache caches. |
432432
| `OS_METADATA_OVERLAY_CACHE_TTL_MS` | number | `30000` | Staleness bound, in milliseconds, for the cross-request cache of the `sys_metadata` overlay rows read inside `getMetaItems` (the list read) and `getMetaItem` (the served by-name read the REST API-exposure gate makes on every `/data` request) — leg D of #11633. `0` means **off**, a real path that restores the uncached query pattern exactly. Ships **on**, for the same reason as `OS_LOCALIZATION_CACHE_TTL_MS`: invalidation is synchronous and in-process, because every `sys_metadata` write goes through the engine, whose middleware retires the entry when the write's statement completes, before the next read. Outside a transaction that is the commit. Inside an engine transaction it is earlier than the commit: a read that lands between the statement and the commit can keep the pre-commit rows until the next `sys_metadata` write or the TTL. A write to any other object does not retire it; a non-`write` bump of the engine write epoch retires it wholesale. What is cached is the overlay ROW SET only — never the merged answer — so the SchemaRegistry, the MetadataService and the artifact table are re-consulted on every call, cached or not, and the read-side registry hydration keeps running on a cache hit. The TTL therefore bounds one thing: a write made on **another replica** with no cluster bridge attached at all — neither the `metadata.mutated` channel's own receipt path (`applyRemoteMetadataMutation` calls `bumpWriteEpoch` right after registry convergence, #13609) nor the `authz.invalidated` bridge, either of which retires this entry the moment it is attached and fires. ⚠️ A malformed value reads as `0` (off) — same arm and same reason as `OS_LOCALIZATION_CACHE_TTL_MS`. Deployment config only, never a settings row. |
433-
| `OS_METADATA_COMPILE_CACHE_TTL_MS` | number | `30000` | Bound, in milliseconds, for the per-environment cache of compiled item answers ([ADR-0156](https://github.com/objectstack-ai/objectstack/blob/main/docs/adr/0156-compiled-metadata-answer-cache-every-source-counts-its-own-changes.md)): the served item read (`getMetaItem`) of an app, object, view, page or dashboard, which the app bundle (`GET /api/v1/meta/app/:appId/bundle`) and the item reads make. `0` means **off**, a real path: the read is the uncached one, the same reads in the same order. Only the caller-independent answer is cached; the per-caller gate, field mask, translation and `ETag` are computed on every request. A local change is seen at once: the cache keeps the change counter of every source it reads (the `sys_metadata` overlay generation, the schema registry's `revision` and `objectRevision`, the metadata service's `revision`) and drops every entry when one moves; a source without its counter makes it decline. When the bound passes it confirms before it recompiles, with one reading of what this process cannot see (the `sys_metadata` row count and newest `updated_at`, and each metadata loader's own change mark: the file loader stats the directories and files its reads touched); unchanged, the entries stand for another bound; unreadable, nothing is renewed. The bound is therefore how long another replica's write with no cluster bridge, or a file edited under a running process, can stay unseen. ⚠️ A malformed value reads as `0` (off). Deployment config only, never a settings row. |
433+
| `OS_METADATA_COMPILE_CACHE_TTL_MS` | number | `30000` | Bound, in milliseconds, for the per-environment cache of compiled item answers ([ADR-0156](https://github.com/objectstack-ai/objectstack/blob/main/docs/adr/0156-compiled-metadata-answer-cache-every-source-counts-its-own-changes.md)): the served item read (`getMetaItem`) of an app, object, view, page or dashboard, which the app bundle (`GET /api/v1/meta/app/:appId/bundle`) and the item reads make. `0` means **off**, a real path: the read is the uncached one, the same reads in the same order. Only the caller-independent answer is cached; the per-caller gate, field mask, translation and `ETag` are computed on every request. A local change is seen at once: the cache keeps the change counter of every source it reads (the `sys_metadata` overlay generation, the schema registry's `revision` and `objectRevision`, the metadata service's `revision`) and drops every entry when one moves; a source without its counter makes it decline. When the bound passes it confirms before it recompiles, with one reading of what this process cannot see (a digest of every `sys_metadata` row's content, which moves even when a write leaves `updated_at` alone, and each metadata loader's own change mark: the file loader stats the directories and files its reads touched); unchanged, the entries stand for another bound, up to 10 bounds from when each was compiled; unreadable, nothing is renewed. Each confirmation also retires the overlay row cache, so the recompile reads the rows as they are now. The bound is therefore how long another replica's write with no cluster bridge, or a file created, removed or edited under a running process, can stay unseen; a file edit no `stat` can tell apart (same size, within the file system's time grain) is seen within 10 bounds. ⚠️ A malformed value reads as `0` (off). Deployment config only, never a settings row. |
434434
| `OS_INLINE_SEED_BUDGET_MS` | number | `8000` | Time budget for synchronous seed execution at boot before deferring to a worker. |
435435
| `OS_TENANT_AUDIT` | flag | `1` | Set to `0` to silence the tenant-isolation audit warnings emitted by the SQL driver. |
436436

0 commit comments

Comments
 (0)