Repository navigation
fix(windows): apply settings while all initial devices are unavailable - #330
MrRussLuther wants to merge 3 commits into
Conversation
ReenigneArcher
left a comment
There was a problem hiding this comment.
The single-display KVM scenario now passes in the Windows UCRT64 mocks. Please limit the fallback to settings changes within the active topology while recovery is pending. The guard below passed all 287 mocked and undock tests, including the new clone-group regression.
Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh
| // and hope that we are still "safe" to make further changes (to be determined by computeNewTopologyAndMetadata call below). | ||
| const auto stripped_initial_state {win_utils::stripInitialState(new_state.m_initial, devices)}; | ||
| // The new topology is based on the initial state, which is the current topology if the cached one is of no use. | ||
| const auto stripped_initial_state {computeBaseInitialState(new_state.m_initial, cached_state.has_value(), topology_before_changes, devices)}; |
There was a problem hiding this comment.
Preserve the interim display layout while recovery is pending. With every original device absent and no built-in panel, EnsureOnlyDisplay can now split a temporary clone group. The saved m_initial still describes the absent layout, so the failed revert falls back to extending every enumerated display. I reproduced this with [["stream","clone"]] and one inactive output. Apply succeeded, then disconnect left [["stream"],["clone"],["inactive"]] with the original recovery still pending.
Add this at the start of if (change_is_needed) in prepareTopology(), before reverting previous settings or switching topology.
if (cached_state && isTopologyUnavailable(new_state.m_initial.m_topology, devices)) {
DD_LOG(error) << "Cannot switch display topology while all original devices are unavailable!";
return std::nullopt;
}In tests/unit/windows/test_settings_manager_undock.cpp, use the layout above to check that applying EnsureOnlyDisplay to stream leaves the clone group intact and recovery pending. The existing single-display regression verifies that the same request still applies the requested mode when the active topology already matches.
Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh
There was a problem hiding this comment.
Makes sense. The interim layout isn't recorded anywhere, so there's nothing to put it back from. Done in 8351756: a topology change is refused while all the original devices are away, and mode/HDR changes within the active topology still go through.
I put the check in a small helper (isTopologyChangeBlocked) and call it just before if (change_is_needed) instead of inside it. Inline, it adds 3 to prepareTopology() (a nested if plus the &&), which takes it from 24 to 27, over Sonar's cognitive complexity limit of 25. As a top-level call it adds 1.
Added UndockRecovery.TopologyIsNotSwitchedWhileRecoveryIsPending with your layout. It fails on the previous commit (apply returns Ok and leaves [["stream"]]) and passes now. 287 mocked and undock tests pass here.
One thing I noticed while testing: with the guard the apply is refused and the clone group survives, but a revertSettings() afterwards still ends at [["stream"],["clone"],["inactive"]]. The topology guard in revertSettings() extends every enumerated display whenever the revert fails, and Sunshine (2026.914 at least) calls revert on disconnect even after a failed apply. This PR doesn't touch that path, so I left it alone, but I can look at it in the follow-up if you want.
There was a problem hiding this comment.
Thanks, Russ. I checked the rebased head (013e7f0): the apply guard and clone-group regression address the apply-side finding, and mode/HDR changes can still proceed when the topology already matches.
Yes, please take the disconnect behavior in a separate follow-up. revertSettings() can still use a fully extended topology when recovery fails, even if apply left the layout alone. A regression test could start with the original monitors absent, an active [["stream", "clone"]] group, and a third inactive output. After a refused apply and a call to revertSettings(), assert that the clone group stays intact, the third output stays inactive, and the saved recovery stays pending. Then reconnect the originals and check that the original layout is restored. Please compare the clone groups explicitly, not just the set of active IDs.
I checked the source, not a live Windows setup. This follow-up doesn’t require changing whether Sunshine saves temporary layouts in #5942.
Review completed by Codex | Model: unavailable | Thinking: unavailable
There was a problem hiding this comment.
Thanks for checking the rebased head. I'll leave the revertSettings() disconnect behavior out of this PR. It comes from the same cause as #5942, a saved record that disagrees with the displays that are connected, so I'd rather fix it there than patch the revert path on its own. I'll use your scenario as the regression test: the originals absent, an active [["stream", "clone"]] group with a third output inactive, a refused apply, then revertSettings(). It will compare the clone groups explicitly and check that the originals' layout comes back when they return.
A persisted state whose initial devices are all gone (e.g. displays behind a KVM switch after an unclean shutdown) made every applySettings() call fail until the persistence was reset by hand. Use the current topology as the base in that case. The cached initial state is still persisted, so the original layout is restored once the devices return.
Keeps prepareTopology under the cognitive complexity limit (S3776).
The cached initial state still describes the absent layout, so the active topology could not be restored after changing it. Mode and HDR changes within the active topology are still applied.
8351756 to
013e7f0
Compare
|



Description
I hit this on a desktop whose monitors sit behind a KVM switch, streaming to a virtual display with
ensure_only_display. The PC was shut down while a stream was still up, so the revert never ran and the persisted state kept the two monitors as the initial topology. On the next boot the KVM was on another machine and only the virtual display was enumerated. The revert failed, which is expected, but every laterapplySettings()also failed with "Enumerated device list does not contain ANY of the devices from the initial state!" until I reset the persistence by hand. Streams still started, just at whatever mode the virtual display was left in.#298 keeps recovery pending when there's no original display or panel to fall back to. This doesn't change that. It only changes apply: when none of the cached initial devices are available, the current topology is used as the base for the new one. A request that would need a topology change is still refused in that state, because the interim layout couldn't be restored afterwards. The cached initial state is still what gets persisted, so the original layout comes back once those displays return.
This is separate from SunshineStream/Sunshine#5942. That one is about the session layout not sticking when changes aren't saved to the Windows database. This one also happens on v2026.914.233613, which is where I hit it, and a pending revert shouldn't block a new session whichever way #5942 is resolved.
The two do share a cause: the persisted record and Windows' saved layout can disagree once the set of connected displays changes. If saving to the database comes back, I'd like to follow up with a PR that keeps a topology-only record pending until the original displays return (
keepUnavailableSettings()drops it today). That should cover the redock case SunshineStream/Sunshine#5625 was after withoutsave_to_database = false. I'm happy to wait for a direction on #5942 before starting on it.Screenshot
Issues Fixed or Closed
Roadmap Issues
Testing
PrepareTopology, InitialDevicesUnavailable(plus its failure branch) andUndockRecovery.StreamCanBeConfiguredWhileRecoveryIsPending, which runs apply, a revert with the display still away, then a revert after it returns.UndockRecovery.TopologyIsNotSwitchedWhileRecoveryIsPendingafter review:EnsureOnlyDisplayon one member of an active clone group is refused while the original displays are away.test_libdisplaydevice.exe --gtest_filter='*Mocked*:UndockRecovery.*'on a Windows x86_64 build cross-compiled from Linux (clang, not UCRT64): 287 tests pass.SettingsManager. Master returnsDevicePrepFailed. This branch returnsOkand switches the virtual display from 3180x2384 to the requested 1920x1080. A revert with the monitors still away puts 3180x2384 back and stays pending, with the original initial topology left in the state file. After switching the KVM back, the next revert returnsOk: both monitors are active again, the virtual display is off and the state file is cleared.Harness output (trimmed, mode JSON shortened to one line)
master (b40ce11):
this branch:
this branch, after the monitors returned:
Type of Change
Checklist
AI Usage
See our AI usage policy.
AI assistance was used to trace the failure through the logs and code, and to draft the patch and tests.