One liveness-gated snapshot pass per launch, chained after provisioning: gateway.pid pid-liveness + ps scan (skip while the engine runs), 24 h age check, curated recursive copy (credentials and SQLite sidecars in; logs/caches/locks out), atomic temp+rename install, keep last 7. Restore stays manual copy-back in v1 — Help > Open Backup Folder and a RESTORE.md written beside the snapshots. [Generated by AI]
5.5 KiB
5.5 KiB
M0: Profile backup — daily snapshot pass (S2.6)
Date: 2026-09-25 Type: issue Reference: #50 Build: implement daily profile backup pass (map #15)
Goal
Land the #15 map's build ticket: the mentor's accumulated state survives profile corruption or a bad update. On qualifying launches Museion copies the whole museion profile to a timestamped snapshot under ~/Library/Application Support/Museion/Backups/, keeping the last 7 — liveness-gated, credentials included, restore = manual Finder copy-back in v1.
What Was Done
Museion/ProfileBackup.swift(new) —ProfileBackup(nonisolated enum, EngineProbe/Provisioner pattern): one pass = liveness gate → age check → curated recursive copy → temp+rename atomic install → prune past 7.BackupModel(@MainActor @Observable) app-scoped viaAppGateState.backup, runs off-main, guards stacking.Museion/ContentView.swift—onEnginePasschainsprovisioning.runPassthenbackup.runPass(a failed provision doesn't skip the backup; sequencing avoids racing the per-skill seed renames).Museion/MuseionApp.swift—AppGateState.backup; Help menu → Open Backup Folder (NSWorkspace.openon the Backups root).RESTORE.mdwritten once into the Backups root at first snapshot — manual copy-back instructions travel with the snapshots.MuseionTests/ProfileBackupTests.swift(new) — 8 tests, injected roots/clock/psScan.PRD.mdG4 + S2.6 amended (curated-exclusions wording per the map's charting decision);Museion/AGENTS.mdbackup section;MuseionTests/AGENTS.mdtest-pattern note.
Decisions & Rationale
| Decision | Rationale |
|---|---|
Plain contentsOfDirectory recursion for the copy, not FileManager.enumerator |
Enumerator yields fstab-resolved paths (/var → /private/var), so substring rel-path arithmetic silently produced garbage; skipDescendants() on a file entry also eats following siblings. The plain walk has no path math and no traps — smaller and correct. |
psScan injectable, default real ps ax pipeline via EngineProbe.execute |
Tests must not depend on whether a dev machine happens to run the real engine (hermes acp -p museion would make every CI/dev run skip). Map decision preserved in production default. |
Snapshot layout <stamp>/museion/<contents> |
The folder name travels with the snapshot so restore is literally one Finder copy-back — RESTORE.md documents exactly that shape. |
RESTORE.md as static text written into the Backups root, not a bundled help-book resource |
It must sit beside the snapshots it describes even when the app that wrote them is gone (corruption scenario = the app may be reinstalling). |
| Sequencing as caller's await chain, not a polling wait inside BackupModel | await provisioning.runPass(); await backup.runPass() — one line, no timer hack, failure-independent (#15 decision). |
gateway.pid parsed as JSON (pid key), not bare integer |
Probed the real file: it's a JSON line {"pid":…, "hermes_home":"…"}. The map's "parse pid" assumed integer; JSON parse is the verified reality. |
Gotchas & Fixes
| Problem | Root Cause | Fix |
|---|---|---|
Snapshot's museion/ dir empty — all credential assertions failed |
skipDescendants() called on excluded file entries skipped subsequent siblings; separately, enumerator's resolved paths broke dropFirst(source.count) rel-path math across the /var symlink |
Replaced the whole enumerator approach with plain recursive contentsOfDirectory + name-based exclusion |
Tests failed on missing state.db at snapshot root |
Copy landed profile contents directly at <stamp>/, not <stamp>/museion/ |
Create museion/ payload dir inside the temp snapshot before copying |
| Test-target build error "Argument 'timeZone' must precede 'year'" | DateComponents memberwise init has a fixed argument order |
Built components via property assignment |
SwiftFormat reformatted prototypes/GateUIPrototype.swift (untouched file) |
Blanket swiftformat . |
Reverted via git checkout — drive-by formatting isn't part of this ticket |
Files Changed
| File | Change Summary |
|---|---|
Museion/ProfileBackup.swift |
New — backup pass, liveness gate, curated copy, retention, RESTORE.md |
Museion/ContentView.swift |
onEnginePass chains backup after provisioning |
Museion/MuseionApp.swift |
AppGateState.backup; Help → Open Backup Folder |
MuseionTests/ProfileBackupTests.swift |
New — 8 tests: liveness branches, exclusions, credentials, age, retention, failure |
PRD.md |
G4 + S2.6 amended to curated-exclusions wording |
Museion/AGENTS.md |
New "Profile backup" section (DOX) |
MuseionTests/AGENTS.md |
ProfileBackupTests pattern note |
AGENTS.md |
GitNexus counter refresh (965 symbols) + this log's window row |
Open Items & Next Steps
- All four #15 acceptance criteria test-pinned (daily cadence, complete-of-what-matters copy, last-7 retention, manual-restore docs; snapshots user-local by construction — Backups root is in Application Support, never the project).
- First real snapshot happens at next qualifying launch (engine idle, newest >24 h) — verify
~/Library/Application Support/Museion/Backups/then. - Map #15 closeout: resolution comment + Decisions-so-far pointer (blocked on forge-write authorization).
Log written by write-log skill