Skip to content

test(desktop): prove a power cut loses derived rows and derived_seq together - #189

Merged
1 commit merged into
mainfrom
claude/test-derive-crash-from-main
Nov 22, 2026
Merged

1 commit merged into
mainfrom
claude/test-derive-crash-from-main

Conversation

@HMarzban

Copy link
Copy Markdown
Contributor

The condition on the D-A6 amendment in #185 (approved 2026-11-22 by the coordinator, under the owner's delegation). Derived rows commit at synchronous=NORMAL, so a power cut may lose the last derive while the FULL content append before it survives. This proves the derived rows and derived_seq are lost together, so the document reads as stale and is derived again.

The test

tests/unit/desktop/storage/derive-crash-loss.test.ts simulates the power cut on the files.

The harness can't do it by closing the connection: closing the last connection checkpoints the WAL into the main file. So the test works on copies:

  1. Right after a FULL append, it copies the main file and the WAL. That copy is what a disk that has finished syncing holds.
  2. It runs a putDerived, then crashes the library.
  3. It restores the main file and cuts the WAL back:
    • dropped last commit: at the append's end;
    • torn tail: 124 bytes into the derive's first frame.
  4. It deletes -shm, so the WAL index is rebuilt from the WAL, and reopens. The reopen sees an unclean exit and quick_check reports ok.

In both cases:

  • the append's text survives;
  • the backlinks are gone;
  • nextStale() returns the document, so derived_seq went with its rows;
  • the next putDerived restores the rows.

Control: with the whole WAL kept, the derive survives.

Base

The base is main (2764fb5), as asked. The test passes with or without #185, because it simulates the loss itself.

One line will conflict with #185. It's the D-A6 row in docs/superpowers/specs/2026-11-15-desktop-architecture.md:

To resolve, keep #185's amendment and add this PR's "Proven by …" sentence to it.

Test plan

  • The new test: 3 pass (dropped commit, torn tail, control)
  • bun run typecheck; Biome on the new file

…ogether

The condition on D-A6's amendment: after a FULL append and a NORMAL
derive, a dropped last commit or a torn WAL tail keeps the append, loses
the derived rows with their derived_seq, and leaves the document stale
for the next derive to restore. The spec's amendment note points here.
@HMarzban
HMarzban marked this pull request as ready for review November 22, 2026 15:40
@github-merge-queue github-merge-queue Bot closed this pull request by merging all changes into main in 44d48d8 Nov 22, 2026
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