DankMaterialShell icon indicating copy to clipboard operation
DankMaterialShell copied to clipboard

gamma: scheduler stalls indefinitely with no suspend; only a real config change recovers it

Open wowo101 opened this issue 4 months ago • 2 comments

Version: dms-shell 1.5.2 (Arch/CachyOS pkg), quickshell 0.3.0, niri 26.04, Wayland. The affected files are byte-identical in v1.5.2 and v1.5.3.

Summary

The gamma scheduler stopped publishing state and stopped applying ramps for ~9 h across a dawn transition, on a machine that never suspended. Night mode stayed enabled and light/dark switching (theme.auto) kept working normally the whole time, so the only symptom was that the screen sat at the night temperature all morning.

Observed

$ date
Fri 31 Jul 07:54:33 BST 2026

$ dms ipc call night status
Night mode: enabled
Current temperature: 3200K
Target night temperature: 3200K
Target day temperature: 6500K
Automation: location
Period: night
Next transition: 2026-07-31T04:38:00+01:00    <- 3h15m in the past
Sunrise: 2026-07-30T05:39:41+01:00            <- previous day's
Sunset: 2026-07-30T20:33:26+01:00

Those are exactly the values updateStateFromSchedule() produces between the backend's start (22:47:50 the previous evening) and midnight: previous-day SunTimes, and tomorrowDawn() for the next transition. Nothing was published for ~9 h — roughly 110 missed ticks against maxScheduleWait = 5 * time.Minute.

theme.auto transitioned correctly at sunrise the same morning (05:41, session state rewritten, wallpaper swapped).

Ruled out

  • Suspend. CLOCK_BOOTTIME - CLOCK_MONOTONIC == 0.0s; no logind sleep events, no kernel PM events. Nothing froze a time.Timer.
  • Write path. Forcing a temperature change applied the new ramp instantly and visibly (a 3500 K step was obvious on the panel), so controlsInitialized, anyOutputReady(), the waylandActor goroutine and applyGamma were all healthy.
  • Dropped commands. Actor command queue full never logged. (Go WARN lines do reach the journal — 230 of them that boot.)
  • Apply failures. gamma: failed to set output never logged.
  • Location. Real sun times were computed, and getLocation() caches after first success, so no repeated lookups.

I could not pin the reason the timer branch issued no post for ~110 consecutive firings, and could not reproduce it on demand.

Recovery

Any request that changes a config value:

dms ipc call night setDayTemp 6000; dms ipc call night setDayTemp 6500

State and ramp both snap correct within a second, via schedulerLoop's updateTrigger branch, which recomputes and publishes inline.

Why it stays stuck

Every backend setter returns early when the value is unchanged (SetEnabled, SetTemperature, SetManualTimes, SetUseIPLocation, SetGamma), and updateTrigger is only armed by a change that actually lands. So every recovery path the shell itself takes is a no-op against a stalled-but-correctly-configured scheduler:

  • dms ipc call night enable while already enabled
  • a DMSService reconnect → checkGammaControlAvailability() → setEnabled(true) → startAutomation()
  • reopening the settings dialog

Suggested direction

schedulerLoop only arms timers; the sole unconditional publisher of State is the updateTrigger branch. Everything else goes through m.post(...) → applyCurrentTemp, which returns before updateStateFromSchedule() whenever !m.controlsInitialized || !m.anyOutputReady().

thememode.schedulerLoop recomputes and publishes inline on every iteration and did not stall. Publishing gamma state from the scheduler goroutine itself — independent of output readiness — would at minimum make the fault visible in night status rather than presenting a stale schedule as a live one, and would let a later tick re-drive a transition that was missed.

Separate bug, same file: write-then-validate leaves an invalid config

SetTemperature writes into m.config before validating and leaves the rejected pair in place on error:

m.config.LowTemp = low
m.config.HighTemp = high
err := m.config.Validate()
m.configMutex.Unlock()
if err != nil {
    return err
}

With a 3200 K night temperature, dms ipc call night setDayTemp 2500 leaves the manager holding LowTemp=3200, HighTemp=2500 — which fails LowTemp <= HighTemp — fires no update, logs nothing, and the CLI still prints Day temperature set to 2500K. SetLocation, SetManualTimes and SetGamma have the same write-then-validate shape.

wowo101 avatar Jul 31 '26 07:07 wowo101

Still present on dms-shell 1.5.3-1 (Arch/CachyOS), quickshell 0.3.1, niri 26.04. Measured 2026-08-24, 21:30–22:05 CEST.

Two things that go beyond the original report:

1. It reproduces from a cold start. The stall is not something that only develops over long uptime. The backend was fully restarted at 22:00 CEST (new PIDs for both dms and qs); 35 seconds later:

$ date
Mon 24 Aug 22:00:35 CEST 2026

$ dms ipc call night getSchedule
Mode: location
Period: night
Dawn:            2026-08-24T05:40:09+02:00
Sunrise:         2026-08-24T06:32:34+02:00
Sunset:          2026-08-24T19:43:00+02:00
Night:           2026-08-24T20:35:25+02:00
Next transition: 2026-08-24T05:40:09+02:00   <- 16h20m in the past

A freshly started process, at 22:00 and with Period: night, publishes the current day's dawn as the next transition instead of tomorrow's. The value is identical to what the previous instance (started 00:49 the same day) had been reporting for the preceding 21 hours, so both instances agree — which points at the schedule computation choosing the wrong day when now is past the night boundary, rather than at the publish loop going quiet.

2. The recovery documented in this issue no longer recovers.

$ dms ipc call night getSchedule | grep 'Next transition'
Next transition: 2026-08-24T05:40:09+02:00
$ dms ipc call night setDayTemp 6000; dms ipc call night setDayTemp 6500
$ dms ipc call night getSchedule | grep 'Next transition'
Next transition: 2026-08-24T05:40:09+02:00   <- unchanged

The write path is healthy while this is true: setTargetTemp 3000 moves the ramp and getCurrentTemp follows within a second, then back to 4500 on restore. So gamma application works; only the schedule stays stale.

3. A second, probably related symptom. With the schedule stale, night disable reports the flag change but the published temperature does not follow:

$ dms ipc call night disable
Night mode disabled
$ dms ipc call night status        # sampled once a second for 6 s
Night mode: disabled
Current temperature: 4500K         <- unchanged for the whole window

The panel does visibly return to neutral during those seconds (confirmed by eye), so the gamma is released correctly and it is the published state that is stale, not the ramp. Anything reading getCurrentTemp — the shell's own indicator included — shows the night temperature while the screen is neutral.

Happy to run further probes on this machine; it reproduces on every cold start here.

Mark2Mac avatar Aug 24 '26 20:08 Mark2Mac

It has been fixed on master but not in 1.5.3, will get cut into the next release either 1.5.4 or 1.6 whichever comes first

bbedward avatar Aug 24 '26 22:08 bbedward