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
16 changes: 16 additions & 0 deletions .changeset/37881-skills-lifecycle-signed-expiry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/skills': patch
---

docs(skills): the lifecycle rule teaches which sealed objects take signed expiry, and that a retention override cannot shorten a packaged sealed object's declared window

Clause-②: no (published prose only; teaches behaviour already on main)
Metadata-protocol: none

`skills/objectstack-data/rules/lifecycle.md` (Sealing) no longer says expiry is not built and that the sweeper deletes every sealed object's rows. It now says: signed expiry covers objects whose lifecycle is declared in packaged metadata, whose sealed rows leave only by whole checkpoints and read as `expired`; on such an object with no `archive`, a retention override below the declared window is rejected and the declared window applies, and to keep rows for less time the declared window is what to shorten; on any other sealed object (one created at runtime) the sweeper still deletes sealed rows, which then read as missing. The `retention_overrides` row of the Operations table points at that paragraph.

The same sentence said no verifier is built. `os audit verify` reads the checkpoints back, so that clause is removed.

The file sat at its token ceiling, so the words are paid for in the same file and no ceiling moves: the page drops the rationale sentence after "the file never shrinks" and its echo in the first validation example, the example list in the rule sentence (the Lifecycle Classes table carries a typical use per class), the hook names in the intro, the rationale clause of the Separation bullet, and three filler words in Safety Semantics.

