Skip to content

Keep machine records across a protocol bump that leaves their shape alone - #3244

Merged
max-sixty merged 2 commits into
mainfrom
record-since
Oct 20, 2026
Merged

max-sixty merged 2 commits into
mainfrom
record-since

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

state.Record stamped every record leaf-<kind>/<protocol> and read any other format as absent, so each protocol bump discarded every record on the machine at once. With the protocol going 10 → 13 in one day, that cost a live session its claim (its Stop hook stopped watching and the user's page input went undelivered), reset a delivery cursor so the same input was redelivered four times, read service.json as absent so the page server came back on a new port and so a new browser origin, stranding drafts held by the old URL, and dropped user-view preferences.

Each Record now declares since, the protocol at which its own shape last changed, and its format names that number: Record(kind, schema, since=13). A bump for anything else leaves the record readable; a change to the record's shape moves since to the current protocol, bumping the protocol first where since already names it (layer-registry.md, "Page protocol"). The page protocol stays Leaf's only version. Every record starts at 13, the current protocol, so records written today stay readable.

access.json becomes the server.ACCESS record. It had been left out of Record because a protocol-stamped format would have rotated the machine's key, signing every tab out, at each bump; with since it rotates only when its own shape changes. host_key now mints under access.lock through ACCESS.write, replacing its stage-and-link, so two first serves agree on one key even when both find a file at another format. Today's unformatted access.json reads as absent, so the key rotates once when this lands.

A check that a Record's schema can't change without its since moving comes in a follow-up, with the protocol schema baseline it shares.

The composer's draft in browser storage still carries the current protocol (runtime/protocol.js), so a bump still drops a draft's drawing.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 2 commits October 19, 2026 22:26
…lone

`state.Record` stamped every record `leaf-<kind>/<protocol>` and read any
other format as absent, so each protocol bump discarded every record on
the machine at once. With 10 -> 13 in one day that cost a live session
its claim (its Stop hook stopped watching and the user's input went
undelivered), reset a delivery cursor so the same input arrived four
times, read `service.json` as absent so the page server came back on a
new port and a new browser origin, stranding drafts held by the old URL,
and dropped user-view preferences.

Each Record now declares `since`, the protocol at which its own shape
last changed, and its format names that number: `Record(kind, schema,
since=13)`. A bump for anything else leaves the record readable; a
change to the record's shape moves `since` to the current protocol,
bumping the protocol first where `since` already names it. The page
protocol stays Leaf's only version. Every record starts at 13, the
current protocol, so records written today stay readable.

`access.json` becomes the `server.ACCESS` record. It was left out of
`Record` because a protocol-stamped format would have rotated the
machine's key, signing every tab out, at each bump; with `since` it
rotates only when its own shape changes. `host_key` now mints under
`access.lock` and writes through `ACCESS`, replacing its hand-rolled
stage-and-link, so two first serves still agree on one key, including
when both find a file at another format. The existing unformatted
`access.json` reads as absent, so the key rotates once when this lands.
The test of the staged secret's cleanup goes with the staging;
`replace_bytes` owns that cleanup.

The composer's draft in browser storage still carries the current
protocol (`runtime/protocol.js`), so a bump drops a draft's drawing as
before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 33f74d3 into main Oct 20, 2026
3 checks passed
@max-sixty
max-sixty deleted the record-since branch October 20, 2026 05:44
max-sixty added a commit that referenced this pull request Oct 20, 2026
#3263)

The protocol check compared TypeScript generated from the schemas with a
snapshot of that TypeScript (`protocol-contract.d.ts`). TypeScript drops
`pattern`, length and value bounds, `uniqueItems` and conditional
clauses, so tightening one of those in `$events`, the served state or
`schema.VERB_SCHEMA` passed the check while a page vendored at the same
protocol started failing. Records kept outside a page (#3244) had no
check: nothing stopped a `state.Record` schema changing while its
`since` stayed put.

## What changes

The baseline is now the schemas themselves,
`build/browser/protocol-baseline.json`: `$events`, the served state, the
x-state verb and every `state.Record` with its `since`, as they last
stood. `build/browser/protocol.mjs` walks it beside the current schemas
and names each place where the side that must accept the other's values
no longer would:

- what a vendored page sends or holds (browser commands, log events):
the current schema takes everything the baseline did;
- what Leaf serves the page (served state, view answer): the baseline
takes everything the current schema allows, so an event record the page
is also served holds both ways;
- a record: both, while its `since` is unchanged; a `since` may move
only to the current protocol, and never past it.

A field the old schema declares, at any depth and in any branch, and the
new one lacks breaks either way. Tightening is a narrower type, enum or
const, a changed pattern or format, a raised minimum or lowered maximum,
a newly required field or `dependentRequired` entry, `uniqueItems`, a
field newly named on a map that the map's schema wouldn't take, or, at
the browser door (the only consumer that validates), a closed object
that stops naming a field, a newly closed object, or any change to a
`oneOf`. The walk throws on any keyword it doesn't read, compares
patterns and the conjunctive keywords (`allOf`, `not`,
`if`/`then`/`else`, `dependentSchemas`) only for equality, and refuses
to compare a conjunct holding a `$ref`.

The baseline is a build output: `pnpm run build:browser` refuses a
breaking change and otherwise moves it forward, and `check:browser`
names it stale until rebuilt, including after a record's schema changes
in Python. On the real tree, tightening `comment.anchor.source`'s
pattern fails with `event comment.anchor.source: pattern
"^[a-z][a-z0-9-]*$" → "^[a-z]+$"` plus each served path that carries it;
changing the claim record's `cwd` type fails with `record claim.cwd:
type ["string"] → ["integer"]`; adding an optional field to an event
record or a served object passes.

`protocol.test.ts` and `protocol-contract.d.ts` go, since the walk
covers their dropped-field and type checks; `contract.d.ts` is still
generated, from the same `protocolSchemas` reading. `state.RECORDS`
lists every declared record for the build to read. `schemaReference` is
the one parser of the served state's references, read by both the type
generator and the walk.

No maintained dependency fits: `json-schema-diff` reads neither
`pattern`, `enum` nor `const`, and `is-json-schema-subset` was last
released in 2022 on ajv 6.

## Behaviour to know

Because event records are also served, any bound or enum change on one
now needs a bump, in either direction, as type changes already did; so
does adding an event kind, since the served state carries every kind.
Changing a `oneOf` in anything the browser sends needs a bump even where
it loosens.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 20, 2026
…alone (#3282)

The composer's draft in browser storage carried `leaf-draft/<protocol>`,
and a runtime reading a draft at another format keeps its words but
drops its drawing, so every protocol bump dropped the drawing of every
unsent draft, whatever the bump changed. #3244 fixed the same problem
for `state.Record`s; this does it for the draft.

The draft now carries `$events.draft_since` (registry.json), the
protocol at which its drawing last changed shape. `runtime/protocol.js`
exports `DRAFT_FORMAT` generated from it, replacing the
`recordFormat(kind)` only the draft used.

The protocol baseline (#3263) holds it like a record: `protocolSchemas`
adds a `draft` entry whose schema is the part of a draft its format
guards, the comment record's `drawing` plus the `at` placement a draft
adds to it. Changing the drawing's shape while `draft_since` stays put
fails the build (`record draft.drawing.says: maxLength 500 → 100`);
moving `draft_since` to the current protocol clears it.

The draft's `at` schema is written in `contract-types.mjs` beside a
pointer to `captured` in `runtime/composing/drawing.js`, its writer,
since no schema declared it before.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 20, 2026
…ed at (#3345)

Since #3244 a record's `format` names the protocol at which its own
shape last changed (its `since`), so a change to a record moves that
stamp and bumps the protocol only where the stamp already names it. Root
`AGENTS.md` still said a change to a record always bumps the protocol;
this brings that line in line with `layer-registry.md`, "Page protocol",
which owns the rule. The user approved the wording on their Leaf page.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants