Auditor recorded output

← All 27 packs

Proven

Snapserver change applied but not recorded for undo when its RPC call times out or errors

buglow src/argus_scout/channels/snapcast.py:323

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 by await self.rpc.call(*change)). A failed or ambiguous change then still gets reverted in the finally block.
  • Re-check src/argus_scout/channels/snapcast.py after the fix

Status

  1. claimed
  2. resolved

The fix

3499007409 fix: snapcast records each revert before its change, so a failed call is still undone.

diff --git a/src/argus_scout/channels/snapcast.py b/src/argus_scout/channels/snapcast.pyindex 7bbf07f..96fc5a6 100644--- a/src/argus_scout/channels/snapcast.py+++ b/src/argus_scout/channels/snapcast.py@@ -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)diff --git a/tests/test_voice_channels.py b/tests/test_voice_channels.pyindex 65e00ce..5ee6862 100644--- a/tests/test_voice_channels.py+++ b/tests/test_voice_channels.py@@ -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.

Teston devdev + patch
tests/test_voice_channels.py::test_snapcast_reverts_a_setup_call_that_failedfailedpassed
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_channelpassedpassed
tests/test_voice_channels.py::test_encode_to_snapcast_sample_formatspassedpassed
tests/test_voice_channels.py::test_mask_bearer_token_from_env_and_refusal_without_itpassedpassed
tests/test_voice_channels.py::test_mask_external_sound_screen_counts_as_readypassedpassed
tests/test_voice_channels.py::test_mask_http_still_refuses_a_clone_whatever_the_attestationpassedpassed
tests/test_voice_channels.py::test_mask_push_refused_for_a_vanished_screen_is_skipped_and_errors_failpassedpassed
tests/test_voice_channels.py::test_mask_ready_screen_gets_pcm_with_the_right_headerspassedpassed
tests/test_voice_channels.py::test_mask_screen_not_ready_is_skipped_and_nothing_is_pushedpassedpassed
tests/test_voice_channels.py::test_mask_skip_is_reported_by_the_dispatcher_and_not_recordedpassedpassed
tests/test_voice_channels.py::test_mask_waits_for_a_screen_when_configuredpassedpassed
tests/test_voice_channels.py::test_mask_ws_busy_face_is_skipped_and_a_refusal_failspassedpassed
tests/test_voice_channels.py::test_mask_ws_caps_what_mask_may_sendpassedpassed
tests/test_voice_channels.py::test_mask_ws_cloned_voice_needs_the_consent_attestationpassedpassed
tests/test_voice_channels.py::test_mask_ws_discloses_a_cloned_voice_and_not_a_synthetic_onepassedpassed
tests/test_voice_channels.py::test_mask_ws_goes_only_to_the_configured_hostpassedpassed
tests/test_voice_channels.py::test_mask_ws_needs_websocketspassedpassed
tests/test_voice_channels.py::test_mask_ws_not_ready_is_skipped_before_connectingpassedpassed
tests/test_voice_channels.py::test_mask_ws_pcm_arrives_intact_in_capped_framespassedpassed
tests/test_voice_channels.py::test_mask_ws_timeouts_and_early_close_fail_promptlypassedpassed
tests/test_voice_channels.py::test_mask_ws_url_follows_the_configured_schemepassedpassed
tests/test_voice_channels.py::test_plan_switches_unmutes_sets_volume_and_undoes_eachpassedpassed
tests/test_voice_channels.py::test_resampling_and_remixingpassedpassed
tests/test_voice_channels.py::test_snapcast_config_is_validated_per_entrypassedpassed
tests/test_voice_channels.py::test_snapcast_fifo_without_a_reader_fails_in_time_not_a_hangpassedpassed
tests/test_voice_channels.py::test_snapcast_raw_pcm_input_at_the_stream_rate_passes_throughpassedpassed
tests/test_voice_channels.py::test_snapcast_reader_that_stops_reading_fails_in_timepassedpassed
tests/test_voice_channels.py::test_snapcast_refuses_a_path_that_is_not_a_fifopassedpassed
tests/test_voice_channels.py::test_snapcast_restores_even_when_playback_failspassedpassed
tests/test_voice_channels.py::test_snapcast_rpc_errors_and_timeouts_are_boundedpassedpassed
tests/test_voice_channels.py::test_snapcast_rpc_over_http_goes_to_the_configured_host_onlypassedpassed
tests/test_voice_channels.py::test_snapcast_sets_volume_and_stream_then_restores_thempassedpassed
tests/test_voice_channels.py::test_snapcast_writes_converted_pcm_into_the_fifopassedpassed
tests/test_voice_channels.py::test_unsupported_formats_are_refused_clearlypassedpassed
tests/test_voice_channels.py::test_wav_and_raw_pcm_decode_to_the_same_samplespassedpassed
tests/test_voice_channels.py::test_wav_encodings_float_24_bit_and_8_bitpassedpassed
tests/test_voice_channels.py::test_wav_helper_round_trip_through_stdlib_wavepassedpassed