refactor(rigs): address external-review findings

- Recall router state in applyState: the lightweight (no-rebuild) recall path
  now positionally applies router branch pedal params and the splitter/merger
  blend, instead of silently dropping them for routed rigs. Test added.
- Simplify first-run seeding: RigLibraryStore.save persists asynchronously
  (best-effort, logged not thrown), so the previous per-entry rollback could
  never fire for a real disk failure. Replaced with an honest best-effort
  save + working-rig fallback, and a comment stating the semantics.
- Move FactoryRigBuild to its own file (one public type per file).
- Document that a router's output master gain is intentionally not persisted,
  matching BoardState's treatment of board master gain.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 13:32:58 -07:00
parent 7dccf596f4
commit 2c970aa344
6 changed files with 78 additions and 40 deletions
@@ -46,39 +46,20 @@ public enum RigLibraryBootstrap {
// working session is intentionally left as-is (no `currentRigID`) — the user picks a starter
// rig from the sidebar to load it, rather than the highlight pointing at a rig the working
// graph has not actually loaded.
let entries: [RigEntry]
do {
entries = try FactoryRigLibrary.makeEntries()
} catch {
// Building the shipped rigs is deterministic and should never fail at runtime; if it
// somehow does, fall back to seeding the working rig so the library is not left empty.
print("[RigLibraryBootstrap] building factory rigs failed: \(error)")
seedWorkingRig(store, seedFrom: shoeGaze, seedName: seedName)
return
}
// Save sequentially, rolling back on failure. Seeding is gated on `store.entries.isEmpty`,
// so a partially-saved library would be frozen forever (never retried, never completed). If
// any save fails, delete the entries saved this run so the library returns to empty and a
// later launch retries the full seed. (This is best-effort, not truly atomic: if a rollback
// `delete` itself fails, a partial set can still be left behind and frozen — the residual
// hole a non-transactional store cannot fully close.)
var savedThisRun: [RigEntry] = []
// Seed the shipped starter rigs. `store.save` updates the in-memory library synchronously
// (so the session sees every rig immediately) and persists to disk asynchronously — a disk
// failure is logged by the store, not thrown here, so there is no per-entry rollback to do.
// `save` throws only on a synchronous encode failure of this deterministic rig data, which
// should not happen at runtime; if the build or an encode somehow fails, fall back to
// seeding the working rig so the library is never left empty on first run.
do {
let entries: [RigEntry] = try FactoryRigLibrary.makeEntries()
for entry: RigEntry in entries {
try store.save(entry)
savedThisRun.append(entry)
}
} catch {
print("[RigLibraryBootstrap] seeding factory rigs failed after "
+ "\(savedThisRun.count)/\(entries.count); rolling back: \(error)")
for entry: RigEntry in savedThisRun {
do {
try store.delete(entry)
} catch {
print("[RigLibraryBootstrap] rollback of '\(entry.name)' failed: \(error)")
}
}
print("[RigLibraryBootstrap] seeding factory rigs failed: \(error)")
seedWorkingRig(store, seedFrom: shoeGaze, seedName: seedName)
}
}