Repository navigation
Compare protocol schemas by position, halving the protocol check - #3286
Conversation
`protocol.mjs` checked each schema change semantically: it resolved references, intersected a union's shared keywords into each branch, matched a value's branch to the closest consumer branch, guarded recursion, and walked a separate field-retention pass. Each review round of #3263 found another place where that machinery let a tightening through, and the file reached 549 lines. It now lays each baseline schema beside its current form and compares them keyword by keyword. A reference compares by its text, and its target where it is declared: served `$defs` by name, and each event record as its own root, compared both ways since the served state carries every kind. Union, `allOf` and `prefixItems` positions compare by index, a union on one side only as a union of one, and a browser contract as an overlay that narrows its record. That removes the resolver, `intersect`, `command`, the recursion guard, the closest-branch heuristic and the retention walk: 549 lines become 261. 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 reports once where it is declared, not at every served path that reaches it. Every fault the earlier walk's tests caught still fails a test, and the current tree compared with itself passes. Review of drafts found four cases this comparison first got wrong, now covered: a contract dropping a field leaves it to its record; a contract may bound at once a field new to its record; a served branch dropped takes the fields no other branch names; and a position `prefixItems` stops naming holds what `items` allows. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The dropped-branch field check only inspects immediate properties. If a served anyOf ends with a branch containing payload.x, while an earlier branch contains payload.y, removing the last branch leaves payload named elsewhere and this check reports no break. I reproduced protocolBreaks returning [] for that change, although the old page can still read payload.x from that served variant. The field-retention check needs to follow nested paths within a removed branch, including when another branch retains only their parent.
A union branch the new schema drops took with it only the fields it named at its own top level, so dropping a served variant whose `payload.x` no other branch names passed while another branch kept `payload`. The check now follows every field the dropped branch names, through nested objects, items and branches. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The dropped-branch check can still miss a removed field and report a field that remains available.
The dropped-branch check missed fields a branch names under `prefixItems`, `dependentSchemas` or a map, and reported a field gone that the union's shared schema still names. It now follows those children, and counts the shared schema among what remains. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The new prefixItems path in fields can also report a field as gone when a surviving items schema still names it. With served anyOf branches [{items: {properties: {x: {}}}}, {prefixItems: [{properties: {x: {}}}]}], removing the second branch reports served state.pick[0].x: the field is gone; the first branch still covers x at index 0. The retention check needs to compare coverage of an array position by items as well as by prefixItems before requiring a protocol bump.
…a dropped branch A field a dropped branch named at `prefixItems[0]` read as gone though a surviving branch's `items` still named it, and a field named under `if`/`then`/`else` went unread. Every array position is now one field path, `[]`, and the conditional children are read like the others. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The dropped-branch field check still misses a field removed at one array position.
… each Reading every array position as one path let a field a dropped branch named at `prefixItems[0]` pass as kept where a surviving branch named it only at `prefixItems[1]`. Positions are distinct again, and a field a surviving branch's `items` names counts at every position. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The dropped-branch check still treats items as covering a position occupied by prefixItems. In a surviving branch with prefixItems[0] as a closed empty object and items naming x, removing a branch whose prefixItems[0] names x returns []: the items field is counted at index 0 even though it applies only after the prefix. The old page can lose pick[0].x without a protocol bump. I reproduced this with protocolBreaks; the field-retention comparison needs to account for where each branch's items starts, rather than replacing every numeric index with [].
Each fix to how a dropped union branch's fields at tuple positions are kept opened another case: positions collapsed, then `items` covering a position a prefix still held. No protocol schema puts a field in a tuple position (`prefixItems` holds only the drawing's numbers), so the comparison now refuses a field inside `prefixItems`, failing loudly, and a field's path names no position. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The tuple-field refusal misses a removed served union branch. diff returns early for that branch because its new schema is false, and fields no longer visits prefixItems, so removing a branch that alone declares pick[0].x returns [] without a protocol bump. I reproduced this with two served anyOf tuple branches, one declaring x and the other y. The refusal needs to run while collecting a removed branch's fields too.
The keyword check and the refusal of fields inside `prefixItems` ran only on the nodes the comparison visited, so a union branch the new schema drops, which it doesn't descend, escaped both. `readable` now walks every compared schema once, at the edge, and the comparison itself checks nothing. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.mjsreached 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:
$defscompare by name, and each event record as its own root, both ways, since the served state carries every kind.allOfandprefixItemsentries compare by index, and a union on one side only compares as a union of one.prefixItemsis refused, so a field's path names no tuple position; no protocol schema has one.required, maps and closedness follow the same direction rules as before.pattern,format,notandif/then/elsecompare only for equality, and so doesoneOfat 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
prefixItemsstops naming holds whatitemsallows.