Skip to content

desktop::safety: wait for the supervisor thread instead of a fixed sleep (fixes #50) - #51

Merged
blockmandev merged 1 commit into
mainfrom
fix/safety-flaky-timing
Oct 22, 2026
Merged

blockmandev merged 1 commit into
mainfrom
fix/safety-flaky-timing

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Fixes #50.

Problem: three Supervisor tests in src/desktop/safety.rs slept a fixed time and then read the switch once. When the beating thread went unscheduled longer than that window (macOS CI: silent_for: 136ms against a 120 ms deadline), they failed although the code was right.

Fix: each test now waits, for up to 10 s, for the state it proves:

  • the switch open at a moment past its first deadline;
  • Stopped once the subject dies;
  • Unsupervised once the supervisor is dropped.

A slow scheduler only delays them.

Checked:

  • Controls: with no heartbeat, both "keeps it open" tests fail; with a Drop that leaves the thread beating, the drop test fails with got Ok(()).
  • Under load: 15 runs of the module beside a full parallel cargo test --lib, 0 failures.
  • Gate: fmt and clippy clean.
  • Full suite locally: 2241 passed and 2 failed, neither in this file.
    • acp_agent::flow_tests::session_new_answers_before_a_slow_server_has_listed_its_tools: a timing test, passes when rerun on its own (3 of 3).
    • desktop::uia::tests::live::the_focused_window_can_be_walked: a live test that walks the focused window. On this machine that was a web page with a 1×1 visually-hidden element at y = −16079, which the test's bounds assertion rejects. Tracked separately.

…ce after a sleep (fixes #50)

Three Supervisor tests slept a fixed time and then read the switch once:
"still live" 60 ms into a 120 ms deadline, "open" 400 ms into a 150 ms
one, "stopped" 120 ms after the subject died. Each failed whenever the
beating thread went unscheduled for longer than its window, as it did on
macOS CI (silent_for 136 ms at safety.rs:513) while ~2200 tests ran in
parallel: the code under test was right, the tests read too early.

Each now waits, up to WAIT_FOR_THREAD (10 s), for the state it proves: the
switch open at a moment past its first deadline (only a beat after the
start explains that), Stopped once the subject dies, Unsupervised once the
supervisor is dropped. A stalled scheduler only delays them; a supervisor
that never beats, or a drop that leaves it beating, still fails them --
both checked by breaking the code (no heartbeat; Drop not stopping the
thread). 15 runs of the module beside a full parallel test run: 0 failures.
@blockmandev
blockmandev merged commit 9fec014 into main Oct 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky on macOS CI: desktop::safety dropping_the_supervisor_lets_the_switch_trip_on_its_own

1 participant