Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/34164-seal-chain-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@objectstack/spec': minor
'@objectstack/plugin-audit': minor
---

feat(spec, plugin-audit): a sealed object names its chain column with `lifecycle.seal.chainField`

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

An audit-class object that declares `lifecycle.seal` was sealed only when it had a `tenant_id` column, because the sealer read each row's organization from that column alone. An object whose organization lives in the tenant column the platform injects, `organization_id`, was reported at `error` every hour and never sealed.

- **The key.** `lifecycle.seal.chainField` names the column whose value is the organization chain a sealed row joins, for example `seal: { valueFields: ['payload'], chainField: 'organization_id' }`. It is optional. An object that names none chains by `tenant_id`, as before.
- **Refused at authoring.** A named column the object does not have is refused at `lifecycle.seal.chainField`, with the reason. Declared fields count, and so do the columns the platform injects: `organization_id` counts unless the object opts out of the tenant column (`systemFields: false`, `systemFields.tenant: false`, `tenancy.enabled: false`).
- **Also refused there: a column that cannot name an organization.** A column whose value is not one text on every store (a number, currency, percent, rating, slider, progress, summary, boolean, toggle, date, datetime, JSON-shaped or multi-value column, the injected `updated_at` included), which would put rows into the deployment chain with no report; `id` and `created_at`, which order the sealed rows; and a column `valueFields` also lists, whose value the chain would carry in clear. Name a text or lookup column that holds the organization id.
- **Fixed once sealed.** Changing `chainField` on an object that already has checkpoints seals the last sealed hour's rows again under the new column, which `os audit verify` reports as `listed_twice`, and `--org` then reads the earlier rows as `late`. Both fail the check.
- **One reader.** The sealer, `os audit verify`'s live check and the proof bundle it writes read a row's chain value through one function. `os audit verify --org X` reports the rows of organization `X` whichever column holds it.
- **Bytes unchanged.** The checkpoint's signed `tenant_id` member keeps its name and carries the chain column's value. For an object chained by `tenant_id`, the leaf input, the signed body and the root are byte for byte what they were.
- **Still reported, not refused.** Authoring judges only a named `chainField`; the default `tenant_id` is not judged. An object that names no chain column and has no `tenant_id` still parses: the sealer reports it at `error` and does not seal it, as before. It does the same for a definition that reached the registry without the parse and names a column it lacks, and for an object chained by `organization_id` that its deployment declares platform-global, which withholds that column. Refusing the default case at authoring is a narrowing, and #34352 carries it.

