Shapes write the whole top-level raw value
Millwork never uses the nested setAttr path.
Context
The @warp-drive/json-api cache has a nested write path: setAttr(key, ['shipTo', 'city'], v).
A schema-object field uses it when the app sets a nested field on the record. The spike
confirms two bugs in it, on 5.8.0 and on 5.9.1:
- Set two nested fields, then set one back to its remote value. The cache deletes all local changes of the top-level field. The other edit is lost.
- A nested write on a field with no remote value throws a
TypeError.
Also, a whole-object write to a polymorphic schema-object throws a TypeError. The setter
reads the ObjectSchema of field.type, and a polymorphic field has none.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
- Millwork never uses the nested
setAttrpath. A shape write makes the next top-level raw value and callssetAttr(key, field, next)once. - So a Millwork shape does not hand out the WarpDrive
schema-objectsetters. It reads through WarpDrive, and it writes through its own setter. - To clear a change, Millwork compares the next raw value with the remote raw value with the
codec
equals. When they are equal, it writes the remote reference back. The simple path compares with!==, so only the same reference clears the change. - Millwork keeps per-path change state itself (plan section 4.5). The cache gives only
top-level
[old, new]pairs. - Millwork reports the bugs upstream (draft:
upstream-nested-setattr.md). Thetest.failstests flip when upstream ships a fix. Then this ADR can change.
Consequences
- One write copies one top-level value. This costs more for a large shape, but it is correct.
- A polymorphic shape must also write through the Millwork setter, not through the
schema-objectsetter. - A Polaris record needs
checkoutbefore a write. A write on the immutable record throws.commitmoves the local state into the remote state. A legacy-mode record is editable with nocheckout.
Confirmation
Evidence
packages/warp-drive/tests/spikes/s2-nested-setattr.test.tspackages/warp-drive/tests/spikes/polaris-checkout.test.ts
Interview record
Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.
| Question | Answer | Source |
|---|---|---|
| Where does the text of this page come from? | From the Markdown file docs/adr/0005-nested-write-strategy.md at commit c8154b0. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so. | Document: docs/adr/0005-nested-write-strategy.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Status in the Markdown file: Accepted (M0, spike S2). |
| 2026-12-01 | Joe Gaudet | Commit 0a16254: Build Millwork 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0005-nested-write-strategy.md to this page. The text is the text of the Markdown file. |
The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.