Repository navigation
Commit 9e6fee1
feat(spec, plugin-audit): a sealed object names its chain column with lifecycle.seal.chainField (#34351)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
Fixes #34164
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbSUQWB2j9eHYsRcrCiq1X1C)_
Clause-②: yes (widening). A sealed object may name its chain column with
`lifecycle.seal.chainField`; the default stays `tenant_id`, and an
object that seals today is byte-identical.
Metadata-protocol: added
Skills-docs: follow-up #33773
## 维护者速读
- 改了什么:审计封存对象可以用 `lifecycle.seal.chainField` 指定按哪一列分组织成链(默认仍是
`tenant_id`);封存器、`os audit verify`
现场校验和证明包统一经一个函数读取链值。编写期拒绝点名的列:对象没有的列、取值不是文本的列(数字、布尔、日期、日期时间、JSON、多值)、`id`/`created_at`、以及同时列在
`valueFields` 里的列。既无 `tenant_id` 又没写 `chainField`
的对象仍可通过编写,由封存器报错且不封存(这一半是 #34352)。
- 为什么改:企业版的 AI 审计日志 `sys_ai_audit_log` 的组织在平台注入的 `organization_id` 列里,没有
`tenant_id`,今天根本无法封存;cloud#4128 等这条框架接缝。
- 风险与回滚:默认 `tenant_id`
的对象叶子输入、签名体、根逐字节不变(有基线摘要钉住);新键可选,新增的拒绝都只针对新键,主干上能解析的声明一条也不多拒。已有检查点的对象改
`chainField` 会让校验失败(已实测并写进文档)。回滚即撤掉本 PR。含 ADR-0154 附注,属 Tier H 面。
-
先看:`packages/spec/src/data/object.zod.ts`(`refuseUnknownSealChainField`
的四种拒绝与
`nonTextChainColumnType`)、`packages/plugins/plugin-audit/src/audit-seal/sealer.ts`(五处读链改走
`chainValueOf`)、ADR-0154 文末附注。
- 两分钟验证:`pnpm --filter @objectstack/spec exec vitest run
src/data/object-lifecycle-seal-chain-field-34164.test.ts`,预期 25
条全绿:数字、日期、JSON、多值列以及 `id`、与 `valueFields` 重叠的列都在
`lifecycle.seal.chainField` 处被拒,文本与 lookup 列照常通过。
- 需要你做的:审阅并合并(含 `docs/adr/**`,需维护者批准)。
## What changes
- **`@objectstack/spec`.** `lifecycle.seal` gains the optional
`chainField`: the column whose value is the organization chain a sealed
row joins. `refuseUnknownSealChainField` refuses a NAMED column, each
time with one located issue at `lifecycle.seal.chainField`:
- a column the object does not have. Declared fields count, and so do
the columns the registry injects (`resolveInjectedSystemColumns`):
`organization_id` counts unless the object opts out of the tenant
column;
- (round 3, review S1) a column whose value is not one text on every
store. The set is derived, not listed: `NUMERIC_VALUE_TYPES`,
`BOOLEAN_VALUE_TYPES`, `CALENDAR_DATE_TYPES`, `INSTANT_TYPES` and
`STRUCTURED_JSON_TYPES` from the field-value contract, plus any field
`isMultiValueField` calls multi-value. A declared column is judged by
its own definition; an injected one by the definition the registry
injects (`injectedSystemColumnDefs`), so the injected `updated_at` (a
`datetime`) is refused. `chainValueOf` reads a chain only from a
non-empty string, so such a column would put rows into the deployment
chain with no report;
- (round 3, review S1) `id` and `created_at`, through
`isSealLeafOrderColumn`, the predicate the `valueFields` refusal now
reads too (extracted from its inline check, same two names);
- (round 3, review S2) a column `valueFields` also lists: the leaf would
commit the value while the chain carries it in clear in every checkpoint
and proof bundle.
The default case, an object that names no `chainField`, is not judged at
authoring: that half is #34352. The reference docs regenerate.
- **`@objectstack/plugin-audit`.** One reader, `chainValueOf(row,
chainField)`, with `sealChainFieldOf(lifecycle)` for the default, both
in `audit-seal/canonical.ts`. It replaces the sealer's and the
verifier's `tenantOf`. The sealer reads it at its five chain reads; the
live check reads it for rows no checkpoint holds, which is also where
the proof bundle's `unsealed` entries come from. The checkpoint's signed
`tenant_id` member keeps its name and carries the chain value. No source
change in round 3.
- **ADR-0154.** One note, appended. Round 3: its status cites hand-off
6912069272 (the 09:00Z ruling) and #34352, and says an object with
neither column still parses and is reported by the sealer (S4); D10
records the round-3 refusals and that the chain column is fixed once the
object has checkpoints, with what a change costs, measured (S1, S2, S3);
D5, D10 and the "Names this record fixes" row each gain a dated pointer
to the note (N1).
- **`os audit verify`.** No source change: `--org` passes through as
`orgs` to the live check, which reads the chain column.
- **Docs.** `content/docs/data-modeling/objects.mdx` § Sealed audit
objects teaches `chainField`: its default, every name authoring refuses
(round 3 adds the non-text, leaf-order and `valueFields` refusals), that
an object with neither column still parses and is reported, the
empty-value rule, `--org`, and (round 3) that the chain column is fixed
once the object has checkpoints. The changeset says the same.
## Tests
-
`packages/spec/src/data/object-lifecycle-seal-chain-field-34164.test.ts`
(25 tests): the key parses for the injected `organization_id`, a
declared field, and (round 3 control) a declared `text`, `lookup` and
`select` column. A seal without the key is unchanged. Refused at the
key, each asserted by code, path and the message's first sentence: an
unknown name, an undeclared `tenant_id`, `organization_id` under the
three tenant opt-outs; (round 3) a declared `number`, `currency`,
`boolean`, `date`, `datetime`, `json` and `multiselect` column, a
`lookup` declared `multiple: true`, the injected `updated_at`; `id` and
`created_at` declared, and `id` only the driver provides; a chain column
also in `valueFields`, declared or the injected `organization_id`.
-
`packages/plugins/plugin-audit/src/audit-seal/audit-seal-chain-field-34164.test.ts`
(52 tests):
- Live `ObjectKernel` over SQLite: one chain per organization by the
injected `organization_id`; `verifyAuditLedger({ orgs: ['org_x'] })`
reports only org_x; a row edited below the hooks reads `modified` in its
own chain.
- Byte identity against digests from the base sealer, for the default
and for `chainField: 'tenant_id'`.
- A definition that skipped the parse and names a column it lacks is not
sealed, and is reported at `error`.
- (round 3) For every `FieldType` with a canonical rule, the spec
refuses it as a chain column exactly when the sealer's own rule
(`AUDIT_SEAL_TYPE_RULES`) is not `text`; `select`, `radio`, `lookup` and
`user` with `multiple: true` are refused. This holds the derived spec
set to the reader's rules.
- (round 3, S3, measured) On the in-memory store, an object sealed by
`tenant_id` and then switched to `chainField: 'org_ref'`: the next pass
seals the last sealed window's row again under the new chain
(checkpoints `org:org_a window r1`, `org:org_a window r2`, then
`org:org_b window r2`, `org:org_b window r3`); the whole check reports
`org:org_b#0:listed_twice` and is not ok; scoped to `org_b`, the row
sealed earlier reads `late`, unsealed, and the check is not ok.
-
`packages/cli/src/commands/audit/verify.chain-field-34164.integration.test.ts`:
unchanged in round 3 (the real command, spawned, `--org org_x` / `--org
org_y`).
<details><summary>Readings on head 55812f7 (round 3)</summary>
- Under os-verify-lock, VERDICT command-exit 0 (held 1363s on a shared
box): `@objectstack/plugin-audit` whole suite Test Files 98 passed (98),
Tests 1623 passed (1623); `typecheck` exit 0. `@objectstack/spec` whole
suite Test Files 936 passed (936), Tests 28607 passed, 1 todo;
`typecheck` exit 0.
- Card files, run as single files outside the lock (declared below):
spec Tests 25 passed (25); plugin-audit Tests 52 passed (52).
- `pnpm --filter @objectstack/spec check:generated` after a spec build:
first run 1 of 14 stale (`content/docs/references/**`, from the new
`.describe()`), regenerated with `--fix`; second run "All 14 generated
artifacts are up to date".
- `@objectstack/cli` card file: not re-run; no CLI file and no
plugin-audit source changed in round 3. Round-1 readings stand.
</details>
<details><summary>Ablations, round 3 (each through
scripts/ablation-replace.mjs: anchor hit once, blob moved, then restored
to HEAD's blob with git diff HEAD empty)</summary>
- **Non-text refusal** (`if (nonText !== null)` made dead): spec card
file 9 failed (the seven declared types, the multi-value lookup, the
injected `updated_at`); plugin-audit card file 24 failed (every
non-`text` rule type and the four `multiple: true` cases).
- **Leaf-order refusal** (the chain-field `isSealLeafOrderColumn` branch
made dead): spec card file 3 failed (`id` declared, `created_at`
declared, `id` from the driver).
- **`valueFields` overlap refusal** (made dead): spec card file 2 failed
(declared column, injected `organization_id`).
- No `dist/` preflight was owed: the spec suite runs on its own `src/`,
and plugin-audit's vitest config aliases `@objectstack/spec` to source.
- Round 1's ablations (chain column, through the CLI, bytes,
unknown-name refusal, sealer backstop) stand; their files did not
change.
</details>
## Acceptance notes
- **Option A, by the seat's shape ruling (hand-off 6912069272).**
Authoring judges only a NAMED `chainField`. An object that names none
and has no `tenant_id` still parses, and the sealer still reports it at
`error` and does not seal it. Refusing that case, and a non-text
`tenant_id`, at parse would refuse declarations that parse today; that
half is #34352. The sealer-time check stays for definitions that skip
the parse.
- **Every round-3 refusal needs the new key, so none narrows.**
`lifecycle.seal` is a strict object: on `main` any `chainField` is
refused as an unknown key. Each added refusal fires only when
`chainField` is present, so nothing that parses on `main` is refused
here, and `Clause-②: yes (widening)` / `Metadata-protocol: added` hold.
- **How the non-text set was derived.** From the field-value classes
(ADR-0104 D1) and from what `chainValueOf` accepts (a non-empty string):
numbers and booleans are never strings; `date` / `datetime` and JSON
payloads are text on one store and a `Date` or parsed value on another,
which is why the sealer gives them their own canonical rules. `time`
stays allowed (its stored form is always `HH:MM` text, sealer rule
`text`). Types with no canonical rule (`password`, `secret`, `formula`,
the file types) are not judged as chain columns: the sealer does not
seal an object that declares one. The plugin-audit cross-check above
pins the agreement per type.
- **A definition that skipped the parse with a non-text chain column**
still seals its rows into the deployment chain, as a non-text
`tenant_id` does on `main` today; the sealer has no type check for the
chain column. Noted, not built: the default half belongs with #34352.
- **An import cycle, deliberate and function-only.** `object.zod.ts`
imports `resolveInjectedSystemColumns` and now
`injectedSystemColumnDefs`; both modules import `isTenancyDisabled` back
from `object.zod.ts` (the second through the first). Each side calls the
other only at parse time. The field-value sets are read inside a
function too, never at module evaluation, since `field-value.zod` sits
in the `field.zod` evaluation cycle.
- **Loose ends.** "A `chainField` also listed in `valueFields`" is now
refused (S2). The platform-global deployment case stays accepted as
shipped, per the review's ①: a `chainField: 'organization_id'` passes
authoring, and the sealer reports that object at `error` and does not
seal it.
- **Not taken from the review:** N2 (`sealChainFieldOf` answers
`tenant_id` for an empty or non-string `chainField` on a definition that
skipped the parse) and N3 (`sys_audit_checkpoint.chain_key` is sized for
an organization id).
- **Skills still to teach the key:**
`skills/objectstack-data/rules/lifecycle.md` § Sealing and the stale
verifier claim in
`skills/objectstack-data/evals/objects-fields-relationships.json` go to
#33773 (the `Skills-docs:` line). `skills/**` is not touched here.
## Verification
- Round 3 gates on 55812f7: `node scripts/pm/dispatch-gates.mjs
--commands --repo objectstack-ai/objectstack` over the seven round-3
paths derived 120 families. 117 exited 0 (the three changeset-reading
gates re-run after the last changeset commit, exit 0). Three answered
PREREQUISITE NOT MET (exit 3) on unbuilt closures and are NOT MEASURED
locally: `check:skill-examples` (client SDK `dist/`), `check:i18n`
(workspace CLI `dist/`) and `check:dual-build-cjs-loads` (a
whole-workspace build); the shared verify lock stayed held by other runs
for each try at those builds. All three run inside `Lint & Repo Gates`,
success on d1d44a3 and on 55812f7. `--ran` with exit codes recorded:
120 derived, 117 run, 3 NOT-MEASURED, 0 UNRUN.
- Round 3 PR-body guards on this exact body:
`check-partof-closing-keyword` exit 0; `check-closing-keyword-parity
--body` exit 2 (the report: only the card's own closing line on line 2,
bound by 2 of 3 parsers); `check-closing-target-claim` exit 0, with one
UNDETERMINED warning: the card's newest `Claim:` comment (the round-2
amendment) carries no `Branch:` line.
- Round 1 and round 2 gate readings (123 and 55 families, each
reconciled with `--ran`, 0 unrun) stand for their paths; round 3 derived
its own list over the seven round-3 paths.
- Overlap: #33675 merged into `main` (35c9a30) after this branch's
base. A driver-free bare-clone `merge-tree` of this head against
`origin/main` (23a18fd) exits 0 with a tree id: no conflict, so no
merge of `main` was made.
- CI, round-3 heads (check-runs, latest per name): d1d44a3 58 success,
10 skipped, 0 failed, after the two reds on 470a621 were fixed (`Type
Check · source gates` at `check:docs`: the reference page was not
regenerated; `Test Core (2/8)`: the `multiselect` fixture's option value
`a` was itself refused as a system identifier, so the chain-field
refusal arrived second). On 55812f7 at report time: `Lint & Repo
Gates`, `Type Check · source gates`, `Check Changeset`, `Governed
Surface Queue Guard`, `Dogfood Regression Gate` and `Live E2E UI`
success; `Test Core`, `Build Core`, `Type Check · workspace`, `Type
Check UI`, `Test UI` and `Build & E2E UI` in progress; 0 failed.
- `Tier H`: the diff touches `docs/adr/**`. Landing is the maintainer's.
Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
Round 2 and 3 session:
https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5nNrLRm8ssuwWcBVcw -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent eb0d480 commit 9e6fee1
12 files changed
Lines changed: 1069 additions & 22 deletions
File tree
- .changeset
- content/docs
- data-modeling
- references/data
- docs/adr
- packages
- cli/src/commands/audit
- plugins/plugin-audit/src/audit-seal
- spec/src/data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
239 | 264 | | |
240 | 265 | | |
241 | 266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| |||
366 | 367 | | |
367 | 368 | | |
368 | 369 | | |
369 | | - | |
| 370 | + | |
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
| |||
0 commit comments