Keep-awake: retry a refused inhibition; follow the latest demand (#913) #920

Closed
charles wants to merge 0 commits from fix-913-keep-awake-retry into textchat
Owner

Refs #913

Fixes the Linux CI failure of a_refused_inhibitor_does_not_stop_the_share after #915 was merged (run 392). It was also a real product defect.

Cause

keep_awake_rt only sees the published snapshots now and then, and it reduced them to one bool. In the test, the share was refused, then stopped, then started again. If all of that passed between two looks, the follower never saw the display as free and sent nothing. Because the first attempt had been refused and nothing was held, nothing asked again, so the display was left unprotected for the rest of the share. The same gap would leave a user unprotected if the portal was not up yet when the share started.

Reproduced before the fix by running the whole keep_awake_runtime binary in a loop, six niced copies in parallel (no synthetic load): 2 failures in 60 runs, both timed out waiting for: the next share keeps the display awake (acquired 0, released 0, wanted 1, 0).

Rule and fix

  • The demand carries detail now. New in fluxer-core: selectors::keep_awake_demand(&voice) -> KeepAwakeDemand { reasons, share: Option<ShareStage>, watched }. It includes the share's stage (each start has its own timer id, and a live share has its publication id) and the watched streams. A new start, a new publication, another watched stream or another reason therefore all count as a new demand, even if the display never showed as free in between.
  • Retry on a new demand. In keep_awake_rt, each change of the demand gets a new generation number. If the display is wanted and nothing is held, a new generation asks the system again at once.
  • Retry on a timer. If a request was refused and the demand has not changed, it is asked again after 5 s, 15 s, then every 60 s while the display is still wanted (RETRY_AFTER). A portal that comes up after the client at login is therefore picked up.
  • Only the latest state counts. The holder thread always acts on the newest wish and ignores the steps in between, so a missed release or a hold that outlives the demand is not possible. A free display releases what is held and forgets past refusals. A held inhibition is kept across any change of reasons.
  • Testable without waiting. The holder's state machine (Hold::settle) takes the time as an argument, so its unit tests don't sleep.
  • Test hooks: Runtime::with_keep_awake_retry sets shorter waits for tests, and FakeKeepAwake::attempts counts every request, refused ones included.

Tests

  • Unit tests in keep_awake_rt:
    • refused, then a new demand with no free display in between: asked again at once. The same demand is not retried before its wait.
    • the waits are exactly 5, 15, 60, 60 s, and an inhibitor that comes up is taken at the next try.
    • a free display releases what is held, stops the retry timer and restarts the waits from 5 s.
    • with a real snapshot channel, bursts of snapshots seen in any grouping always end with what the last snapshot says, and at most one inhibition is ever held.
    • a refused share followed by a new one in a single snapshot step is retried, even with a one-hour retry wait.
    • Check: switching the new-demand rule back to the old behaviour makes two of these tests fail.
  • Core: a_new_start_is_a_new_demand.
  • Runtime tests: they now wait on the fake's state rather than on snapshot timing; the time limits only stop a hung test.
    • a_refused_inhibitor_does_not_stop_the_share_and_the_next_share_asks_again replaces the failing test. With a one-hour retry wait, only the new share can trigger the request.
    • a_refused_inhibitor_is_asked_again_while_the_share_goes_on covers the timer retry with nothing else changing.
  • Under load after the fix: six niced copies of the keep_awake_runtime binary in parallel, each running 50 times in a row: 300 passed, 0 failed.
  • Gate: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci, run under dbus-run-session with FLUXER_NO_DESKTOP_NOTIFICATIONS=1, ended with ==> xtask ci: all steps passed.

🤖 Generated with Claude Code

Refs #913 Fixes the Linux CI failure of `a_refused_inhibitor_does_not_stop_the_share` after #915 was merged (run 392). It was also a real product defect. ## Cause `keep_awake_rt` only sees the published snapshots now and then, and it reduced them to one bool. In the test, the share was refused, then stopped, then started again. If all of that passed between two looks, the follower never saw the display as free and sent nothing. Because the first attempt had been refused and nothing was held, nothing asked again, so the display was left unprotected for the rest of the share. The same gap would leave a user unprotected if the portal was not up yet when the share started. Reproduced before the fix by running the whole `keep_awake_runtime` binary in a loop, six niced copies in parallel (no synthetic load): **2 failures in 60 runs**, both `timed out waiting for: the next share keeps the display awake (acquired 0, released 0, wanted 1, 0)`. ## Rule and fix - **The demand carries detail now.** New in fluxer-core: `selectors::keep_awake_demand(&voice) -> KeepAwakeDemand { reasons, share: Option<ShareStage>, watched }`. It includes the share's stage (each start has its own timer id, and a live share has its publication id) and the watched streams. A new start, a new publication, another watched stream or another reason therefore all count as a new demand, even if the display never showed as free in between. - **Retry on a new demand.** In `keep_awake_rt`, each change of the demand gets a new generation number. If the display is wanted and nothing is held, a new generation asks the system again at once. - **Retry on a timer.** If a request was refused and the demand has not changed, it is asked again after 5 s, 15 s, then every 60 s while the display is still wanted (`RETRY_AFTER`). A portal that comes up after the client at login is therefore picked up. - **Only the latest state counts.** The holder thread always acts on the newest wish and ignores the steps in between, so a missed release or a hold that outlives the demand is not possible. A free display releases what is held and forgets past refusals. A held inhibition is kept across any change of reasons. - **Testable without waiting.** The holder's state machine (`Hold::settle`) takes the time as an argument, so its unit tests don't sleep. - **Test hooks:** `Runtime::with_keep_awake_retry` sets shorter waits for tests, and `FakeKeepAwake::attempts` counts every request, refused ones included. ## Tests - **Unit tests in `keep_awake_rt`:** - refused, then a new demand with no free display in between: asked again at once. The same demand is not retried before its wait. - the waits are exactly 5, 15, 60, 60 s, and an inhibitor that comes up is taken at the next try. - a free display releases what is held, stops the retry timer and restarts the waits from 5 s. - with a real snapshot channel, bursts of snapshots seen in any grouping always end with what the last snapshot says, and at most one inhibition is ever held. - a refused share followed by a new one in a single snapshot step is retried, even with a one-hour retry wait. - Check: switching the new-demand rule back to the old behaviour makes two of these tests fail. - **Core:** `a_new_start_is_a_new_demand`. - **Runtime tests:** they now wait on the fake's state rather than on snapshot timing; the time limits only stop a hung test. - `a_refused_inhibitor_does_not_stop_the_share_and_the_next_share_asks_again` replaces the failing test. With a one-hour retry wait, only the new share can trigger the request. - `a_refused_inhibitor_is_asked_again_while_the_share_goes_on` covers the timer retry with nothing else changing. - **Under load after the fix:** six niced copies of the `keep_awake_runtime` binary in parallel, each running 50 times in a row: **300 passed, 0 failed**. - **Gate:** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci`, run under `dbus-run-session` with `FLUXER_NO_DESKTOP_NOTIFICATIONS=1`, ended with `==> xtask ci: all steps passed`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CI run 392 (Linux) failed a_refused_inhibitor_does_not_stop_the_share:
the runtime looks at the published snapshots now and then, so a share
stopped and started again could pass without the display ever showing as
free; the follower then never sent a change, and as the earlier attempt
had been refused, nothing asked again. Reproduced 2 times in 60 runs with
six niced copies of the test binary in parallel.

- fluxer-core: selectors::keep_awake_demand, the reasons with the share's
  stage (a new start, a new publication) and the watched streams.
- keep_awake_rt: every change of the demand is a new generation; a refused
  inhibition is asked for again at once for a new generation and otherwise
  after 5 s, 15 s, then every 60 s while still wanted. The holder acts on
  the latest wish only, so a release cannot be missed nor a hold outlive
  the demand. The state machine takes the time as an argument and is unit
  tested without waiting.
- Runtime::with_keep_awake_retry for tests; FakeKeepAwake::attempts.
- The runtime tests wait on the fake's state, not on snapshot timing.

Refs #913

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Merged into textchat by hand (the merge API returns 405); the commits are in the branch.

Merged into `textchat` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-18 23:07:28 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.