Spec §8.2.2: random revisions and nonces, STALE from the log, no clock assumption
Astra's second review of feat/suite-producer (54640b4): a pre-0009 backup restored and migrated again, and a restore onto a clock set back within the first fix's own allowance, both reissued a revision. Revisions are now fresh random positive int63s (code and migration), feed nonces too; S2's STALE is read from suite_feed; memoria's equality-only use of revisions is verified (memoria f002955, models.go SiblingRevision) and cited. The consumer reset after a restore stays, as defence in depth.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+47
−23
docs/superpowers/specs/2026-08-30-docs-design.md+47 −23
diff --git a/docs/superpowers/specs/2026-08-30-docs-design.md b/docs/superpowers/specs/2026-08-30-docs-design.md| index 72d936d..8fcba9a 100644 |
| --- a/docs/superpowers/specs/2026-08-30-docs-design.md |
| +++ b/docs/superpowers/specs/2026-08-30-docs-design.md |
| @@ -668,16 +668,22 @@ transaction as the change, on creation and on every applied update |
| (`ApplyUpdate`), rename, visibility change and deletion. `doc_updates.seq` |
| 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 is **max(previous + 1, now in unix microseconds)** — strictly |
| -increasing, still an integer under 2^53 — never simply previous + 1. Rows |
| -that existed before migration 0009 start at 1 and jump to the clock on |
| -their first change. |
| +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 |
| +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 |
| +uses in `store.go` and `agent_response.go` are `==`/`!=` with 0 as the |
| +"not a sibling" sentinel — and S2's `STALE` is read from Docs' own log |
| +(below), never from comparing two numbers. |
| **The feed log.** `suite_feed (id AUTOINCREMENT, document_id, revision, |
| gone, touched_at, stamp)` is append-only and written in the same |
| transaction as each bump, creation included; a change whose feed row cannot |
| -be written does not commit. `stamp` is the row's creation in unix |
| -nanoseconds, written once. Migration `0009` writes one row per live |
| +be written does not commit. `stamp` is a random positive nonce, written |
| +once with the row (the backfill rows too). Migration `0009` writes one row per live |
| document that existed before it, so a consumer's first poll sees the whole |
| library. *Live* is `deleted_at IS NULL AND owner_id > 0`: the orphans |
| `0002_owners.sql` made are readable by nobody and are not fed. |
| @@ -712,8 +718,12 @@ member, or a holder of a live grant) is refused like any other stranger. |
| Then, for each pair: a deleted or unknown id is `NOT_VISIBLE`; a document |
| the actor may not read through `permissionScope` is `NOT_VISIBLE`, or |
| `UNKNOWN` when team standing is `Unknown`; a readable one is `VISIBLE` at |
| -the current revision, `STALE` below it, and `UNKNOWN` above it or at a |
| -revision below 1. A Home subject with no Docs principal yet still reads the |
| +the current revision, `STALE` at a revision **this document's `suite_feed` |
| +rows hold** (one it had and has moved on from — doctrine §4.3, "compare |
| +the asked revision against your log"), and `UNKNOWN` at any other value: |
| +one never issued, another document's, or one issued before a restore that |
| +the restored log does not hold. The person is checked before the |
| +revision. A Home subject with no Docs principal yet still reads the |
| team rung by standing alone, since its first sign-in would. Nothing is |
| cached: every call reads the roster lease and the database afresh. |
| @@ -725,20 +735,31 @@ change answers `ErrNotAvailable`, so a body is never labelled with a |
| revision it does not match. S3 carries no person, so it does not consult |
| `permissionScope`. |
| -**Restore from a backup (Astra's review, 2026-11-01).** What is protected: |
| -a revision or a feed position issued before a restore is never issued again |
| -after it. Counting revisions up from the restored value reissued them for |
| -different content — a private draft backed up, renamed to confidential |
| -text and held by memoria, restored and shared with the team, answered S2 |
| -`VISIBLE` for a teammate against the confidential copy — and AUTOINCREMENT |
| -reissued feed ids, so memoria's cursor met a tip that said nothing had |
| -changed. With the clock as the revision's floor every copy memoria holds |
| -from before the restore is `STALE` or `UNKNOWN`, withheld loudly; with the |
| -stamp, memoria's cursor is a 503. That 503 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 `""`.** The protection assumes |
| -the clock does not run backwards across the restore by more than the time |
| -between the backup and the restore. |
| +**Restore from a backup (Astra's review, two rounds, 2026-11-01).** What is |
| +protected: a revision or a feed position issued before a restore is never |
| +issued again after it, whatever the clock and whenever the backup was |
| +taken. Three ways of breaking that were found and are closed: |
| + |
| +- *Counted revisions* reissued the held value: a private draft backed up, |
| + renamed to confidential text and held by memoria, restored and shared |
| + with the team, answered S2 `VISIBLE` for a teammate against the |
| + confidential copy. AUTOINCREMENT reissued feed ids too, so memoria's |
| + cursor met a tip that said nothing had changed. |
| +- *Clock-floored revisions* (this branch's first fix) reissued it when the |
| + restore landed on a clock set back to the confidential edit's time, which |
| + the first fix's own allowance permitted. |
| +- *A backup taken before migration 0009*, restored and migrated again, |
| + 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 |
| +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 |
| +`""`.** |
| **`DOCS_SUITE_CONSUMERS`.** `server.EnvSuffix`'s variable, strict JSON: |
| `[{"consumer_id":"memoria","tokens":[{"epoch":1,"sha256":"<64 hex>"}]}]`, |
| @@ -770,7 +791,10 @@ default and the migrated private rows, the rung for a member and not a |
| non-member, S1 paging, the tip, `gone` and every bump, every S2 branch, S3's |
| 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 |
| -restore sequence above with a real SQLite backup, a lease running out |
| +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 |
| 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. |