Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
spaces: drop the absent-revisions normalisation; kernel #726 keeps cleared history cleared (#748)
nyblnete1d629e980d3
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.mdindex a0e81480..e4c5326d 100644--- a/docs/DECISIONS.md+++ b/docs/DECISIONS.md@@ -10671,3 +10671,29 @@ Verified in `scripts/test-spaces-restore.ts`. Mutations, all red:- `'revisions'` added to `keepLiveWhenAbsent`, together with thenormalisation removed, which resurrects cleared drafts. With thenormalisation still in place, only the pins catch adding `'revisions'`.++## 2026-10-17 — bento/spaces drops its own "absent revisions = cleared" step; the kernel does it++This supersedes one part of the 2026-10-15 entry "bento/spaces restores by+direction". That entry's `asWholeRecovery` step, which turned an absent+`revisions` into `[]` before a recovery, is gone. Since kernel #726, a whole+recovery snapshot removes an absent history key by default, so cleared+history stays cleared without the spaces step. `RECOVER_RULES` still opts out+exactly `['trail']` (`keepLiveWhenAbsent`), because a missing trail means "no+rows yet", not a clear. `revisionsRecover` is kept unchanged:+- a `[]` the snapshot carries still removes the key;+- a foreign list on either side still keeps the live list;+- a readable recovered list still follows the snapshot.++With the step gone, the list is the only thing keeping cleared history+cleared. `scripts/test-spaces-restore.ts` holds it two ways:+- a pin that the list is exactly `['trail']`;+- a behavioural row that plants `['trail', 'revisions']` on the real rules+ and runs the real recovery path. The cleared drafts come back, and the row+ asserts that the real rules do not do this.++Mutations, all red:+- adding `'revisions'` to the list: 8 rows in that rig and 1 in+ `test-spaces-restore-gate.ts`, including every cleared-stays-cleared row+ (before this change, only the 2 pins caught it);+- removing the list: 6 + 1, covering the trail rows.diff --git a/scripts/test-spaces-model.ts b/scripts/test-spaces-model.tsindex 65e5738b..cbe92e7d 100644--- a/scripts/test-spaces-model.ts+++ b/scripts/test-spaces-model.ts@@ -456,7 +456,7 @@ for (const [label, input, err] of [// entry is foreign input, gated first — restoregate.ts — and then handed to// replaceDoc, going 'back')const gate = fs.readFileSync(new URL('../spaces/src/restoregate.ts', import.meta.url), 'utf8')- ok(/restoreVersion\(h\.store, v\.json\)/.test(about) && /store\.replaceDoc\(incoming, direction/.test(gate) &&+ ok(/restoreVersion\(h\.store, v\.json\)/.test(about) && /store\.replaceDoc\(g\.doc, direction/.test(gate) &&/function restoreVersion\([^)]*\)[^{]*\{\s*return restoreInto\(store, json, 'back'\)/.test(gate),'…and restores through replaceDoc, so ⌘Z walks it back')}diff --git a/scripts/test-spaces-restore.ts b/scripts/test-spaces-restore.tsindex bbc2bbe5..cd065d68 100644--- a/scripts/test-spaces-restore.ts+++ b/scripts/test-spaces-restore.ts@@ -31,7 +31,7 @@ import { readFileSync } from 'node:fs'import { join } from 'node:path'import { Store, RESTORE_RULES, RECOVER_RULES, rulesFor, restoreAt } from '../spaces/src/store.ts'import { parseDoc, FORMAT, type SpacesDoc } from '../spaces/src/model.ts'-import { recoverInto, restoreVersion, replaceFromJson, recoveryOffered, gateRestored, asWholeRecovery } from '../spaces/src/restoregate.ts'+import { recoverInto, restoreVersion, replaceFromJson, recoveryOffered, gateRestored } from '../spaces/src/restoregate.ts'import { trailRecover, pruneTrail, TRAIL_BUDGET, TRAIL_MAX, spanOf, dayIndex, parseTrailKey, type Trail, type TrailRow } from '../spaces/src/trail.ts'import { recordRevision, restoredDoc, revisionsOf, revisionsRecover, clearHistory } from '../spaces/src/history.ts'import { recoveryBanner, wireRecoveryOff, type RecoveryBanner } from '../spaces/src/recoverynotice.ts'@@ -303,10 +303,33 @@ console.log('\n5. crash recovery goes RECOVER\n')const s2 = new Store(mk({ revisions: clone(DRAFTS) }))const withEmpty = snapOf(mk()); withEmpty.revisions = []; withEmpty.pages[0].blocks[0].html = 'e'ok(recoverInto(s2, { json: J(withEmpty), at: LIVE_MS + HOUR }) && !('revisions' in s2.doc), 'an incoming [] is cleared too: no key, never `revisions: []`')- // the normalisation itself- ok(J((asWholeRecovery({ ...mk(), revisions: undefined } as SpacesDoc) as Obj).revisions) === '[]', 'asWholeRecovery states an absent revisions as []')- const has = mk({ revisions: clone(DRAFTS) })- ok(asWholeRecovery(has) === has, '…and leaves a snapshot that carries revisions untouched')+ // THE GUARD, MEASURED. Spaces no longer normalises an absent `revisions`+ // itself; the kernel (#726) removes it from a whole snapshot unless the+ // field is listed in keepLiveWhenAbsent. So RECOVER_RULES' list is the one+ // thing between a cleared history and its resurrection. Plant the mistake —+ // a variant listing 'revisions' — on the REAL rules object and run the REAL+ // recovery path: the cleared drafts come BACK. That is the failure the+ // exact-list pin above exists to prevent; the real rules must not do it.+ {+ const realList = RECOVER_RULES.keepLiveWhenAbsent+ const runRecovery = (): SpacesDoc => {+ const st = new Store(mk({ revisions: clone(DRAFTS) })) // the file still has the drafts+ recoverInto(st, { json: snapJson, at: LIVE_MS + HOUR }) // the snapshot was taken after Clear history+ return st.doc+ }+ let planted: SpacesDoc+ try {+ ;(RECOVER_RULES as { keepLiveWhenAbsent?: readonly string[] }).keepLiveWhenAbsent = ['trail', 'revisions']+ planted = runRecovery()+ } finally {+ ;(RECOVER_RULES as { keepLiveWhenAbsent?: readonly string[] }).keepLiveWhenAbsent = realList+ }+ ok(J(planted.revisions) === J(DRAFTS),+ 'PLANTED BUG: rules listing \'revisions\' in keepLiveWhenAbsent RESURRECT the cleared drafts (the bug the list guards against)')+ const real = runRecovery()+ ok(!('revisions' in real), '…while the REAL RECOVER_RULES leave cleared history cleared')+ ok(J(RECOVER_RULES.keepLiveWhenAbsent) === J(['trail']), '…and the plant was undone (the list is exactly [\'trail\'] again)')+ }// a FOREIGN LIVE list is never written over by a readable recovered oneconst foreignLive = [{ id: 'future', at: '2026-09-01T00:00:00Z', body: { v9: true, pages: 'a newer shape' } }]const s3 = new Store(mk({ revisions: clone(foreignLive) }))diff --git a/spaces/src/history.ts b/spaces/src/history.tsindex 173117b5..6d3982f8 100644--- a/spaces/src/history.ts+++ b/spaces/src/history.ts@@ -245,13 +245,14 @@ export function historyIsForeign(doc: SpacesDoc): boolean {* store.ts `RESTORE_RULES` and consulted only by the crash-recovery banner* ('recover'), only when the snapshot carries the key. In this ORDER:*- * 1. `[]` — CLEARED. restoregate.ts `asWholeRecovery` turns a snapshot with- * NO `revisions` into `[]` before the kernel sees it (the snapshot is the- * whole document, so absence means the person ran Clear history). Return- * `undefined` so the key is REMOVED, exactly as Clear history deletes it- * and never stores `[]`. Cleared stays cleared: otherwise drafts somebody- * cleared before sharing came back with Restore and left in the next copy- * — confidentiality beats integrity behind a banner the person accepted.+ * 1. `[]` — CLEARED. Return `undefined` so the key is REMOVED, exactly as+ * Clear history deletes it and never stores `[]`. (A snapshot with NO+ * `revisions` never reaches this hook: the kernel removes an absent+ * history key from a whole snapshot itself, #726, and RECOVER_RULES does+ * not opt `revisions` out.) Cleared stays cleared: otherwise drafts+ * somebody cleared before sharing came back with Restore and left in the+ * next copy — confidentiality beats integrity behind a banner the person+ * accepted.* 2. FOREIGN incoming — not an array, or any entry failing `readable` (the* check a file's list passes, `historyIsForeign`) → keep LIVE. A recovery* snapshot is foreign input (file:// documents share its IndexedDB); onediff --git a/spaces/src/restoregate.ts b/spaces/src/restoregate.tsindex 081cdb9c..72e9a95f 100644--- a/spaces/src/restoregate.ts+++ b/spaces/src/restoregate.ts@@ -71,30 +71,7 @@ export function gateRestored(): Gated {const g = gateOnly(json, live)if (!g.ok) return g- const incoming = direction === 'recover' ? asWholeRecovery(g.doc) : g.doc- return { ok: true, doc: applyRestore(live, incoming, direction, rulesFor(direction), restoreAt(live, incomingAt)) }-}--/**- * The recovery path only ('recover', RECOVER_RULES — the whole-snapshot- * path): a snapshot with NO `revisions` means the person CLEARED them.- *- * The snapshot is kernel autosave's `contentOnly(doc)`, the WHOLE document, so- * a missing key is a deleted one. When this was written the kernel kept an- * ABSENT history field live before any hook ran, so Restore brought back- * drafts Clear history had removed; the absence is therefore stated as `[]`,- * which history.ts `revisionsRecover` reads as "cleared" and answers by- * removing the key. Since kernel #726 a whole snapshot removes an absent- * history key itself, so this is now REDUNDANT (same result) and kept as a- * second guard; removing it is a separate follow-up.- *- * `trail` is NOT normalised, and RECOVER_RULES opts it out of #726's removal- * (keepLiveWhenAbsent: ['trail']): a whole snapshot with no trail means "no- * rows yet", so the live rows stay.- */-export function asWholeRecovery(doc: SpacesDoc): SpacesDoc {- if ((doc as { revisions?: unknown }).revisions !== undefined) return doc- return { ...doc, revisions: [] } as SpacesDoc+ return { ok: true, doc: applyRestore(live, g.doc, direction, rulesFor(direction), restoreAt(live, incomingAt)) }}/** The gate itself — bounded, prototype-safe, this space's docId, parseDoc,@@ -156,9 +133,10 @@ export function restoreInto(store: Store, json: unknown, direction: RestoreDirecif (store.readOnly) return falseconst g = gateOnly(json, store.doc)if (!g.ok) return false- // 'recover' is the whole-snapshot path: an absent `revisions` was cleared- const incoming = direction === 'recover' ? asWholeRecovery(g.doc) : g.doc- store.replaceDoc(incoming, direction, restoreAt(store.doc, incomingAt))+ // On 'recover' (RECOVER_RULES, a WHOLE snapshot) the kernel removes an+ // absent `revisions` itself (#726): the person cleared it, and cleared stays+ // cleared. Only `trail` opts out (keepLiveWhenAbsent).+ store.replaceDoc(g.doc, direction, restoreAt(store.doc, incomingAt))return true}diff --git a/spaces/src/store.ts b/spaces/src/store.tsindex 940b92d9..c0f59e0c 100644--- a/spaces/src/store.ts+++ b/spaces/src/store.ts@@ -77,7 +77,7 @@ export { FROM_LIVE }* this space, so history is reconciled with it rather than kept:* `revisions` follows the snapshot when it carries a READABLE* list, is REMOVED when the snapshot has none (a whole snapshot- * without it was CLEARED — restoregate.ts asWholeRecovery), and+ * without it was CLEARED — the kernel's default since #726), and* a foreign list on either side keeps live (history.ts* `revisionsRecover`); `trail` unions by day (trail.ts* `trailRecover`), so an absent trail keeps the live rows.@@ -113,6 +113,10 @@ export const RECOVER_RULES: RestoreRules = {// `trail`: nobody "clears" a trail by omission; a snapshot without one means// "no rows yet" (recorded nothing before the crash), and the live rows are// observations nobody can recompute. ONLY 'trail', never 'revisions'.+ // This list is the ONE thing keeping cleared history cleared on recovery+ // (spaces no longer normalises an absent `revisions` itself):+ // scripts/test-spaces-restore.ts pins it to exactly ['trail'] and proves a+ // variant listing 'revisions' brings cleared drafts back.keepLiveWhenAbsent: ['trail'],}validateRestoreRules(RECOVER_RULES)