diff --git a/architecture.md b/architecture.md index e64f89d..74c3434 100644 --- a/architecture.md +++ b/architecture.md @@ -336,6 +336,12 @@ Revision conflict handling belongs to the server/editor boundary in M9.3. Profile switch: parse/validate candidate, prepare/probe required resources without writes, pause input briefly, drain old writes with a deadline, obtain fresh state, then commit a new config generation and publish bindings/feedback together. Abort on prepare failure and retain the old profile. If an old in-flight call cannot be safely drained, close/reconnect and reconcile before activation; generation tags alone do not cancel native writes. In-flight group membership is fixed at command acceptance. Re-arm pickup, invalidate stale queued commands, and adopt live volumes by default. Persist the active profile pointer only after successful activation; disk failure leaves the active runtime profile clearly marked unsaved. Durable crash-atomic multi-file transactions are not claimed. +The Pulse implementation accepts a profile switch only when its bounded dispatch +queue and published objects have no pending operation. A busy switch is rejected +for retry after readback/reconciliation rather than publishing over in-flight +native work. The committed mapping generation advances the public mixer revision, +invalidating commands created from the prior profile. + ## CLI, IPC, and TUI Plan `fader_master serve`, `tui`, `validate --config PATH`, `devices`, `status`, and `profile switch ID`. Run one server per user/runtime namespace with an owned Unix socket and lock; TUI disconnect must not stop MIDI control. No network listener. Bound IPC message size and queue sizes, enforce socket permissions/peer identity, negotiate protocol version, use request IDs and revisioned snapshots, and resnapshot after missed deltas. Length-prefixed UTF-8 TOML messages reuse Serde schemas initially; cap frames before allocation. diff --git a/fader_master/src/cli.rs b/fader_master/src/cli.rs index b0e82d4..733a4f4 100644 --- a/fader_master/src/cli.rs +++ b/fader_master/src/cli.rs @@ -57,7 +57,12 @@ pub enum Command { #[derive(Clone, Debug, PartialEq, Subcommand)] pub enum ProfileCommand { /// Request activation of a validated profile ID. - Switch { id: String }, + Switch { + id: String, + /// Override the XDG runtime socket path. + #[arg(long)] + socket: Option, + }, } #[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)] diff --git a/fader_master/src/ipc.rs b/fader_master/src/ipc.rs index 1039282..43d24d6 100644 --- a/fader_master/src/ipc.rs +++ b/fader_master/src/ipc.rs @@ -3,7 +3,7 @@ use std::io::{self, Read, Write}; use serde::{Deserialize, Serialize, de::DeserializeOwned}; use thiserror::Error; -pub const PROTOCOL_VERSION: u16 = 8; +pub const PROTOCOL_VERSION: u16 = 9; pub const MAX_FRAME_BYTES: usize = 64 * 1024; /// Kind of mixer object addressed by a client. @@ -59,6 +59,9 @@ pub enum RequestCommand { SaveConfiguration { expected_revision: u64, }, + SwitchProfile { + id: String, + }, SetVolume { object: MixerObjectKey, gain: f64, diff --git a/fader_master/src/live.rs b/fader_master/src/live.rs index 29024ea..fb188a6 100644 --- a/fader_master/src/live.rs +++ b/fader_master/src/live.rs @@ -67,6 +67,7 @@ pub struct LiveMixerState { backend: String, status: String, configuration: ConfigurationSnapshot, + revision_offset: u64, } #[derive(Debug, Error)] @@ -262,6 +263,7 @@ impl LiveMixerState { backend: backend.into(), status: "connecting".to_owned(), configuration: configuration_snapshot(profile, 0, false, 0), + revision_offset: 0, }) } @@ -382,7 +384,7 @@ impl LiveMixerState { objects.push(output); } MixerSnapshot { - revision: self.reducer.revision().get(), + revision: self.view_revision(), backend: self.backend.clone(), status: self.status.clone(), objects, @@ -417,14 +419,21 @@ impl LiveMixerState { } /// Replaces profile-derived routing while retaining confirmed backend state. - pub(crate) fn reconfigure(&mut self, profile: &Profile) -> Result<(), LiveMixerError> { - let mut replacement = Self::new(self.write_ceiling, self.backend.clone(), profile)?; + pub(crate) fn reconfigure( + &mut self, + profile: &Profile, + write_ceiling: Gain, + ) -> Result<(), LiveMixerError> { + let next_revision = self.view_revision().saturating_add(1); + let mut replacement = Self::new(write_ceiling, self.backend.clone(), profile)?; std::mem::swap(&mut replacement.reducer, &mut self.reducer); std::mem::swap(&mut replacement.metadata, &mut self.metadata); std::mem::swap(&mut replacement.output, &mut self.output); std::mem::swap(&mut replacement.status, &mut self.status); std::mem::swap(&mut replacement.devices, &mut self.devices); replacement.configuration = self.configuration.clone(); + replacement.revision_offset = + next_revision.saturating_sub(replacement.reducer.revision().get()); *self = replacement; let faders = self.faders.keys().cloned().collect::>(); self.rearm_faders(&faders); @@ -601,6 +610,11 @@ impl LiveMixerState { .to_owned(), )); } + RequestCommand::SwitchProfile { .. } => { + return Err(LiveMixerError::Profile( + "profile switches must be handled by the server owner".to_owned(), + )); + } RequestCommand::SetVolume { object, gain, @@ -742,7 +756,7 @@ impl LiveMixerState { } fn check_revision(&self, expected: u64) -> Result<(), LiveMixerError> { - let current = self.reducer.revision().get(); + let current = self.view_revision(); if current == expected { Ok(()) } else { @@ -753,6 +767,11 @@ impl LiveMixerState { } } + fn view_revision(&self) -> u64 { + self.revision_offset + .saturating_add(self.reducer.revision().get()) + } + fn writable_handles( &self, object: &MixerObjectKey, @@ -867,13 +886,30 @@ mod reconfigure_tests { operation: None, })) .unwrap(); + let old_revision = state.snapshot().revision; let edited = source.replace("label = \"Music\"", "label = \"Listening\""); state - .reconfigure(&Profile::parse(&edited).unwrap()) + .reconfigure(&Profile::parse(&edited).unwrap(), Gain::UNITY) .unwrap(); let snapshot = state.snapshot(); assert_eq!(snapshot.objects[0].label, "Listening"); assert_eq!(snapshot.objects[0].gain, Some(0.6)); + assert!(snapshot.revision > old_revision); + let stale = state + .request(ClientRequest { + version: PROTOCOL_VERSION, + request_id: 99, + command: RequestCommand::SetVolume { + object: MixerObjectKey { + kind: MixerObjectKind::Application, + id: "music".to_owned(), + }, + gain: 0.2, + expected_revision: old_revision, + }, + }) + .unwrap_err(); + assert!(matches!(stale, LiveMixerError::StaleRevision { .. })); } } diff --git a/fader_master/src/local.rs b/fader_master/src/local.rs index 243b9c3..364bc0b 100644 --- a/fader_master/src/local.rs +++ b/fader_master/src/local.rs @@ -179,6 +179,7 @@ pub struct LocalServer { poll_interval: Duration, configuration: ConfigurationEditor, applied_configuration_revision: u64, + profile_directory: PathBuf, } impl LocalServer { @@ -191,6 +192,13 @@ impl LocalServer { let profile = document.preview()?; let midi = crate::midi_runtime::MidiRuntime::new(&profile).map_err(LocalError::MidiRuntime)?; + let profile_directory = profile_path + .parent() + .ok_or_else(|| fader_config::ConfigError::Validation { + path: "profile.path".to_owned(), + message: "profile path has no parent directory".to_owned(), + })? + .to_owned(); Ok(Self { listener: OwnedListener::bind(socket)?, // One waiting native command keeps round-trip backpressure at the @@ -208,6 +216,7 @@ impl LocalServer { poll_interval: profile.poll_interval(), configuration: ConfigurationEditor::new(document, profile_path), applied_configuration_revision: 0, + profile_directory, }) } @@ -298,116 +307,88 @@ impl LocalServer { fn serve_client(&mut self, stream: &mut UnixStream) -> Result<(), LocalError> { let request: ClientRequest = read_frame(stream)?; let request_id = request.request_id; - let result = match request.command { - crate::ipc::RequestCommand::EditConfiguration { - expected_revision, - edit, - } if request.version == PROTOCOL_VERSION => { - match self.configuration.apply(expected_revision, edit) { - Ok(profile) => { - self.mixer.set_configuration(configuration_snapshot( - &profile, - self.configuration.revision(), - self.configuration.dirty(), - self.applied_configuration_revision, - )); - self.mixer.request(ClientRequest { - version: request.version, - request_id, - command: crate::ipc::RequestCommand::Snapshot, - }) + let result = (|| -> Result<_, crate::live::LiveMixerError> { + match request.command { + crate::ipc::RequestCommand::EditConfiguration { + expected_revision, + edit, + } if request.version == PROTOCOL_VERSION => { + match self.configuration.apply(expected_revision, edit) { + Ok(profile) => { + self.mixer.set_configuration(configuration_snapshot( + &profile, + self.configuration.revision(), + self.configuration.dirty(), + self.applied_configuration_revision, + )); + self.mixer.request(ClientRequest { + version: request.version, + request_id, + command: crate::ipc::RequestCommand::Snapshot, + }) + } + Err(error) => Err(crate::live::LiveMixerError::Profile(error.to_string())), } - Err(error) => Err(crate::live::LiveMixerError::Profile(error.to_string())), } - } - crate::ipc::RequestCommand::StartMidiLearn { - surface, - fader, - action, - } if request.version == PROTOCOL_VERSION => { - let profile = self - .configuration - .profile() - .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; - if !profile.surfaces().iter().any(|item| item.id() == surface) { - return self.write_client_error( - stream, - request_id, - format!("unknown MIDI surface {surface:?}"), - ); - } - if !profile.faders().iter().any(|item| item.id() == fader) { - return self.write_client_error( - stream, - request_id, - format!("unknown fader {fader:?}"), - ); - } - let action = match action.as_str() { - "volume" => fader_config::Action::Volume, - "toggle_mute" => fader_config::Action::ToggleMute, - _ => { - return self.write_client_error( - stream, - request_id, - format!("unsupported MIDI learn action {action:?}"), - ); - } - }; - let surface_id = SurfaceId::new(&surface) - .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; - let fader_id = FaderId::new(&fader) - .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; - self.midi.start_learn(crate::midi_runtime::MidiLearn { - surface: surface_id, - fader: fader_id, + crate::ipc::RequestCommand::StartMidiLearn { + surface, + fader, action, - }); - let mut configuration = configuration_snapshot( - &profile, - self.configuration.revision(), - self.configuration.dirty(), - self.applied_configuration_revision, - ); - configuration.learning = Some(format!("{surface} -> {fader} ({action:?})")); - self.mixer.set_configuration(configuration); - self.mixer.request(ClientRequest { - version: request.version, - request_id, - command: crate::ipc::RequestCommand::Snapshot, - }) - } - crate::ipc::RequestCommand::CancelMidiLearn if request.version == PROTOCOL_VERSION => { - self.midi.cancel_learn(); - let profile = self - .configuration - .profile() - .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; - self.publish_configuration(&profile, None); - self.mixer.request(ClientRequest { - version: request.version, - request_id, - command: crate::ipc::RequestCommand::Snapshot, - }) - } - crate::ipc::RequestCommand::ApplyConfiguration { expected_revision } - if request.version == PROTOCOL_VERSION => - { - if expected_revision != self.configuration.revision() { - Err(crate::live::LiveMixerError::Profile(format!( - "stale configuration revision {expected_revision}; current revision is {}", - self.configuration.revision() - ))) - } else { + } if request.version == PROTOCOL_VERSION => { + let profile = self + .configuration + .profile() + .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; + if !profile.surfaces().iter().any(|item| item.id() == surface) { + return Err(crate::live::LiveMixerError::Profile(format!( + "unknown MIDI surface {surface:?}" + ))); + } + if !profile.faders().iter().any(|item| item.id() == fader) { + return Err(crate::live::LiveMixerError::Profile(format!( + "unknown fader {fader:?}" + ))); + } + let action = match action.as_str() { + "volume" => fader_config::Action::Volume, + "toggle_mute" => fader_config::Action::ToggleMute, + _ => { + return Err(crate::live::LiveMixerError::Profile(format!( + "unsupported MIDI learn action {action:?}" + ))); + } + }; + let surface_id = SurfaceId::new(&surface) + .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; + let fader_id = FaderId::new(&fader) + .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; + self.midi.start_learn(crate::midi_runtime::MidiLearn { + surface: surface_id, + fader: fader_id, + action, + }); + let mut configuration = configuration_snapshot( + &profile, + self.configuration.revision(), + self.configuration.dirty(), + self.applied_configuration_revision, + ); + configuration.learning = Some(format!("{surface} -> {fader} ({action:?})")); + self.mixer.set_configuration(configuration); + self.mixer.request(ClientRequest { + version: request.version, + request_id, + command: crate::ipc::RequestCommand::Snapshot, + }) + } + crate::ipc::RequestCommand::CancelMidiLearn + if request.version == PROTOCOL_VERSION => + { + self.midi.cancel_learn(); let profile = self .configuration .profile() .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; - let midi = crate::midi_runtime::MidiRuntime::new(&profile) - .map_err(crate::live::LiveMixerError::Profile)?; - self.mixer.reconfigure(&profile)?; - self.midi = midi; - self.applied_configuration_revision = self.configuration.revision(); self.publish_configuration(&profile, None); self.mixer.request(ClientRequest { version: request.version, @@ -415,15 +396,24 @@ impl LocalServer { command: crate::ipc::RequestCommand::Snapshot, }) } - } - crate::ipc::RequestCommand::SaveConfiguration { expected_revision } - if request.version == PROTOCOL_VERSION => - { - match self.configuration.save(expected_revision) { - Ok(()) => { + crate::ipc::RequestCommand::ApplyConfiguration { expected_revision } + if request.version == PROTOCOL_VERSION => + { + if expected_revision != self.configuration.revision() { + Err(crate::live::LiveMixerError::Profile(format!( + "stale configuration revision {expected_revision}; current revision is {}", + self.configuration.revision() + ))) + } else { let profile = self.configuration.profile().map_err(|error| { crate::live::LiveMixerError::Profile(error.to_string()) })?; + let midi = crate::midi_runtime::MidiRuntime::new(&profile) + .map_err(crate::live::LiveMixerError::Profile)?; + self.mixer + .reconfigure(&profile, Gain::new(profile.max_gain())?)?; + self.midi = midi; + self.applied_configuration_revision = self.configuration.revision(); self.publish_configuration(&profile, None); self.mixer.request(ClientRequest { version: request.version, @@ -431,15 +421,99 @@ impl LocalServer { command: crate::ipc::RequestCommand::Snapshot, }) } - Err(error) => Err(crate::live::LiveMixerError::Profile(error.to_string())), } + crate::ipc::RequestCommand::SaveConfiguration { expected_revision } + if request.version == PROTOCOL_VERSION => + { + match self.configuration.save(expected_revision) { + Ok(()) => { + let profile = self.configuration.profile().map_err(|error| { + crate::live::LiveMixerError::Profile(error.to_string()) + })?; + self.publish_configuration(&profile, None); + self.mixer.request(ClientRequest { + version: request.version, + request_id, + command: crate::ipc::RequestCommand::Snapshot, + }) + } + Err(error) => Err(crate::live::LiveMixerError::Profile(error.to_string())), + } + } + crate::ipc::RequestCommand::SwitchProfile { id } + if request.version == PROTOCOL_VERSION => + { + let profile_id = fader_core::ProfileId::new(&id) + .map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?; + if !self.dispatch.is_empty() + || self + .mixer + .snapshot() + .objects + .iter() + .any(|item| item.pending) + { + Err(crate::live::LiveMixerError::Profile( + "profile switch is waiting for pending audio work to reconcile; retry" + .to_owned(), + )) + } else { + let path = self + .profile_directory + .join(format!("{}.toml", profile_id.as_str())); + let source = fs::read_to_string(&path).map_err(|error| { + crate::live::LiveMixerError::Profile(format!( + "could not read candidate profile {}: {error}", + path.display() + )) + })?; + let document = ProfileDocument::parse(&source).map_err(|error| { + crate::live::LiveMixerError::Profile(error.to_string()) + })?; + let profile = document.preview().map_err(|error| { + crate::live::LiveMixerError::Profile(error.to_string()) + })?; + if profile.id().as_str() != profile_id.as_str() { + return Err(crate::live::LiveMixerError::Profile(format!( + "candidate profile ID {:?} does not match requested {:?}", + profile.id().as_str(), + profile_id.as_str() + ))); + } + if profile.audio().adapter() == fader_config::Adapter::Pipewire { + return Err(crate::live::LiveMixerError::Profile( + "candidate requires native PipeWire but this server owns Pulse" + .to_owned(), + )); + } + if profile.poll_interval() != self.poll_interval { + return Err(crate::live::LiveMixerError::Profile( + "candidate changes runtime.poll_interval_ms; restart is required" + .to_owned(), + )); + } + let midi = crate::midi_runtime::MidiRuntime::new(&profile) + .map_err(crate::live::LiveMixerError::Profile)?; + self.mixer + .reconfigure(&profile, Gain::new(profile.max_gain())?)?; + self.midi = midi; + self.configuration = ConfigurationEditor::new(document, path); + self.applied_configuration_revision = 0; + self.publish_configuration(&profile, None); + self.mixer.request(ClientRequest { + version: request.version, + request_id, + command: crate::ipc::RequestCommand::Snapshot, + }) + } + } + command => self.mixer.request(ClientRequest { + version: request.version, + request_id, + command, + }), } - command => self.mixer.request(ClientRequest { - version: request.version, - request_id, - command, - }), - }; + })(); let response = match result { Ok((response, commands)) => { self.enqueue(commands)?; @@ -469,26 +543,6 @@ impl LocalServer { self.mixer.set_configuration(configuration); } - fn write_client_error( - &self, - stream: &mut UnixStream, - request_id: u64, - message: String, - ) -> Result<(), LocalError> { - write_frame( - stream, - &ServerResponse { - version: PROTOCOL_VERSION, - request_id, - result: ResponseResult::Error { - message, - resync: false, - }, - }, - )?; - Ok(()) - } - fn enqueue(&mut self, commands: Vec) -> Result<(), LocalError> { for command in commands { let operation = match &command { @@ -590,9 +644,11 @@ fn remove_stale_socket(path: &Path) -> Result<(), LocalError> { #[cfg(test)] mod tests { - use std::time::Instant; + use std::{fs, time::Instant}; use super::*; + use crate::ipc::RequestCommand; + use tempfile::tempdir; #[test] fn accepted_unix_peer_credentials_match_the_server_user() { @@ -611,4 +667,77 @@ mod tests { assert!(matches!(error, crate::ipc::FrameError::Truncated(_))); assert!(started.elapsed() < Duration::from_millis(250)); } + + #[test] + fn profile_switch_prepares_before_commit_and_invalid_candidate_keeps_old_profile() { + let root = tempdir().unwrap(); + let source = include_str!("../../examples/profiles/desktop.toml"); + let active_path = root.path().join("desktop.toml"); + fs::write(&active_path, source).unwrap(); + fs::write(root.path().join("broken.toml"), "not = [toml").unwrap(); + let native = source + .replace("id = \"desktop\"", "id = \"native\"") + .replace("adapter = \"auto\"", "adapter = \"pipewire\""); + fs::write(root.path().join("native.toml"), native).unwrap(); + let switched = source + .replace("id = \"desktop\"", "id = \"secondary\"") + .replace("label = \"Music\"", "label = \"Listening\""); + fs::write(root.path().join("secondary.toml"), switched).unwrap(); + let mut server = LocalServer::pulse( + root.path().join("control.sock"), + Gain::UNITY, + ProfileDocument::parse(source).unwrap(), + active_path, + ) + .unwrap(); + + let response = direct_request( + &mut server, + RequestCommand::SwitchProfile { + id: "broken".into(), + }, + ); + assert!(matches!(response.result, ResponseResult::Error { .. })); + assert_eq!(server.mixer.snapshot().configuration.profile_id, "desktop"); + let response = direct_request( + &mut server, + RequestCommand::SwitchProfile { + id: "native".into(), + }, + ); + assert!(matches!(response.result, ResponseResult::Error { .. })); + assert_eq!(server.mixer.snapshot().configuration.profile_id, "desktop"); + let old_revision = server.mixer.snapshot().revision; + + let response = direct_request( + &mut server, + RequestCommand::SwitchProfile { + id: "secondary".into(), + }, + ); + let ResponseResult::Snapshot { snapshot } = response.result else { + panic!("valid candidate should activate"); + }; + assert_eq!(snapshot.configuration.profile_id, "secondary"); + assert_eq!(snapshot.objects[0].label, "Listening"); + assert!(snapshot.revision > old_revision); + } + + fn direct_request( + server: &mut LocalServer, + command: crate::ipc::RequestCommand, + ) -> ServerResponse { + let (mut client, mut server_stream) = UnixStream::pair().unwrap(); + write_frame( + &mut client, + &ClientRequest { + version: PROTOCOL_VERSION, + request_id: 77, + command, + }, + ) + .unwrap(); + server.serve_client(&mut server_stream).unwrap(); + read_frame(&mut client).unwrap() + } } diff --git a/fader_master/src/main.rs b/fader_master/src/main.rs index 9b524e3..17b4f6b 100644 --- a/fader_master/src/main.rs +++ b/fader_master/src/main.rs @@ -37,7 +37,9 @@ fn main() -> Result<()> { ), Command::Status { socket } => status(socket.as_deref()), Command::Devices => devices(), - command => bail!("{command:?} is not available until its later milestone"), + Command::Profile { + command: fader_master::cli::ProfileCommand::Switch { id, socket }, + } => switch_profile(&id, socket.as_deref()), } } @@ -157,6 +159,28 @@ fn status(socket_override: Option<&Path>) -> Result<()> { } } +fn switch_profile(id: &str, socket_override: Option<&Path>) -> Result<()> { + let socket = socket_override.map_or_else(default_socket_path, |path| Ok(path.to_owned()))?; + let response = client_request( + &socket, + &ClientRequest { + version: PROTOCOL_VERSION, + request_id: 1, + command: RequestCommand::SwitchProfile { id: id.to_owned() }, + }, + )?; + match response.result { + ResponseResult::Snapshot { snapshot } => { + println!( + "active profile={} status={}", + snapshot.configuration.profile_id, snapshot.status + ); + Ok(()) + } + ResponseResult::Error { message, .. } => bail!(message), + } +} + fn devices() -> Result<()> { let catalog = MidiInputCatalog::new("fader_master devices")?; let ports = catalog.ports()?; diff --git a/fader_master/tests/cli.rs b/fader_master/tests/cli.rs index 84243d7..c2660cb 100644 --- a/fader_master/tests/cli.rs +++ b/fader_master/tests/cli.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use clap::{CommandFactory, Parser}; -use fader_master::cli::{AudioArgument, Cli, Command, ThemeArgument}; +use fader_master::cli::{AudioArgument, Cli, Command, ProfileCommand, ThemeArgument}; #[test] fn every_planned_command_is_present_in_help() { @@ -71,3 +71,25 @@ fn tui_accepts_known_themes_and_rejects_unknown_names() { ); assert!(Cli::try_parse_from(["fader_master", "tui", "--theme", "hot-dog-stand"]).is_err()); } + +#[test] +fn profile_switch_accepts_an_id_and_socket_override() { + assert_eq!( + Cli::try_parse_from([ + "fader_master", + "profile", + "switch", + "gaming", + "--socket", + "/run/user/1000/fader_master/control.sock", + ]) + .unwrap() + .command, + Command::Profile { + command: ProfileCommand::Switch { + id: "gaming".into(), + socket: Some("/run/user/1000/fader_master/control.sock".into()), + }, + } + ); +} diff --git a/task.md b/task.md index e3f3b6f..d7a0d15 100644 --- a/task.md +++ b/task.md @@ -356,7 +356,11 @@ Dependencies: M8, M2, M1. Dependencies: M9, M6, M7. -- [ ] **M10.1 Prepare/activate:** validate/probe candidate, pause/drain old writes, obtain new snapshot and atomically publish generation/mappings. Tests: invalid profile/unavailable manual adapter keeps old profile; late commands/events do not reach new targets; un-drainable native operations force reconciliation before activation. +- [x] **M10.1 Prepare/activate:** validate/probe candidate, pause/drain old writes, obtain new snapshot and atomically publish generation/mappings. Tests: invalid profile/unavailable manual adapter keeps old profile; late commands/events do not reach new targets; un-drainable native operations force reconciliation before activation. + `profile switch ID` now prepares a sibling profile, rejects invalid/native-only + candidates and runtime timing changes, waits for pending audio reconciliation, + then publishes matching, groups, faders, pickup, and MIDI together. Activation + advances the mixer view revision so pre-switch client commands are stale. - [ ] **M10.2 Restore/adopt policy:** default switch adopts live state; explicit restore uses saved object intents and deterministic overlap ordering. Tests: no surprise startup/switch write, restore limits enforced, offline/new members follow configured policy, pickup/feedback resync happens on every surface. - [ ] **M10.3 Durable selection:** save active pointer after successful activation and reconcile state namespaces. Tests: disk failure marks active runtime selection unsaved, restart selects last durably saved profile, and corruption cannot silently activate an unintended profile.