ADR-0154 gains a note recording the key under D10, and how D5's "its `tenant_id` names" reads with it.
29 changes: 27 additions & 2 deletions content/docs/data-modeling/objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,33 @@ lifecycle: {
commitments instead of in clear, so a checkpoint never carries their values.
Each must be a declared field other than `id` and `created_at` (refused at
parse time otherwise). Both must be in the object's registered fields, with
`tenant_id`, which keys each checkpoint chain: an object without one of the
three is not sealed.
the chain column below: an object without one of the three is not sealed.
- `chainField` names the chain column: the column whose value is the
organization a row's checkpoint chain belongs to. It is optional and
defaults to `tenant_id`. An object whose organization lives in the tenant
column the platform injects names that column instead:
`seal: { valueFields: ['payload'], chainField: 'organization_id' }`. A
named column must be a declared field or a column the platform injects;
`organization_id` counts unless the object opts out of the tenant column
(`systemFields: false`, `systemFields.tenant: false` or
`tenancy.enabled: false`). Any other name is refused at parse time, at
`lifecycle.seal.chainField`, and so is a column that cannot name an
organization: one whose value is not one text on every store (a number,
currency, percent, rating, slider, progress, summary, boolean, toggle, date,
datetime, JSON-shaped or multi-value column, the injected `updated_at`
included), `id` or `created_at` (they order the rows), and a column
`valueFields` also lists (the chain value travels in clear in every
checkpoint). Name a text or lookup column holding the organization id. An object that names no chain column and has
no `tenant_id` field still parses, but it is not sealed: the sealer reports
it at `error`. So is an object chained by `organization_id` that its
deployment declares platform-global, which withholds that column. A row whose chain column is empty is
sealed with the rows about no organization. `os audit verify --org <id>`
reads the same column, so it reports that organization's rows whichever
column holds it. The chain column is fixed once the object has
checkpoints: after a change, the last sealed hour's rows are sealed again
under the new column, `os audit verify` reports them `listed_twice`, and
verifying one organization with `--org` reads the rows sealed before the
change as `late` and unsealed. Both fail the check.
- Every column must have a type with one canonical spelling. A column of type
`password`, `secret`, `formula`, `summary`, `image`, `file`, `avatar`,
`video` or `audio` has none, and an object that declares one is not sealed.
Expand Down
5 changes: 3 additions & 2 deletions content/docs/references/data/object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const result = ApiMethod.parse(data);
| **ttl** | `{ field: string; expireAfter: string; onlyWhen?: Record<string, string \| number \| boolean \| object \| object> }` | optional | Per-row TTL auto-expiry (transient/event classes). |
| **storage** | `{ strategy: 'rotation'; shards: integer; unit: Enum<'day' \| 'week' \| 'month'> }` | optional | Physical storage strategy for high-frequency telemetry (LifecycleService Rotator). |
| **archive** | `{ after: string; to: string; keep?: string }` | optional | Cold-store archival (LifecycleService Archiver) — audit-class hot→cold hand-off. |
| **seal** | `{ valueFields: string[] }` | optional | Seals the rows into signed, chained checkpoints (ADR-0154), so a change, insert or delete made outside the platform shows. Only `class: 'audit'` may declare it, and not beside a `retention` or `ttl` `onlyWhen`, a `ttl` on another field than `created_at`, or rotation `storage`. Until expiry amendments ship (ADR-0154 P4), the retention sweeper still deletes sealed rows, which then read as missing. A deployment with no crypto provider seals nothing and reports that at error. |
| **seal** | `{ valueFields: string[]; chainField?: string }` | optional | Seals the rows into signed, chained checkpoints (ADR-0154), so a change, insert or delete made outside the platform shows. Only `class: 'audit'` may declare it, and not beside a `retention` or `ttl` `onlyWhen`, a `ttl` on another field than `created_at`, or rotation `storage`. Until expiry amendments ship (ADR-0154 P4), the retention sweeper still deletes sealed rows, which then read as missing. A deployment with no crypto provider seals nothing and reports that at error. |
| **reclaim** | `boolean` | optional | Run driver space reclamation (SQLite incremental_vacuum) after sweeping this object. Default true for non-record classes. |

### Nested Shape: `Lifecycle.retention`
Expand Down Expand Up @@ -121,6 +121,7 @@ const result = ApiMethod.parse(data);
| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **valueFields** | `string[]` | ✅ | Columns that enter each sealed row as salted commitments instead of in clear, so a checkpoint never carries their values; every other declared column enters in clear. Each must name a declared field other than `id` and `created_at`, which order the leaves. |
| **chainField** | `string` | optional | The column whose value names the organization chain each sealed row joins (default `tenant_id`); a row whose value is empty seals into the deployment chain. It must name a declared field or a column the platform injects, such as the tenant column `organization_id`, whose value is one text on every store (not a number, boolean, date, datetime, JSON or multi-value column); not `id` or `created_at`, which order the leaves; and not a `valueFields` member. Fixed once the object has checkpoints. |


---
Expand Down Expand Up @@ -366,7 +367,7 @@ const result = ApiMethod.parse(data);
| **ttl** | `{ field: string; expireAfter: string; onlyWhen?: Record<string, string \| number \| boolean \| object \| object> }` | optional | Per-row TTL auto-expiry (transient/event classes). |
| **storage** | `{ strategy: 'rotation'; shards: integer; unit: Enum<'day' \| 'week' \| 'month'> }` | optional | Physical storage strategy for high-frequency telemetry (LifecycleService Rotator). |
| **archive** | `{ after: string; to: string; keep?: string }` | optional | Cold-store archival (LifecycleService Archiver) — audit-class hot→cold hand-off. |
| **seal** | `{ valueFields: string[] }` | optional | Seals the rows into signed, chained checkpoints (ADR-0154), so a change, insert or delete made outside the platform shows. Only `class: 'audit'` may declare it, and not beside a `retention` or `ttl` `onlyWhen`, a `ttl` on another field than `created_at`, or rotation `storage`. Until expiry amendments ship (ADR-0154 P4), the retention sweeper still deletes sealed rows, which then read as missing. A deployment with no crypto provider seals nothing and reports that at error. |
| **seal** | `{ valueFields: string[]; chainField?: string }` | optional | Seals the rows into signed, chained checkpoints (ADR-0154), so a change, insert or delete made outside the platform shows. Only `class: 'audit'` may declare it, and not beside a `retention` or `ttl` `onlyWhen`, a `ttl` on another field than `created_at`, or rotation `storage`. Until expiry amendments ship (ADR-0154 P4), the retention sweeper still deletes sealed rows, which then read as missing. A deployment with no crypto provider seals nothing and reports that at error. |
| **reclaim** | `boolean` | optional | Run driver space reclamation (SQLite incremental_vacuum) after sweeping this object. Default true for non-record classes. |

### Nested Shape: `Object.activityMilestones[number]`
Expand Down
Loading
Loading