Context
While porting test/playwright/unit/ai/client/DockService.spec.mjs back to the Engine under #17968 (PR #18002), a restored arm exercised the dock-model shape gate with a malformed zone descriptor. @neo-gpt reproduced the disagreement independently during review of that PR and required it be filed rather than fixed in the restoration — #17968's own AC says defects found while porting become their own ticket. This is that ticket.
Live latest-open sweep: checked the latest 20 open issues at 2026-09-01T03:2xZ, plus a targeted search over TopologyDiff, computeShapeFingerprint and fail-closed across open and closed. No equivalent exists. Nearest neighbours are #17836 (rebuilding DockLayouts, a different layer) and #18000 (a failure reporting shape, not a gate).
The Problem
TopologyDiff.diffDockDocuments() documents a fail-closed contract at src/dashboard/dock/model/TopologyDiff.mjs:93:
a malformed or cyclic document yields {…empty categories, errors: […]} — no partial categories, no throw
For one malformed shape it yields empty categories with errors: [] instead. Reproduced by execution at dev:
validate() -> ["edge-zone \"edge\" zone \"center\" descriptor must be a JSON object",
"tabs \"tabs\" references missing item \"[object Object]\""]
fingerprint -> "e{}", errors: []
diffDock... -> errors: [], every category emptyThe input is an edge-zone whose zones.center is the bare string 'tabs' rather than a {nodeId} record. Document.validate() rejects it with two errors. The shape gate accepts it.
The failure is worse than a missing error, because the output is indistinguishable from success. {…all categories empty, errors: []} is exactly what a legitimate "these two documents are topologically identical" comparison returns. A consumer asserting "no unexpected topology change" therefore gets a pass on a document the persistence layer would refuse — the malformed half is not reported, it is erased.
The Architectural Reality
The divergence is mechanical, not incidental. In Document.computeShapeFingerprint(), the edge-zone branch resolves each zone through getZoneNodeId():
let nodeId = Document.getZoneNodeId(node.zones?.[zone]);
return nodeId ? `${zone}:${walk(nodeId)}` : ''getZoneNodeId() is strict — it returns null for anything that is not a JSON record carrying a non-empty string nodeId. That null then takes the : '' arm and is dropped by the following .filter(Boolean). No error is pushed. A malformed descriptor and a genuinely absent zone are the same value by the time the fingerprint is assembled, so the walk cannot tell "this zone is not there" from "this zone is corrupt".
Every other arm of that walk fails closed and pushes an error: a missing node, a cycle, an unsupported node type. The zone-descriptor arm is the single opening, and it sits directly under the two callers that exist to be trusted — the persistence guardrail for windowFingerprint, and diffDockDocuments, whose gate loop only ever reads gate.errors.
Note the blast radius is bounded by provenance: documents that reach the gate through createSavedLayout / restoreSavedLayout have already passed validate. The exposure is the paths that fingerprint or diff a document which did not come through validate — a hand-authored fixture, a foreign or older-schema payload, a Neural Link caller passing a constructed document.
The Fix
Close the one open arm: when a zone key is present but its descriptor does not resolve to a node id, push an error rather than emitting ''. An absent zone key must stay silent — that is the legitimate case and it is common.
The distinction is between node.zones not having the key and having it bound to something unusable. Roughly:
if (!(zone in (node.zones || {}))) return '';
let nodeId = Document.getZoneNodeId(node.zones[zone]);
if (!nodeId) {
errors.push(`fingerprint walk found an unusable descriptor for zone "${zone}"`);
return ''
}Whether the message should name the offending zone only, or align word-for-word with validate's wording so the two gates read as one contract, is the open design question — see Out of Scope on unifying them.
Acceptance Criteria
Out of Scope
- Changing
Document.validate(). It already behaves correctly here; the gate is what disagrees with it.
- Unifying
validate and computeShapeFingerprint into one traversal. Tempting, and probably right eventually, but it is a contract-level refactor with its own blast radius across persistence and the render boundary. This ticket closes the polarity gap only.
- The
"[object Object]" in validate's second error. That message stringifies an item record into a diagnostic and reads badly, but it is a message-quality defect in a different function and does not affect the polarity. Worth its own ticket; not folded here.
- Auditing every
computeShapeFingerprint caller for unvalidated documents. The fix makes the gate honest, which is the prerequisite; a caller-provenance census is separate work.
Avoided Traps
- Fixing this inside PR #18002. That PR restores tests and is explicitly forbidden from changing subject behavior; folding a runtime fix into it would hide a contract change inside a 3.5k-line test diff.
- Making the gate reject any zone it cannot resolve, including absent ones.
.filter(Boolean) exists because omitted edge zones are the normal case. A fix that errors on absence would red a large share of existing fixtures and would be reverted rather than corrected.
- Asserting only that
errors is non-empty. The valuable assertion is the agreement between the two gates; an arm that only checks "the gate complained" drifts out of sync with validate again the next time either side changes.
- Treating the empty-category output as merely a missing diagnostic. It is a false green: the fail-open result is byte-identical to a real no-change result, which is why no existing consumer noticed.
Decision Record impact
none — restores the documented fail-closed behavior of an existing contract; no ADR authority is touched and no public signature changes.
Related
- Surfaced by: #17968 / PR #18002, under that ticket's "defects found while porting are filed as their own tickets" criterion.
- Required by: RA-3 of @neo-gpt's review on PR #18002.
- Sibling, one level up: #18006 — the same fail-open survives at the
zones container (node.zones is read as || {} with no record check), so a non-record container still fingerprints clean as e{}. That input class is outside this ticket's descriptor scope and is not closed by this fix; #18006 also records the worse downstream shape (a fabricated all-removes diff rather than an empty one).
- Subject:
src/dashboard/dock/model/Document.mjs, src/dashboard/dock/model/TopologyDiff.mjs.
Origin Session ID: c5d6f187-307b-49b6-af0d-9c4503c71a19
Retrieval Hint: "dock shape gate fails open on a malformed zone descriptor" · computeShapeFingerprint returns e{} with errors: [] while validate rejects
Context
While porting
test/playwright/unit/ai/client/DockService.spec.mjsback to the Engine under #17968 (PR #18002), a restored arm exercised the dock-model shape gate with a malformed zone descriptor. @neo-gpt reproduced the disagreement independently during review of that PR and required it be filed rather than fixed in the restoration — #17968's own AC says defects found while porting become their own ticket. This is that ticket.Live latest-open sweep: checked the latest 20 open issues at 2026-09-01T03:2xZ, plus a targeted search over
TopologyDiff,computeShapeFingerprintandfail-closedacross open and closed. No equivalent exists. Nearest neighbours are #17836 (rebuilding DockLayouts, a different layer) and #18000 (a failure reporting shape, not a gate).The Problem
TopologyDiff.diffDockDocuments()documents a fail-closed contract atsrc/dashboard/dock/model/TopologyDiff.mjs:93:For one malformed shape it yields empty categories with
errors: []instead. Reproduced by execution atdev:validate() -> ["edge-zone \"edge\" zone \"center\" descriptor must be a JSON object", "tabs \"tabs\" references missing item \"[object Object]\""] fingerprint -> "e{}", errors: [] diffDock... -> errors: [], every category emptyThe input is an
edge-zonewhosezones.centeris the bare string'tabs'rather than a{nodeId}record.Document.validate()rejects it with two errors. The shape gate accepts it.The failure is worse than a missing error, because the output is indistinguishable from success.
{…all categories empty, errors: []}is exactly what a legitimate "these two documents are topologically identical" comparison returns. A consumer asserting "no unexpected topology change" therefore gets a pass on a document the persistence layer would refuse — the malformed half is not reported, it is erased.The Architectural Reality
The divergence is mechanical, not incidental. In
Document.computeShapeFingerprint(), theedge-zonebranch resolves each zone throughgetZoneNodeId():let nodeId = Document.getZoneNodeId(node.zones?.[zone]); return nodeId ? `${zone}:${walk(nodeId)}` : ''getZoneNodeId()is strict — it returnsnullfor anything that is not a JSON record carrying a non-empty stringnodeId. Thatnullthen takes the: ''arm and is dropped by the following.filter(Boolean). No error is pushed. A malformed descriptor and a genuinely absent zone are the same value by the time the fingerprint is assembled, so the walk cannot tell "this zone is not there" from "this zone is corrupt".Every other arm of that walk fails closed and pushes an error: a missing node, a cycle, an unsupported node type. The zone-descriptor arm is the single opening, and it sits directly under the two callers that exist to be trusted — the persistence guardrail for
windowFingerprint, anddiffDockDocuments, whose gate loop only ever readsgate.errors.Note the blast radius is bounded by provenance: documents that reach the gate through
createSavedLayout/restoreSavedLayouthave already passedvalidate. The exposure is the paths that fingerprint or diff a document which did not come throughvalidate— a hand-authored fixture, a foreign or older-schema payload, a Neural Link caller passing a constructed document.The Fix
Close the one open arm: when a zone key is present but its descriptor does not resolve to a node id, push an error rather than emitting
''. An absent zone key must stay silent — that is the legitimate case and it is common.The distinction is between
node.zonesnot having the key and having it bound to something unusable. Roughly:if (!(zone in (node.zones || {}))) return ''; // legitimately absent let nodeId = Document.getZoneNodeId(node.zones[zone]); if (!nodeId) { errors.push(`fingerprint walk found an unusable descriptor for zone "${zone}"`); return '' }Whether the message should name the offending zone only, or align word-for-word with
validate's wording so the two gates read as one contract, is the open design question — see Out of Scope on unifying them.Acceptance Criteria
Document.computeShapeFingerprint()returns a non-emptyerrorsarray for anedge-zonewhose present zone key holds a non-record descriptor, a record withoutnodeId, or an empty-stringnodeId.edge-zonethat simply omits a zone key still fingerprints clean, witherrors: []— the absent case must not regress into a false positive.TopologyDiff.diffDockDocuments()surfaces that error through its existing${side} document failed the shape gate:prefix for both thebeforeand theafterposition, proving the gate loop is reached from each side.Document.validate()non-empty ⟺computeShapeFingerprint().errorsnon-empty. This is the arm that would have caught the defect.npm run test-unitstay green — in particular no fixture that currently fingerprints clean starts erroring, which would mean the absent-vs-malformed line was drawn in the wrong place.Out of Scope
Document.validate(). It already behaves correctly here; the gate is what disagrees with it.validateandcomputeShapeFingerprintinto one traversal. Tempting, and probably right eventually, but it is a contract-level refactor with its own blast radius across persistence and the render boundary. This ticket closes the polarity gap only."[object Object]"invalidate's second error. That message stringifies an item record into a diagnostic and reads badly, but it is a message-quality defect in a different function and does not affect the polarity. Worth its own ticket; not folded here.computeShapeFingerprintcaller for unvalidated documents. The fix makes the gate honest, which is the prerequisite; a caller-provenance census is separate work.Avoided Traps
.filter(Boolean)exists because omitted edge zones are the normal case. A fix that errors on absence would red a large share of existing fixtures and would be reverted rather than corrected.errorsis non-empty. The valuable assertion is the agreement between the two gates; an arm that only checks "the gate complained" drifts out of sync withvalidateagain the next time either side changes.Decision Record impact
none— restores the documented fail-closed behavior of an existing contract; no ADR authority is touched and no public signature changes.Related
zonescontainer (node.zonesis read as|| {}with no record check), so a non-record container still fingerprints clean ase{}. That input class is outside this ticket's descriptor scope and is not closed by this fix; #18006 also records the worse downstream shape (a fabricated all-removes diff rather than an empty one).src/dashboard/dock/model/Document.mjs,src/dashboard/dock/model/TopologyDiff.mjs.Origin Session ID: c5d6f187-307b-49b6-af0d-9c4503c71a19
Retrieval Hint: "dock shape gate fails open on a malformed zone descriptor" ·
computeShapeFingerprintreturnse{}witherrors: []whilevalidaterejects