fix: validate mixer revisions only for external requests
Rust CI fader_master passed its selected CI mode.
MadGobblins/fader_master/pipeline/head This commit looks good Details

M9.3: Save advances the public revision offset, but MIDI passed the reducer revision into public validation. Subsequent volume/mute input failed deterministically and escaped the server loop. Move validation to the IPC request boundary; preserve stale-client rejection and execute server-owned MIDI against current state.

Regression reproduced StaleRevision { actual: 1, current: 2 } before the fix; repeated reconfiguration with MIDI volume/mute and correlated readbacks now passes. cargo test -p fader_master --lib live::reconfigure_tests: 4 passed. Full workspace all-target/all-feature tests with --no-fail-fast: all targets exercised, four fixture failures from the pre-existing edited arch-pipewire profile (schema ID and three MIDI routing/device assertions); all 12 live mixer and 47 TUI tests pass. cargo fmt --all -- --check, cargo check --workspace --all-targets --all-features, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace --doc --all-features, and cargo build --workspace --release --all-features all pass.
This commit is contained in:
Dandaedre 2026-10-18 13:16:33 +02:00
parent af3b460375
commit 4d17d98809
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 103 additions and 13 deletions

View File

@ -349,6 +349,14 @@ TOML; creation edits materialize them lazily and removal from an omitted empty
array is a no-op. A present malformed section is rejected during startup.
The live mixer revision and configuration-draft revision are independent.
The public mixer revision also includes a routing-generation offset advanced
on Save/reset/profile switch, while the audio reducer keeps its own revision.
Validate public revisions only at the external client request boundary. MIDI
intents run synchronously under the server's state owner against current routing
and must not pass reducer revisions to that check. Mixing these revisions made
every MIDI volume/mute action fail after reconfiguration, propagating a stale
revision error out of the server loop. Genuine stale client requests still
resnapshot and retry; they must not bypass the public revision check.
Draft edits are serialized by the server, require the caller's expected draft
revision, and never mutate live routing or audio as a side effect. Successful
draft edits are explicitly marked unsaved until a later Save command. A layout

View File

