NEC-270: P3 · Make the plugin the only writer of a bound canvas file #343

Merged
nectenda-agent merged 9 commits from worktree-nec-270-make-the-plugin-the-only-writer-of-a-bou into main 2026-11-08 11:21:23 +00:00
Collaborator

Task: NEC-270 — https://projectron.nerchure.com/tasks/281

While a canvas view is bound live, the plugin is now the only writer of its file: the view's requestSave is replaced on the instance (Obsidian's 2 s save holds save bound at construction, so that is the one way at it) and save is wrapped, each capturing what the view shows and writing nothing; StructuredSync writes the file from the document under compare-and-swap, for every local transaction under the bound view as it always did for remote ones, and a bound canvas view is kept out of the text-view guard's list. Any change to the file while bound is therefore someone else's by construction and is read in against the file it replaced — the view-history classification (holds, baseFor, the view-save ledger origin, reloaded()) that brought a deleted card back and deleted a new one in canvas hardness seed 1103 is gone. Excalidraw's view keeps writing its own file (BoundView.writesFile); the lifecycle's live row allows write-begin unless a writer is bound. Verified against Obsidian 1.13.7, 1.14.4 and 1.15.0's own TextFileView code (the contract test pins the own-property, bound-save and reload-order facts, with Advanced Canvas installed) and against the 19 community canvas plugins that touch a live canvas. The runs found and fixed three things before this opened: a drag in progress carried to the peer by a capture Obsidian's reload offer provoked; a plugin's setViewData(_, false) refused as a reload; and a live card's typing lost from the typist's own file (hardness seed 981946044, round 8). Gate green on e57680fb; canvas hardness seeds 1360304150 (1.15.0/1.15.0) and 53028451 (1.15.0/1.13.7) each passed an hour, nothing lost. Review findings 4–6 are recorded as residuals in sync-limitations.md. The Markdown side is NEC-379 in Backlog. Installed in the local vaults for a manual pass before opening.

Spec: docs/changes/NEC-270-plugin-only-writer-bound-canvas/spec.md

Changelog

Canvas: while a board is open and syncing live, Nectenda now writes its file itself, so a link update or an outside edit can no longer bring back a deleted card or drop a new one.

Task: NEC-270 — https://projectron.nerchure.com/tasks/281 While a canvas view is bound live, the plugin is now the only writer of its file: the view's `requestSave` is replaced on the instance (Obsidian's 2 s save holds `save` bound at construction, so that is the one way at it) and `save` is wrapped, each capturing what the view shows and writing nothing; StructuredSync writes the file from the document under compare-and-swap, for every local transaction under the bound view as it always did for remote ones, and a bound canvas view is kept out of the text-view guard's list. Any change to the file while bound is therefore someone else's by construction and is read in against the file it replaced — the view-history classification (`holds`, `baseFor`, the `view-save` ledger origin, `reloaded()`) that brought a deleted card back and deleted a new one in canvas hardness seed 1103 is gone. Excalidraw's view keeps writing its own file (`BoundView.writesFile`); the lifecycle's `live` row allows `write-begin` unless a writer is bound. Verified against Obsidian 1.13.7, 1.14.4 and 1.15.0's own TextFileView code (the contract test pins the own-property, bound-save and reload-order facts, with Advanced Canvas installed) and against the 19 community canvas plugins that touch a live canvas. The runs found and fixed three things before this opened: a drag in progress carried to the peer by a capture Obsidian's reload offer provoked; a plugin's `setViewData(_, false)` refused as a reload; and a live card's typing lost from the typist's own file (hardness seed 981946044, round 8). Gate green on e57680fb; canvas hardness seeds 1360304150 (1.15.0/1.15.0) and 53028451 (1.15.0/1.13.7) each passed an hour, nothing lost. Review findings 4–6 are recorded as residuals in sync-limitations.md. The Markdown side is NEC-379 in Backlog. Installed in the local vaults for a manual pass before opening. Spec: `docs/changes/NEC-270-plugin-only-writer-bound-canvas/spec.md` ## Changelog Canvas: while a board is open and syncing live, Nectenda now writes its file itself, so a link update or an outside edit can no longer bring back a deleted card or drop a new one.
`requestSave` is an own property set in the constructor over a `save` bound
there, so a `save` wrapped on the instance is not what the 2 s save calls;
`onUnloadFile`, 1.15's `saveImmediately` and the quit loop do reach it. The
fake now has both shapes Obsidian ships — 1.13.7's writable `saving` and
`saveAgain`, 1.15.0's `saving` getter, `savePromise` and `writeData` — and
`loadFileInternal`'s rules for a reload. canvas-fake.test.ts pins each, and
the first of them fails against a debounce that looks `save` up (checked).
`CanvasViewInternal` names `requestSave`, with the offsets.

