Spec §8.2.2: the protection is probabilistic; per-draw and cumulative odds per source
Astra round 3 (P3): code draws 63 bits, migration 0009 62 (forced odd); per-draw 2^-63 / 2^-62, cumulative at most N·M·2^-62 per document; SQLite's random() is ChaCha20, OS-seeded, with a time/pid fallback. Also records the redraw and broken-source tests and the third lease-expiry point.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+26
−10
docs/superpowers/specs/2026-08-30-docs-design.md+26 −10
diff --git a/docs/superpowers/specs/2026-08-30-docs-design.md b/docs/superpowers/specs/2026-08-30-docs-design.md| index 8fcba9a..434d165 100644 |
| --- a/docs/superpowers/specs/2026-08-30-docs-design.md |
| +++ b/docs/superpowers/specs/2026-08-30-docs-design.md |
| @@ -669,9 +669,15 @@ transaction as the change, on creation and on every applied update |
| alone misses renames, and a rename changes S3's bytes. A grant, a revoke or |
| a link changes who may read, which S2 asks live, so none of them moves it. |
| Each new value — on every change, on creation, and in migration 0009 for |
| -every document that existed before it — is **a fresh random positive int63** |
| -(Go's `crypto/rand`; SQLite's OS-seeded `random()` in the migration), never |
| -the current one. It is a token, not a count: it has no order. That is |
| +every document that existed before it — is **a fresh random positive |
| +value**, never the current one. In code it is 63 random bits from Go's |
| +`crypto/rand` (a zero, or the current value, is drawn again; a source that |
| +cannot be read is an error and the change does not commit — nothing falls |
| +back to a clock or a counter). In migration 0009 it is SQLite's `random()` |
| +masked to 63 bits and forced odd, so **62 random bits**; SQLite's PRNG is |
| +ChaCha20 (verified in modernc.org/sqlite v1.55.0), seeded from the OS |
| +(`/dev/urandom`), and falls back to the time and the process id if that |
| +cannot be opened. It is a token, not a count: it has no order. That is |
| enough because **memoria only ever matches revisions for equality** — |
| verified in memoria `origin/main` `f002955`, `internal/memoria/models.go` |
| (`SiblingRevision`: "Never compared, only matched for equality"), and its |
| @@ -752,11 +758,19 @@ taken. Three ways of breaking that were found and are closed: |
| gave its harmless, still-granted document the same revision the first |
| migration gave the confidential one. |
| -Revisions and feed nonces are random now, here and in the migration, so a |
| -repeat has probability 2^-63 with no assumption about the clock, and a |
| -pre-restore copy is `UNKNOWN` (its revision is not in the restored log), |
| -withheld loudly; a pre-restore cursor's nonce does not match its row, so |
| -S1 is a 503. Kept as defence in depth: that persistent S1 error is the |
| +Revisions and feed nonces are random now, here and in the migration, so the |
| +protection is **probabilistic, with no assumption about the clock**. Per |
| +draw: a new value equals one particular earlier value with probability |
| +2^-63 from code and 2^-62 from the migration (for nonces too). Cumulative: |
| +what matters is one document — S2 matches `(item, revision)` — so for a |
| +document whose history held N revisions before a restore and is given M |
| +new ones after it, the chance that any new one equals any old one is at |
| +most N·M·2^-62 (a million each side: about 2×10^-7). A cursor fails to be |
| +refused only if the row now at its id drew the same nonce, 2^-63 or 2^-62 |
| +per cursor. Barring that, a pre-restore copy is `UNKNOWN` (its revision is |
| +not in the restored log), withheld loudly, and a pre-restore cursor is a |
| +503. The migration's fallback seed (time and pid, when `/dev/urandom` |
| +cannot be opened) would weaken only migration-issued values, once. Kept as defence in depth: that persistent S1 error is the |
| signal, not something to retry past — **after a restore memoria must drop |
| everything it holds from Docs and its Docs cursor, and re-read from |
| `""`.** |
| @@ -793,8 +807,10 @@ current-only rule, the CSRF exemption being exactly the three routes, no |
| consumers meaning no routes, and the 401; and, from Astra's review, the |
| three restore sequences above with real SQLite backups, `STALE` read from |
| the log (a revision from the document's history is `STALE`; a value never |
| -issued, or another document's, is `UNKNOWN`), the custody fixture seeded |
| -with each item's revision − 1 in its log, a lease running out |
| +issued, or another document's, is `UNKNOWN`, asked of two documents in one |
| +batch), both redraws forced through a scripted random source and a broken |
| +one refused, the custody fixture seeded |
| +with each item's revision − 1 in its log, a lease running out (before, between and after S2's reads) |
| before and after S2's reads, a change whose feed row cannot be written not |
| committing, and a lone-shape guest answered 404 by every sharing route. |