@ -711,12 +711,7 @@ impl LiveMixerState {
} else {
gain
};
let commands = match self.set_volume(
configured.target.clone(),
target,
self.reducer.revision().get(),
sequence,
) {
let commands = match self.set_volume(configured.target.clone(), target, sequence) {
Ok(commands) => commands,
Err(
LiveMixerError::OfflineObject { .. }
@ -735,7 +730,7 @@ impl LiveMixerState {
.get(&fader)
.cloned()
.ok_or(LiveMixerError::UnknownFader(fader))?;
match self.toggle_mute(configured.target, self.reducer.revision().get(), sequence) {
match self.toggle_mute(configured.target, sequence) {
Ok(commands) => Ok(commands),
Err(
LiveMixerError::OfflineObject { .. }
@ -843,11 +838,17 @@ impl LiveMixerState {
object,
gain,
expected_revision,
} => self.set_volume(object, Gain::new(gain)?, expected_revision, request_id)?,
} => {
self.check_revision(expected_revision)?;
self.set_volume(object, Gain::new(gain)?, request_id)?
}
RequestCommand::ToggleMute {
object,
expected_revision,
} => self.toggle_mute(object, expected_revision, request_id)?,
} => {
self.check_revision(expected_revision)?;
self.toggle_mute(object, request_id)?
}
};
Ok((
ServerResponse {
@ -980,6 +981,9 @@ impl LiveMixerState {
}
fn check_revision(&self, expected: u64) -> Result<(), LiveMixerError> {
// Only external clients carry a public view revision. Server-owned MIDI
// intents execute against current state; reducer revisions exclude the
// offset added when profile routing is reconfigured.
let current = self.view_revision();
if current == expected {
Ok(())
@ -1020,10 +1024,8 @@ impl LiveMixerState {
&mut self,
object: MixerObjectKey,
target: Gain,
expected_revision: u64,
request: u64,
) -> Result<Vec<AdapterCommand>, LiveMixerError> {
self.check_revision(expected_revision)?;
let handles = self.writable_handles(&object)?;
let observed: BTreeMap<_, ChannelGains> = handles
.iter()
@ -1053,10 +1055,8 @@ impl LiveMixerState {
fn toggle_mute(
&mut self,
object: MixerObjectKey,
expected_revision: u64,
request: u64,
) -> Result<Vec<AdapterCommand>, LiveMixerError> {
self.check_revision(expected_revision)?;
let handles = self.writable_handles(&object)?;
let should_mute = handles.iter().any(|handle| {
self.reducer
@ -1089,6 +1089,84 @@ impl LiveMixerState {
mod reconfigure_tests {
use super::*;
#[test]
fn midi_controls_survive_repeated_reconfiguration() {
let source = include_str!("../../examples/profiles/desktop.toml");
let mut state =
LiveMixerState::new(Gain::UNITY, "pulse", &Profile::parse(source).unwrap()).unwrap();
let stream = StreamHandle::new(fader_core::BackendEpoch::new(1), 7, 1);
state
.worker_event(WorkerEvent::StreamMetadata {
stream,
metadata: StreamMetadata::new().with_application_name("Music Player"),
volume_writable: true,
})
.unwrap();
state
.worker_event(WorkerEvent::Adapter(AdapterEvent::Observed {
stream,
channels: ChannelGains::new(vec![Gain::new(0.4).unwrap()]).unwrap(),
muted: Mute::Unmuted,
operation: None,
}))
.unwrap();
let mut observed_mute = Mute::Unmuted;
for iteration in 0..3 {
let edited = source.replace(
"label = \"Music\"",
&format!("label = \"Music {iteration}\""),
);
state
.reconfigure(&Profile::parse(&edited).unwrap(), Gain::UNITY)
.unwrap();
let surface = SurfaceId::new("desk-left").unwrap();
let fader = FaderId::new("media-fader").unwrap();
let commands = state
.midi_intent(
MidiIntent::AbsoluteVolume {
surface: surface.clone(),
fader: fader.clone(),
gain: Gain::new(0.4).unwrap(),
},
iteration * 2,
)
.unwrap();
let [AdapterCommand::SetVolume { operation, .. }] = commands.as_slice() else {
panic!("MIDI volume must dispatch after reconfiguration: {commands:?}");
};
state
.worker_event(WorkerEvent::Adapter(AdapterEvent::Observed {
stream,
channels: ChannelGains::new(vec![Gain::new(0.4).unwrap()]).unwrap(),
muted: observed_mute,
operation: Some(*operation),
}))
.unwrap();
let commands = state
.midi_intent(MidiIntent::ToggleMute { surface, fader }, iteration * 2 + 1)
.unwrap();
let [
AdapterCommand::SetMute {
operation, muted, ..
},
] = commands.as_slice()
else {
panic!("MIDI mute must dispatch after reconfiguration: {commands:?}");
};
assert_ne!(*muted, observed_mute);
observed_mute = *muted;
state
.worker_event(WorkerEvent::Adapter(AdapterEvent::Observed {
stream,
channels: ChannelGains::new(vec![Gain::new(0.4).unwrap()]).unwrap(),
muted: observed_mute,
operation: Some(*operation),
}))
.unwrap();
}
}
#[test]
fn configuration_snapshot_exposes_profile_backed_editor_values() {
let profile = Profile::parse(include_str!("../../examples/profiles/desktop.toml")).unwrap();

View File

@ -390,6 +390,10 @@ Dependencies: M8, M2, M1.
failure leaves the previous disk and live configuration usable.
Save commits the latest server-owned validated draft when the requesting view
is behind; it does not reject already accepted shared edits as stale.
Fixed MIDI volume/mute failures after Save: public revision validation now
belongs to external client requests, not server-owned MIDI actions. A
regression exercises both controls and correlated readbacks after repeated
routing reconfiguration; stale external clients remain rejected.
- [x] **M9.4 Mixer-first layout:** persist ordered logical-fader and separator
entries, synthesize declaration-order entries for old profiles, and retain
hidden faders in place. The main mixer can reorder either entry type, add/edit/