Also the card's spec, approved against 7572bc31.

Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
While a canvas view is bound live, the view's `requestSave` is replaced on
the instance — Obsidian's 2 s save holds `save` bound at construction, so
that is the one way at it — and `save` is wrapped; each captures what the
view shows and writes nothing, and StructuredSync writes the file from the
document under compare-and-swap as it does for an unbound file. Any change
to the file while bound is then someone else's by construction, read in by
the ordinary path against the file's last recorded text; the classification
against what the view held (`holds`, `baseFor`, `reportsSaves`, the
`view-save` ledger origin, `reloaded()`) goes, with the two canvas hardness
faults it caused (seed 1103, rounds 111 and 128).

- A capture asks for the write (`requestWrite`): a local transaction
  schedules none by itself. `save()` without `clear` awaits `writeNow`, so
  Obsidian's quit handler waits for the file.
- `BoundView.writesFile` says who writes: a drawing's view (Excalidraw saves
  its own file) keeps writing, and nothing is written under it; the
  lifecycle's `live` row allows `write-begin` unless a writer is bound.
- The bound view is kept out of the text-view guard's list (main.ts): asked
  to save, it would wait on the write asking it; `askingViews` turns that
  deadlock into a log line if a surface asks anyway. An unbound pane beside
  it keeps the disk path's care.
- Detach hands an owed save back to Obsidian, so sync stop and plugin unload
  still leave the view to save itself; the replacement passes through once
  unbound, even wrapped over by another plugin.
- The fake models both TextFileView shapes; the e2e contract test pins the
  own-property, bound-save and reload facts with Advanced Canvas installed,
  and canvas-live e2e drives the file following the document and a delete
  racing Obsidian's link rewrite.

Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
SAFE-A19's bound-writer sentences, SAFE-A20's reload bullet and SAFE-A45's
write phases now describe the plugin as the writer; the component doc's
lifecycle table, live-canvas section and the Obsidian-behaviour ledger gain
the TextFileView save-path facts the contract test checks; and
sync-limitations.md records what remains — the save Obsidian armed before
the bind, quit within the debounce, stop and unload, the cadence, and the
stale writer outside the view, which stays open.

Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
With the plugin writing the file under a bound view, each write makes
Obsidian offer a reload, and on a dirty view `loadFileInternal` first asks
`getViewData`, which captures. Mid-drag that carried the dragged card's live
position to the peer before the drop: the peer's own card moved, and the
e2e that expects a ghost found none (first run on 1.15.0). The nodes a
gesture moves keep their held position and size in a capture until it ends,
as Obsidian's own save held them back in `canvas.data`; the drop carries
them. Tested before and after the fix.

The contract test's undo count allows Advanced Canvas's node `setData`
patch, which asks the view to save again through the same property, and its
`openIn` opens a split when detaching the last leaf leaves no tab group.
Both files pass on 1.13.7, the gate's Obsidian.

Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
The gate's canvas suite edits an open board through `view.setViewData(json,
false)`, as a plugin may; refused with every reload, that edit never reached
the view. Obsidian's `loadFileInternal` sets `lastSavedData` to the text
before calling `setViewData` (the contract test pins it on 1.13.7 and
1.15.0), so a text that is not the last saved data is an edit of the view:
loaded, and captured into the document. A view with no `lastSavedData` is
refused as before, the lesser mistake. Mutation-checked both ways.

Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
The first canvas hardness run (seed 981946044, round 8) typed into a card
bound live: the typing reached the document through the card's editor
binding — a local transaction no capture sees, since a live card's text is
taken from `held` — and the peer's file followed it as a remote change, but
the typist's own file never did, and the boards disagreed. The binding's
`requestWrite` after a capture goes; `onTransaction` schedules the write for
a local transaction while a view that does not write the file is bound, as
it always has for a remote one. Tested, and the inversion fails the test.

Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
From the review: the test of a save Obsidian armed before the bind found the
file already holding what the view showed and wrote nothing, so the branch
its name claims — the save read in against the file it replaced — was never
exercised; an edit timed just before the debounce makes it write, and the
test now asserts that write and its harmless read-in. The contract test
pins `lastSavedData` being set before `setViewData(_, false)` on a dirty
view too, the only kind the live binding's writes ever reload onto. Three
residuals go into sync-limitations.md: a stale `setViewData` from another
plugin, a long local burst keeping the file behind, and a stop inside the
half-second after the 2 s capture.

Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
Record the canvas hardness seeds NEC-270 was run against
All checks were successful
Release note / release-note (pull_request) Successful in 18s
CI / build (pull_request) Successful in 3m51s
CI / e2e (pull_request) Successful in 16m6s
CI / promote (pull_request) Has been skipped
CI / build (push) Successful in 4m6s
CI / e2e (push) Successful in 16m3s
CI / promote (push) Successful in 31s
0d5df67760
Task: NEC-270
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EV8ztbgDgCvUva9vwk7DZq
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Nectenda/nectenda!343
No description provided.