Repository navigation
[ryoku] shell: night light schedule reconciles once on load and change - #928
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
🦊 mika's reviewIncremental review: new commits since the last checkpoint. Summary
Change diagramflowchart LR
Schedule["Load or set schedule"] --> Arm["Arm reconciliation"]
Arm --> Tick["Schedule tick"]
Tick --> Backend["Night Light backend"]
Tick --> Desire["Record last desire"]
Estimated review effort: 4/5 · risk: medium 📁 Walkthrough details
|
| if pending { | ||
| if want != n.running() { | ||
| var err error | ||
| if want { | ||
| err = n.intent("on") | ||
| } else { | ||
| err = n.intent("off") | ||
| } | ||
| if err != nil { | ||
| log.Printf("ryoku-shell: night light schedule tick failed: %v", err) | ||
| return // retry on the next tick: do not record an action that did not land | ||
| } | ||
| } | ||
| n.schedMu.Lock() | ||
| n.schedPending = false | ||
| n.schedLastDesire = want | ||
| n.schedMu.Unlock() |
There was a problem hiding this comment.
Boot restore can escape reconciliation. During a daytime clock window, the first tick can run before the separately started
ryoku-cmd-nightlight restore creates the light process. Here, want and n.running() are both false, so the tick clears schedPending without removing the saved enabled marker. The restore command can then turn the light on. With schedLastDesire already false, the schedule leaves it on until the next clock edge.
Order restore and the first schedule check, or otherwise ensure a restore that finishes later cannot escape that check. Add a boot test where the saved marker exists before the light process starts.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ryoku/shell/ipc/nightlight_schedule.go
Line: 283-299
Comment:
**Boot restore can escape reconciliation.** During a daytime clock window, the first tick can run before the separately started `ryoku-cmd-nightlight restore` creates the light process. Here, `want` and `n.running()` are both false, so the tick clears `schedPending` without removing the saved enabled marker. The restore command can then turn the light on. With `schedLastDesire` already false, the schedule leaves it on until the next clock edge.
Order restore and the first schedule check, or otherwise ensure a restore that finishes later cannot escape that check. Add a boot test where the saved marker exists before the light process starts.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.3bf55bd to
14cb985
Compare
|
All three findings addressed, and retargeted to unstable-dev.
Full |
Blocking findings were addressed (verified at 14cb985c87).
|
Follow-up hardening from the overlap review on #929: the armed reconciliation tick now re-reads the schedule mode under the lock before it acts, so a schedule disabled or switched while a tick was in flight is not applied by that stale tick. The newer mode gets its own kick, and an off leaves the light alone. The same theoretical mid-flight window exists in the pre-existing last-desire path; I left that untouched here to keep the change scoped, happy to harden it the same way if you want. Full ryoku-shell suite passes, gofmt and vet clean. |
neur0map
left a comment
There was a problem hiding this comment.
🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.
| n.schedMu.Lock() | ||
| moved := n.schedMode != mode | ||
| n.schedMu.Unlock() | ||
| if moved { | ||
| return | ||
| } | ||
| if want != n.running() { | ||
| var err error | ||
| if want { | ||
| err = n.intent("on") | ||
| } else { | ||
| err = n.intent("off") |
There was a problem hiding this comment.
🟠 major · Possible Bug · fix: medium effort
The mode check is released before the backend action, so a concurrent call can disable the schedule after the check and still have this tick change the light. Bounds-only changes are not checked at all, so an old window can also apply its stale desire before the new one is reconciled. Serialize schedule changes with the action or otherwise validate the complete schedule atomically with applying it.
Reply here to discuss, say it's fixed, or explain why it's intended — no mention needed.
4926d5a to
1d6667b
Compare
|
Both findings addressed, with one honest boundary stated. The stale-tick gap ( The boundary I will not paper over: a schedule that is disabled while the intent script is executing (the window between the last check and the script finishing, roughly a second) can still have that one toggle land. That window is not something my reconciliation introduced; the pre-existing last-desire path has had the identical window since the scheduler was written, and closing it means holding the schedule lock across a process spawn or building an undo path. If you want it closed properly, I would rather do that as its own change covering both paths than bolt a half-fix onto the armed pass here. Say the word and I will build it. The test gap ( Full ryoku-shell suite passes, gofmt and vet clean. |
|
I've reviewed 5 pushes on this PR automatically, so I'll stop doing full passes here and only check whether open threads get fixed. Add the |
723ba7d to
ef18cfd
Compare
|
Fixed the remaining scheduling race: schedule edits and backend actions are serialized, with regression and race tests for in-flight ticks, bounds edits, and manual toggles. New head |
|
@ryoku-mika review |
Sipper1236
left a comment
There was a problem hiding this comment.
Good fix, but every active schedule write increments schedArmed even when all values are unchanged; a no-op save can undo a manual toggle. Only arm it when the schedule changes.
ef18cfd to
e7b8c35
Compare
|
Addressed the live finding on Finding: every active Fix: Tests: added @ryoku-mika review |
Arm the one-shot backend reconciliation only when the active schedule really changes (mode, margin or clock bounds), so a no-op re-save after a manual toggle leaves the user's choice alone. Serialize ticks with schedule edits and re-read the arm under the lock so an in-flight tick cannot apply a stale desire. Regression tests cover a no-op save after a manual toggle, a real bounds edit, in-flight edits, and boot reconciliation. Note: Fixed: Night Light schedule changes cannot be overtaken by an in-flight tick Note: Fixed: A no-op Night Light schedule save no longer undoes a manual toggle
e7b8c35 to
2fa7cea
Compare
|
Head advanced to @ryoku-mika review |
|
@ryoku-mika review Fresh pass requested on head |
|
Re-audited current head
@ryoku-mika review Initial draft by me; final wording written with Hermes Agent. |
|
Thanks for the work here, merged with a small boot fix on my side and it goes out with the next update |
On hyperion the watcher is the night light's live publisher and each test's fake backend has its own name. The in-flight tick test now starts the watcher for its boot state, and both caps-gated tests report the fake backend buildNlFake made, so the watcher finds it.
Fixes #919.
The schedule tick compared its wanted state only against its own previous desire, so enabling Follow the Sun (or a clock window) during daylight left an already-running backend on until the next edge, and a light left on across a reboot survived the whole day with the schedule active.
This implements the one-shot reconciliation suggested in the issue:
schedPendingis set inloadSchedule()for a restored sun/clock schedule and insetSchedule()when the mode changes to one.tickSchedule()performs one comparison of the wanted state against the backend's real state (n.running()) while the flag is set, acts on the difference, then clears the flag and records the desire. The existing last-desire comparison resumes afterwards, so a manual toggle stays honoured until the next edge.Tests, driven through the real intent path with the existing
buildNlFakeharness:TestNightlightScheduleReconcilesRunningBackend: the light is on before the schedule exists; enabling a daylight window turns it off on the very next tick, and the following tick sends nothing (one-shot, no fighting).TestNightlightScheduleReconcilesAfterLoad: a light left on with a persisted daylight schedule is turned off by a fresh daemon on its first tick afterloadSchedule(), and a manual re-toggle before that still wins.Full
ryoku-shellmodule suite passes (go test ./...inryoku/shell/ipc, gofmt and vet clean). CHANGELOG entry added under Unreleased/Fixed.(Prepared with an AI agent as the AGENTS.md workflow invites; every behaviour here was verified against the real code and test suite on current main.)
The startup ordering issue still needs a fix before merging.
Fix with agent prompt
Summary
Night Light schedules now check the running light once after startup or a schedule edit, while leaving later manual choices alone.
Reviews (8) · Last reviewed commit: "[ryoku] shell: reconcile night light sch..." · Reviewed by Greptile