Repository navigation
Hold every protocol and record schema change to a JSON schema baseline - #3263
Merged
Merged
Conversation
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 had no check at all: nothing stopped a `state.Record` schema changing while its `since` stayed put. 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. `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 newly closed object or any change to a `oneOf`, whose exclusivity a branch-by-branch comparison can't show. A union's shared keywords, a reference's siblings and a command's record join each branch, target and browser contract as an intersection. 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. The generated types stay (`contract.d.ts`, built from the same `protocolSchemas` reading), while `protocol.test.ts` and `protocol-contract.d.ts` go: the walk covers their dropped-field and type checks. `state.RECORDS` lists every declared record so the build can read them, and refuses two records declaring one kind. `schemaReference` is now the one parser of the served state's references, which both the type generator and the walk read. 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. Neither knows Leaf's references or that a field the old schema declares must survive. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
reviewed
Oct 20, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
Two changes to accepted browser events pass the new compatibility check without a protocol bump. Both leave a page vendored at the same protocol able to send an event the current admission rejects.
Two edits to what a page sends passed the protocol check while admission would refuse an older page's event. Deleting a field from one closed `anyOf` variant while another variant keeps it left the field in the branch-agnostic retention set, and the walk ignored a producer field the consumer's object doesn't name. Closing an open object that names some fields passed too, since the walk took such an object to hold only its named fields. At the browser door, the one consumer that validates, a closed object now refuses each field the old schema named and it doesn't, and closing an object the old schema left open breaks whatever fields it named. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
reviewed
Oct 20, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The new closure check still misses a browser event value the old schema admitted, so this change needs a regression case before the protocol gate can be relied on.
A schema-valued `additionalProperties` evaluates the fields it matches, so `unevaluatedProperties: false` beside it closes nothing. The walk read such an object as closed, so changing its map to `false` at the browser door passed though admission would then refuse a field it took. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 20, 2026
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
The protocol check from #3263 compared schemas semantically: it resolved references, intersected a union's shared keywords into each branch, matched each value to the closest branch, guarded recursion, and ran a separate field-retention walk. Each review round found another hole in that machinery, and `protocol.mjs` reached 549 lines. This replaces it with a positional comparison: **549 → 314 lines**. ## How it compares Each baseline schema sits beside its current form and is compared keyword by keyword: - A reference compares by its text; its target is compared where it is declared. Served `$defs` compare by name, and each event record as its own root, both ways, since the served state carries every kind. - Union, `allOf` and `prefixItems` entries compare by index, and a union on one side only compares as a union of one. - A browser contract compares as an overlay that narrows its record. - A field inside `prefixItems` is refused, so a field's path names no tuple position; no protocol schema has one. - Bounds, types, values, `required`, maps and closedness follow the same direction rules as before. `pattern`, `format`, `not` and `if`/`then`/`else` compare only for equality, and so does `oneOf` at the browser door. ## What changes in behaviour The comparison is conservative where the walk was exact. Reordering a union's branches, or replacing a reference with its target inline, now fails. A changed definition is reported once, where it is declared, rather than at every served path that reaches it. ## Evidence - Every fault the earlier walk's tests caught still fails a test: 22 single-line mutations of the new file each fail at least one test. - The current tree compared with itself passes, as does adding an optional field to an event record, a served object or a record. - Two Codex reviews of drafts and the PR reviewer found cases the positional comparison first got wrong; each is fixed and has a test: - a contract that drops a field leaves it to its record; - a contract may bound at once a field that is new to its record; - a dropped served branch takes with it the fields no other branch names, at any depth; - a position `prefixItems` stops naming holds what `items` allows. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The protocol check compared TypeScript generated from the schemas with a snapshot of that TypeScript (
protocol-contract.d.ts). TypeScript dropspattern, length and value bounds,uniqueItemsand conditional clauses, so tightening one of those in$events, the served state orschema.VERB_SCHEMApassed the check while a page vendored at the same protocol started failing. Records kept outside a page (#3244) had no check: nothing stopped astate.Recordschema changing while itssincestayed put.What changes
The baseline is now the schemas themselves,
build/browser/protocol-baseline.json:$events, the served state, the x-state verb and everystate.Recordwith itssince, as they last stood.build/browser/protocol.mjswalks it beside the current schemas and names each place where the side that must accept the other's values no longer would:sinceis unchanged; asincemay 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
dependentRequiredentry,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 aoneOf. 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:browserrefuses a breaking change and otherwise moves it forward, andcheck:browsernames it stale until rebuilt, including after a record's schema changes in Python. On the real tree, tighteningcomment.anchor.source's pattern fails withevent comment.anchor.source: pattern "^[a-z][a-z0-9-]*$" → "^[a-z]+$"plus each served path that carries it; changing the claim record'scwdtype fails withrecord claim.cwd: type ["string"] → ["integer"]; adding an optional field to an event record or a served object passes.protocol.test.tsandprotocol-contract.d.tsgo, since the walk covers their dropped-field and type checks;contract.d.tsis still generated, from the sameprotocolSchemasreading.state.RECORDSlists every declared record for the build to read.schemaReferenceis the one parser of the served state's references, read by both the type generator and the walk.No maintained dependency fits:
json-schema-diffreads neitherpattern,enumnorconst, andis-json-schema-subsetwas 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
oneOfin anything the browser sends needs a bump even where it loosens.