Snapserver change applied but not recorded for undo when its RPC call times out or errors
The finding
In play, the revert for each planned change is appended to undo only after await self.rpc.call(*change) returns successfully. Snapcast JSON-RPC calls can time out (control_timeout) or lose the response after the server has already applied the change, for example switching a group's stream, unmuting a client, or raising volume. In that case the call raises before undo.append(revert) runs. The finally block then restores only the earlier changes, so this change stays on the snapserver permanently. The house audio is left on the announcement stream or at announcement volume. Every revert sets a setting back to its original value, so applying one for a change that never took effect is harmless.
311| def play_into_fifo(cfg: SnapcastConfig, data: bytes, duration: float, stop: threading.Event | None = None) -> float:
312| """Open the FIFO and write ``data`` (``duration`` seconds of audio) into it; when the first byte went in."""
313| fd = open_fifo(cfg.fifo, timeout=cfg.open_timeout, stop=stop)
314| try:
315| return write_fifo(fd, data, deadline=time.monotonic() + duration + WRITE_SLACK_S, stop=stop)
316| finally:
317| os.close(fd)
318|
319|
320| # --- the channel ---------------------------------------------------------------------------------------------
321|
322|
323| class SnapcastChannel:
324| """The ``snapcast`` voice channel kind."""
325|
326| kind = "snapcast"
327| config_model = SnapcastConfig
328|
329| def __init__(self, config: SnapcastConfig, *, fetcher: Fetcher | None = None) -> None:
330| require_numpy(EXTRA)
331| self.config = config
332| self.format = config.format
333| self.rpc = (
334| SnapcastRpc(config.control, timeout=config.control_timeout, fetcher=fetcher) if config.control else None
335| )The work pack
Recommendation. Record the revert before issuing the change (undo.append(revert) followed by await self.rpc.call(*change)). A failed or ambiguous change then still gets reverted in the finally block.
Acceptance criteria
- Address: Snapserver change applied but not recorded for undo when its RPC call times out or errors
- Keep the change scoped to the cited file/symbols unless impact requires otherwise
- Record the revert before issuing the change (
undo.append(revert)followed byawait self.rpc.call(*change)). A failed or ambiguous change then still gets reverted in thefinallyblock. - Re-check
src/argus_scout/channels/snapcast.pyafter the fix
Status
- claimed
- resolved
The fix
3499007409 fix: snapcast records each revert before its change, so a failed call is still undone.
@@ -358,8 +358,10 @@ class SnapcastChannel: if self.rpc is not None: status = await self.rpc.call("Server.GetStatus") for change, revert in plan(status, cfg):- await self.rpc.call(*change)+ # Recorded first: a call that times out or errors may still have been applied, and putting+ # back a setting that never changed is harmless. undo.append(revert)+ await self.rpc.call(*change) stop = threading.Event() try: started = await asyncio.to_thread(play_into_fifo, cfg, data, duration, stop)@@ -365,6 +365,16 @@ async def test_snapcast_restores_even_when_playback_fails(tmp_path): assert snap.calls[-1][1]["volume"] == {"muted": True, "percent": 30} +async def test_snapcast_reverts_a_setup_call_that_failed(tmp_path):+ # The snapserver may have applied a change whose reply was lost or an error: it is put back all the same.+ async with FakeSnapserver(fail={"Client.SetVolume"}) as snap:+ cfg = snap_cfg(tmp_path / "missing.fifo", control=f"tcp://127.0.0.1:{snap.port}", volume=70)+ with pytest.raises(ChannelError, match="Client.SetVolume"):+ await SnapcastChannel(cfg).play(speech(), message())+ assert [m for m, _ in snap.calls] == ["Server.GetStatus", "Client.SetVolume", "Client.SetVolume"]+ assert snap.calls[-1][1]["volume"] == {"muted": True, "percent": 30}++ async def test_snapcast_rpc_errors_and_timeouts_are_bounded(): async with FakeSnapserver(fail={"Server.GetStatus"}) as snap: with pytest.raises(ChannelError, match="Server.GetStatus.*nope"):How it was judged
Proven 1 test(s) fail on dev and pass with the fix: tests/test_voice_channels.py::test_snapcast_reverts_a_setup_call_that_failed
Judged 24 Nov 2026, 04:48 UTC against dev at d0c0f66.
| Test | on dev | dev + patch |
|---|---|---|
tests/test_voice_channels.py::test_snapcast_reverts_a_setup_call_that_failed | failed | passed |
The other 36 tests in the run (36 with the same result on both trees)
tests/test_voice_channels.py::test_a_missing_extra_fails_only_that_channel | passed | passed |
tests/test_voice_channels.py::test_encode_to_snapcast_sample_formats | passed | passed |
tests/test_voice_channels.py::test_mask_bearer_token_from_env_and_refusal_without_it | passed | passed |
tests/test_voice_channels.py::test_mask_external_sound_screen_counts_as_ready | passed | passed |
tests/test_voice_channels.py::test_mask_http_still_refuses_a_clone_whatever_the_attestation | passed | passed |
tests/test_voice_channels.py::test_mask_push_refused_for_a_vanished_screen_is_skipped_and_errors_fail | passed | passed |
tests/test_voice_channels.py::test_mask_ready_screen_gets_pcm_with_the_right_headers | passed | passed |
tests/test_voice_channels.py::test_mask_screen_not_ready_is_skipped_and_nothing_is_pushed | passed | passed |
tests/test_voice_channels.py::test_mask_skip_is_reported_by_the_dispatcher_and_not_recorded | passed | passed |
tests/test_voice_channels.py::test_mask_waits_for_a_screen_when_configured | passed | passed |
tests/test_voice_channels.py::test_mask_ws_busy_face_is_skipped_and_a_refusal_fails | passed | passed |
tests/test_voice_channels.py::test_mask_ws_caps_what_mask_may_send | passed | passed |
tests/test_voice_channels.py::test_mask_ws_cloned_voice_needs_the_consent_attestation | passed | passed |
tests/test_voice_channels.py::test_mask_ws_discloses_a_cloned_voice_and_not_a_synthetic_one | passed | passed |
tests/test_voice_channels.py::test_mask_ws_goes_only_to_the_configured_host | passed | passed |
tests/test_voice_channels.py::test_mask_ws_needs_websockets | passed | passed |
tests/test_voice_channels.py::test_mask_ws_not_ready_is_skipped_before_connecting | passed | passed |
tests/test_voice_channels.py::test_mask_ws_pcm_arrives_intact_in_capped_frames | passed | passed |
tests/test_voice_channels.py::test_mask_ws_timeouts_and_early_close_fail_promptly | passed | passed |
tests/test_voice_channels.py::test_mask_ws_url_follows_the_configured_scheme | passed | passed |
tests/test_voice_channels.py::test_plan_switches_unmutes_sets_volume_and_undoes_each | passed | passed |
tests/test_voice_channels.py::test_resampling_and_remixing | passed | passed |
tests/test_voice_channels.py::test_snapcast_config_is_validated_per_entry | passed | passed |
tests/test_voice_channels.py::test_snapcast_fifo_without_a_reader_fails_in_time_not_a_hang | passed | passed |
tests/test_voice_channels.py::test_snapcast_raw_pcm_input_at_the_stream_rate_passes_through | passed | passed |
tests/test_voice_channels.py::test_snapcast_reader_that_stops_reading_fails_in_time | passed | passed |
tests/test_voice_channels.py::test_snapcast_refuses_a_path_that_is_not_a_fifo | passed | passed |
tests/test_voice_channels.py::test_snapcast_restores_even_when_playback_fails | passed | passed |
tests/test_voice_channels.py::test_snapcast_rpc_errors_and_timeouts_are_bounded | passed | passed |
tests/test_voice_channels.py::test_snapcast_rpc_over_http_goes_to_the_configured_host_only | passed | passed |
tests/test_voice_channels.py::test_snapcast_sets_volume_and_stream_then_restores_them | passed | passed |
tests/test_voice_channels.py::test_snapcast_writes_converted_pcm_into_the_fifo | passed | passed |
tests/test_voice_channels.py::test_unsupported_formats_are_refused_clearly | passed | passed |
tests/test_voice_channels.py::test_wav_and_raw_pcm_decode_to_the_same_samples | passed | passed |
tests/test_voice_channels.py::test_wav_encodings_float_24_bit_and_8_bit | passed | passed |
tests/test_voice_channels.py::test_wav_helper_round_trip_through_stdlib_wave | passed | passed |