Eval case 16 of `skills/objectstack-data/evals/objects-fields-relationships.json` graded the two withdrawn statements (`not reported`, and `read as missing` for an object an author declares). It now expects the page as it stands: `must_contain` carries `expired` in their place, and `expected_output` ends with the three sentences of the new paragraph.
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,15 @@
{
"id": 16,
"prompt": "Our `consent_change` audit log must show it if anyone edits, inserts or deletes rows directly in the database, but whatever proof is stored must not carry the consent text itself. How do I declare that?",
"expected_output": "Keep `lifecycle.class: 'audit'` with its bounding `retention` (or a `ttl` on `created_at`) and add `seal: { valueFields: ['consent_text'] }`: the audit plugin signs each `created_at` hour into one checkpoint per organization, chained to the one before, where `valueFields` columns enter as salted commitments and every other column in clear. The object declares its own `id` and a text or lookup `tenant_id` field; without that `tenant_id` (and with no `chainField` naming another chain column, such as the injected `organization_id`) it is refused at parse, and without `id` it parses but is not sealed, and the sealer reports it at `error` each hour. Refused at parse: `seal` on a class other than `audit`, `valueFields` naming `id`, `created_at` or an undeclared field, and beside `seal` a `retention` or `ttl` `onlyWhen`, a `ttl` on another field, or rotation `storage`. Two limits today: no verifier reads the checkpoints back yet, so a break is recorded but not reported; and until expiry ships, the sweeper still deletes sealed rows, which then read as missing. Field history is not tamper evidence.",
"expected_output": "Keep `lifecycle.class: 'audit'` with its bounding `retention` (or a `ttl` on `created_at`) and add `seal: { valueFields: ['consent_text'] }`: the audit plugin signs each `created_at` hour into one checkpoint per organization, chained to the one before, where `valueFields` columns enter as salted commitments and every other column in clear. The object declares its own `id` and a text or lookup `tenant_id` field; without that `tenant_id` (and with no `chainField` naming another chain column, such as the injected `organization_id`) it is refused at parse, and without `id` it parses but is not sealed, and the sealer reports it at `error` each hour. Refused at parse: `seal` on a class other than `audit`, `valueFields` naming `id`, `created_at` or an undeclared field, and beside `seal` a `retention` or `ttl` `onlyWhen`, a `ttl` on another field, or rotation `storage`. Signed expiry covers objects whose lifecycle is declared in packaged metadata, as this one is: its sealed rows leave only by whole checkpoints and read as `expired`. With no `archive`, a retention override below the declared window is rejected and the declared window applies; to keep rows for less time, shorten the declared window. On any other sealed object (one created at runtime) the sweeper still deletes sealed rows, which then read as missing. Field history is not tamper evidence.",
"files": [],
"assertions": {
"must_contain": [
"seal",
"valueFields",
"tenant_id",
"salted commitments",
"read as missing",
"not reported"
"expired"
],
"must_not_contain": [
"trackHistory",
Expand Down
37 changes: 19 additions & 18 deletions skills/objectstack-data/rules/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

Declaring how long an object's data lives and how its space is
reclaimed (ADR-0057). Distinct from
**lifecycle hooks** (`beforeInsert` / `afterUpdate` …), which run logic on
writes.
**lifecycle hooks**, which run logic on writes.

## Why This Exists

Every object without a `lifecycle` block is **immortal**: rows are never
deleted, and on SQLite the file never shrinks. That's correct for business
records — and a guaranteed disk leak for anything append-only.
deleted, and on SQLite the file never shrinks.

**Rule: any append-only, high-write-rate object (event log, run history,
delivery outbox, ephemeral tokens) MUST declare a `lifecycle` block.**
**Rule: any append-only, high-write-rate object MUST declare a `lifecycle`
block.**
The platform LifecycleService sweeps declared policies hourly, deletes
expired rows under a system context, and reclaims driver space.

Expand Down Expand Up @@ -96,7 +94,7 @@ Duration literals: `<n>` + `h` / `d` / `w` / `y`.
## Validation Rules (rejected at parse time)

```typescript
// ❌ Non-record class with no bounding policy — grows forever, exactly the bug
// ❌ Non-record class with no bounding policy
lifecycle: { class: 'telemetry' }

// ❌ archive.after must equal retention.maxAge
Expand All @@ -113,17 +111,15 @@ lifecycle: {

## Safety Semantics

- **Archive-then-delete is atomic-ish and safe by default**: an object
declaring `archive` is never hot-deleted before the copy to the archive
datasource succeeded. If no datasource is registered under the `archive.to`
name, rows are simply retained.
- **Rotation** physically time-shards the table on SQLite (writes hit the
- **Archive-then-delete**: an object declaring `archive` is never
hot-deleted before the copy to the archive datasource succeeded. If no
datasource is registered under the `archive.to` name, rows are retained.
- **Rotation** time-shards the table on SQLite (writes hit the
current shard, reads go through a view under the object's name, expired
shards are DROPped). Other dialects enforce the same window with an
age-based reap.
- **Separation**: registering a datasource named `telemetry` moves every
`telemetry`/`event`/`audit` object onto it — telemetry bloat can't touch
the business DB.
`telemetry`/`event`/`audit` object onto it.

## Sealing (`seal`)

Expand Down Expand Up @@ -161,16 +157,21 @@ text `tenant_id` outside `valueFields` (or `chainField: 'organization_id'`),
and beside `seal` any `onlyWhen`, a `ttl` not on `created_at`, or rotation
`storage`. Unsealed, `error` hourly: no declared `id`; a `password`,
`secret`, `formula`, `summary`, `image`, `file`, `avatar`, `video` or `audio`
column; no `cryptoProvider` on `AuditPlugin`. Not built yet (ADR-0154): a
verifier, so a break is recorded but not reported; expiry (P4), so the sweeper
still deletes sealed rows, which then read as missing.
column; no `cryptoProvider` on `AuditPlugin`.

Signed expiry covers objects whose lifecycle is declared in packaged metadata:
their sealed rows leave only by whole checkpoints and read as `expired`. On
such an object with no `archive`, a retention override below the declared
window is rejected and the declared window applies; to keep rows for less
time, shorten the declared window. On any other sealed object (one created at
runtime) the sweeper still deletes sealed rows, which then read as missing.

## Operations

| Knob | Where | Effect |
|:-----|:------|:-------|
| `enabled` | `lifecycle` settings namespace | Runtime master switch |
| `retention_overrides` | settings, **tenant-scoped** | Per-object window overrides — a regulated tenant sets `'2y'` while dev keeps days |
| `retention_overrides` | settings, **tenant-scoped** | Per-object window overrides — a regulated tenant sets `'2y'` while dev keeps days; sealed objects: see § Sealing |
| `quotas` / `quota_defaults` | settings | Row ceilings; breaches ALERT (never delete beyond declared policy) |
| `growth_alert_rows` | settings | Per-sweep growth spike alert |
| `OS_LIFECYCLE_DISABLED=1` | env | Disables sweeping entirely |
Expand Down
Loading