Let a write wait for a file change being read in, so one race keeps one copy #330

Merged
cruelacid merged 1 commit from worktree-nec-365-one-copy into main 2026-10-30 14:30:23 +00:00
Owner

Stacked on #329 (its first four commits are that PR's). The commit to review is the last one.

Found by the Markdown hardness run, seed 2043722577, round 341. One raced save kept two backup copies instead of one. A debounced disk write read the file while a modify event for the same file was still being read in, saw content it didn't expect, and kept a copy of it. The read-in then kept its own copy of the same content.

ContentSync now tracks the read-ins in flight per document. A write that meets one waits for it to settle, then reschedules, so one race keeps one copy. Nothing is discarded: the write still runs, against the content the read-in left.

  • content-sync-record.test.ts adds "keeps one copy of a raced save, not a second from the write that met it while it was read in (NEC-365)". With the wait disabled it fails with 2 copies.
  • docs/sync-limitations.md: a paragraph added to the NEC-280 entry.
  • Local gate and build-mirror --check are green. The fresh Markdown hour, seed 350133408, ran on this branch: 354 rounds settled, passed. Its container build was grepped for the fix.

The changelog is NONE because the raced keep that made the second copy has never been in a released version.

Task: NEC-365

Changelog

NONE

🤖 Generated with Claude Code

https://claude.ai/code/session_01P5JXvAgQ27c4dMFDB2Wu5B

Stacked on #329 (its first four commits are that PR's). The commit to review is the last one. Found by the Markdown hardness run, seed 2043722577, round 341. One raced save kept **two** backup copies instead of one. A debounced disk write read the file while a modify event for the same file was still being read in, saw content it didn't expect, and kept a copy of it. The read-in then kept its own copy of the same content. `ContentSync` now tracks the read-ins in flight per document. A write that meets one waits for it to settle, then reschedules, so one race keeps one copy. Nothing is discarded: the write still runs, against the content the read-in left. - `content-sync-record.test.ts` adds "keeps one copy of a raced save, not a second from the write that met it while it was read in (NEC-365)". With the wait disabled it fails with 2 copies. - `docs/sync-limitations.md`: a paragraph added to the NEC-280 entry. - Local gate and `build-mirror --check` are green. The fresh Markdown hour, seed 350133408, ran on this branch: 354 rounds settled, passed. Its container build was grepped for the fix. The changelog is NONE because the raced keep that made the second copy has never been in a released version. Task: NEC-365 ## Changelog NONE 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01P5JXvAgQ27c4dMFDB2Wu5B
The run's seed 1339151073 failed at round 245: B edited a card in the board
view, stopped sync, and added a card through the file 0.7 s later; Kanban
then saved the board it held, without the card, which was in no file and no
copy. A probe of the same steps with this plugin disabled loses the card
every time it lands 0 to 1500 ms after the edit, and keeps one at 3000 ms:
Kanban 2.0.51 alone does it (NEC-364).

With sync running, the guard reads such a save in against what the board
had loaded (SAFE-A50), and the run keeps testing that. With sync stopped
nothing of ours runs, so a failure there measured Kanban. Offline, a board
write now waits until 4 s after that vault's last card edit in the view,
and the trace says so. No check is loosened.

The probe stays in probes.test.ts as kanban-stale-save, with the Kanban
version a variable, to rerun when Kanban updates. sync-limitations.md
records the case as Kanban's own and still open.

Task: NEC-364
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5JXvAgQ27c4dMFDB2Wu5B
The Markdown hardness run's fresh seed 1392100320 failed at round 141: a
note's properties block read as none, every value still in it, in both
vaults. Its delete takes the line break before a token that starts a line,
as a person's selection would; for a token starting the first line below
the properties, that break ends the closing `---`, and taking it glued the
line onto the delimiter. The run broke its own block, and sync kept what it
was given.

Confirmed on the same trajectory before changing anything: a replay that
deleted exactly as before, only saying when it took that break, failed the
same round, and said so for A's delete in it. Now the delete keeps that one
line break, and the trace says when it did. A replay with it passes round
141.

Task: NEC-364
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5JXvAgQ27c4dMFDB2Wu5B
Stopping sync saves the bound editor as it lets go (NEC-284), and a
write landing just before that save is lost to it, as to any of
Obsidian's (probe outside-write-at-save), with nothing of ours watching
(seed 675638079, round 222). Recorded as open in sync-limitations; the
run now waits out that save before an offline disk write, as it already
did after typing. Online it still writes at once.

Task: NEC-366

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5JXvAgQ27c4dMFDB2Wu5B
Accept a deleted word kept back by a merge the Markdown hardness run caused
Some checks failed
Release note / release-note (pull_request) Successful in 23s
CI / build (pull_request) Successful in 7m10s
CI / e2e (pull_request) Successful in 15m14s
CI / promote (pull_request) Has been skipped
CI / promote (push) Has been cancelled
CI / build (push) Has been cancelled
CI / e2e (push) Has been cancelled
44d36b96b9
A stop cancels a remote change's pending write, so an edit made before
sync runs again is made on text without it, and the merge at the next
connect keeps both versions of the lines both changed, after keeping
the file (seed 301012961, round 59, confirmed by an instrumented
replay). The checker accepts a deleted word back in a note only in the
round its vault kept that note before a merge, with the copy there.
Recorded as open in sync-limitations; flushing the write on stop is
NEC-367.

Task: NEC-367

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5JXvAgQ27c4dMFDB2Wu5B
Let a write wait for a file change being read in, so one race keeps one copy
All checks were successful
Release note / release-note (pull_request) Successful in 21s
CI / build (pull_request) Successful in 7m9s
CI / e2e (pull_request) Successful in 15m9s
CI / promote (pull_request) Has been skipped
CI / build (push) Successful in 6m6s
CI / e2e (push) Successful in 14m32s
CI / promote (push) Successful in 31s
769ba8eaac
A board view's save, raced with a remote card, was kept by its modify
event's read-in as the document held it (SAFE-A39). The write of the next
card read the same save meanwhile, kept it a second time before merging,
and only then saw the ledger move and started again: two copies and two
notices for one race, nothing lost (Markdown hardness run, seed
2043722577, round 341). A write that meets a read of the same note under
way now waits for it and starts again.

Task: NEC-365

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5JXvAgQ27c4dMFDB2Wu5B
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!330
No description provided.