Skip to content

fix(whiteboards): put a content hash in the board revision - #1462

Open
croakingtoad wants to merge 3 commits into
eneskirca:mainfrom
croakingtoad:fix/whiteboard-revision-content-hash
Open

croakingtoad wants to merge 3 commits into
eneskirca:mainfrom
croakingtoad:fix/whiteboard-revision-content-hash

Conversation

@croakingtoad

Copy link
Copy Markdown

What was wrong

A whiteboard's revision (used for compare-and-set on save) was dev:ino:size:mtimeNs. A save publishes by rename, which frees the old inode; ext4 hands that inode straight to the next file, and mtime moves in coarse ticks. So two same-size saves within one mtime tick could produce identical revisions. A stale compare-and-set from another process writing the same folder (e.g. a desktop app and a Server Edition on one project) would then pass and overwrite a newer board.

The fix

The revision now ends in the sha256 of the scene bytes: dev:ino:size:mtimeNs:sha256. What is left after that (same inode, size, tick and bytes) is the very file the caller saw.

  • readRegularFileBytesNoFollow hashes from the same descriptor it reads, so the stamp is consistent with the bytes returned.
  • A revision-only call (read: false) still reads the file to hash it, but through a reused 1 MiB buffer, so a scene near the 64 MB cap is never held in memory whole.
  • The comment on the cross-process window in whiteboards.ts now says what that window is: a read-and-hash of the scene plus the temp write and rename.

Tests

Added to src/core/read-regular-file.test.ts:

  • The stamp tells apart two files with the same inode, size and mtime but different bytes (and matches again when the bytes are restored).
  • Reading the bytes or not (read: false) gives the same stamp, on a file larger than one hash chunk.

Marty added 3 commits November 20, 2026 14:54
A save publishes by rename, which frees the old inode; ext4 hands it to the
next file, and mtime moves in coarse ticks. Two same-size saves in one tick
then got the same dev:ino:size:mtime stamp, so a stale compare-and-set from
another core (desktop + Server Edition on one project) could overwrite a
newer board. The stamp now ends in the scene's sha256; a revision-only read
hashes the file in 1 MiB chunks instead of holding it.
…s-core window now is

The revision check reads and hashes the whole scene, so the window between
two cores' check and rename is no longer just a stat long.
@croakingtoad
croakingtoad marked this pull request as ready for review November 20, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant