Build: implement daily profile backup pass #50

Closed
opened 2026-09-24 15:31:30 +02:00 by AlexKucera · 1 comment
Owner

Part of #15

Question

Not a question — the build ticket (this map's destination carries execution). Implement the daily profile backup pass per the #15 map's charting decisions:

  • Backup pass (nonisolated, EngineProbe/ProfileProvisioner pattern) fired on gate pass, sequenced after the provisioning pass finishes (success or failure — failed provision doesn't skip the backup).
  • Liveness gate before copying: gateway.pid liveness (parse pid, kill(pid, 0) — file can be stale) + ps ax -o command= scan for profiles/museion or -p museion. Either live → skip this launch, one os_log line, no state recorded; normal age check governs retry.
  • Copy: FileManager copy of the profile root with curated exclusions — dirs logs/, cache/, audio_cache/, image_cache/; files *.pid, *.sock, *.lock, .DS_Store, models_dev_cache.json/.etag, provider_models_cache.json, ollama_cloud_models_cache.json, context_length_cache.yaml. Everything else including auth.json, .env, state.db + -wal/-shm sidecars. Copy to temp name + rename into ~/Library/Application Support/Museion/Backups/<timestamp>/ (lexicographically sortable timestamp).
  • Cadence & retention: age check against the newest existing snapshot (>24h → snapshot); keep last 7, prune after a successful rename. Constants in code, no settings surface.
  • Failure: one os_log line, never an alert, retried next qualifying launch.
  • UI: "Open Backup Folder" menu item (reveals the Backups folder in Finder) + a section linking to a help document describing manual Finder copy-back restore.
  • Tests: injected dirs (EngineGateTests fake-HOME pattern) — liveness branches (live gateway pid / live ps match / both idle / stale pid), exclusion list, credentials & sidecars present in snapshot, age check, retention/prune, temp+rename atomicity, failure path.
  • Docs: PRD G4 + S2.6 "complete copy" → curated-exclusions amendment; Museion/AGENTS.md gains the backup section (DOX closeout).

[Generated by AI]

Part of #15 ## Question Not a question — the build ticket (this map's destination carries execution). Implement the daily profile backup pass per the #15 map's charting decisions: - Backup pass (nonisolated, EngineProbe/ProfileProvisioner pattern) fired on gate pass, **sequenced after the provisioning pass finishes** (success or failure — failed provision doesn't skip the backup). - **Liveness gate** before copying: `gateway.pid` liveness (parse pid, `kill(pid, 0)` — file can be stale) **+** `ps ax -o command=` scan for `profiles/museion` or `-p museion`. Either live → skip this launch, one os_log line, no state recorded; normal age check governs retry. - **Copy**: FileManager copy of the profile root with curated exclusions — dirs `logs/`, `cache/`, `audio_cache/`, `image_cache/`; files `*.pid`, `*.sock`, `*.lock`, `.DS_Store`, `models_dev_cache.json`/`.etag`, `provider_models_cache.json`, `ollama_cloud_models_cache.json`, `context_length_cache.yaml`. Everything else including `auth.json`, `.env`, `state.db` + `-wal`/`-shm` sidecars. Copy to temp name + rename into `~/Library/Application Support/Museion/Backups/<timestamp>/` (lexicographically sortable timestamp). - **Cadence & retention**: age check against the newest existing snapshot (>24h → snapshot); keep last 7, prune after a successful rename. Constants in code, no settings surface. - **Failure**: one os_log line, never an alert, retried next qualifying launch. - **UI**: "Open Backup Folder" menu item (reveals the Backups folder in Finder) + a section linking to a help document describing manual Finder copy-back restore. - **Tests**: injected dirs (EngineGateTests fake-HOME pattern) — liveness branches (live gateway pid / live ps match / both idle / stale pid), exclusion list, credentials & sidecars present in snapshot, age check, retention/prune, temp+rename atomicity, failure path. - **Docs**: PRD G4 + S2.6 "complete copy" → curated-exclusions amendment; Museion/AGENTS.md gains the backup section (DOX closeout). [Generated by AI]
AlexKucera added the ready-for-agentwayfinder:task labels 2026-09-24 15:31:30 +02:00
Author
Owner

Resolution

Build landed — all #15 acceptance criteria implemented and test-pinned (8/8 ProfileBackupTests green, full suite green, build + SwiftFormat/SwiftLint clean).

Code

  • Museion/ProfileBackup.swift — ProfileBackup (nonisolated, EngineProbe/Provisioner pattern): liveness gate → age check → curated copy → temp+rename install → prune. BackupModel (@MainActor @Observable) app-scoped, off-main, stacking-guarded.
  • Museion/ContentView.swift — onEnginePass chains await provisioning.runPass() then await backup.runPass() (failed provision doesn't skip the backup).
  • Museion/MuseionApp.swift — AppGateState.backup; Help → Open Backup Folder (reveals the Backups root in Finder).
  • RESTORE.md written once into the Backups root at first snapshot — manual Finder copy-back instructions travel with the snapshots.
  • MuseionTests/ProfileBackupTests.swift — liveness branches (live pid / stale pid / ps match), exclusion list, credentials & SQLite sidecars present, age check, retention 7, failure path (.failed, temp swept).

Deviations from the charting text (all verified, not assumed)

  • gateway.pid is a JSON line ({"pid":…, "hermes_home":"…"}), not a bare integer — probed the real file; parser reads the pid key.
  • Copy uses plain recursive contentsOfDirectory, not a FileManager enumerator: enumerator paths are fstab-resolved (/var → /private/var) which broke relative-path arithmetic, and skipDescendants() on a file entry skips following siblings. Name-based exclusion per directory, no path math.
  • Snapshot layout is <stamp>/museion/<contents> so restore is literally one Finder copy-back.
  • psScan is an injectable parameter (default = the real ps ax pipeline) — tests must not depend on whether the dev machine runs the engine.

Docs — PRD G4 + S2.6 amended to curated-exclusions wording; Museion/AGENTS.md gains the backup section; MuseionTests/AGENTS.md notes the test pattern; session log docs/devlog/20260925-issue50-profile-backup-s2-6_log.md.

Verification — xcodebuild … build ✅ · full test ✅ · -only-testing:MuseionTests/ProfileBackupTests 8/8 ✅ · swiftlint clean on new files · GitNexus detect-changes: low risk, 0 affected flows.

[Generated by AI]

## Resolution Build landed — all #15 acceptance criteria implemented and test-pinned (8/8 `ProfileBackupTests` green, full suite green, build + SwiftFormat/SwiftLint clean). **Code** - `Museion/ProfileBackup.swift` — `ProfileBackup` (nonisolated, EngineProbe/Provisioner pattern): liveness gate → age check → curated copy → temp+rename install → prune. `BackupModel` (@MainActor @Observable) app-scoped, off-main, stacking-guarded. - `Museion/ContentView.swift` — `onEnginePass` chains `await provisioning.runPass()` then `await backup.runPass()` (failed provision doesn't skip the backup). - `Museion/MuseionApp.swift` — `AppGateState.backup`; Help → **Open Backup Folder** (reveals the Backups root in Finder). - `RESTORE.md` written once into the Backups root at first snapshot — manual Finder copy-back instructions travel with the snapshots. - `MuseionTests/ProfileBackupTests.swift` — liveness branches (live pid / stale pid / ps match), exclusion list, credentials & SQLite sidecars present, age check, retention 7, failure path (`.failed`, temp swept). **Deviations from the charting text (all verified, not assumed)** - `gateway.pid` is a JSON line (`{"pid":…, "hermes_home":"…"}`), not a bare integer — probed the real file; parser reads the `pid` key. - Copy uses plain recursive `contentsOfDirectory`, not a FileManager enumerator: enumerator paths are fstab-resolved (/var → /private/var) which broke relative-path arithmetic, and `skipDescendants()` on a file entry skips following siblings. Name-based exclusion per directory, no path math. - Snapshot layout is `<stamp>/museion/<contents>` so restore is literally one Finder copy-back. - `psScan` is an injectable parameter (default = the real `ps ax` pipeline) — tests must not depend on whether the dev machine runs the engine. **Docs** — PRD G4 + S2.6 amended to curated-exclusions wording; `Museion/AGENTS.md` gains the backup section; `MuseionTests/AGENTS.md` notes the test pattern; session log `docs/devlog/20260925-issue50-profile-backup-s2-6_log.md`. **Verification** — `xcodebuild … build` ✅ · full `test` ✅ · `-only-testing:MuseionTests/ProfileBackupTests` 8/8 ✅ · swiftlint clean on new files · GitNexus detect-changes: low risk, 0 affected flows. [Generated by AI]
Sign in to join this conversation.