Smart Power: never leave auto power-cycle off; restarts in maintenance aren't "needed" #69

Merged
jared merged 1 commits from smart-power-confirm into main 2026-11-26 22:54:05 -05:00
Owner

Bug: the Restart modem button left Smart Power off (2026-11-26)

What happened:

  • At 16:57 UTC the button asked UniFi to pause auto power-cycle on RPDU outlet 13 ("AT&T Modem").
  • UniFi accepted the request. Gandalf read the setting back immediately, it still showed the old value, and Gandalf logged Smart Power paused on 0 outlet(s).
  • UniFi then applied the change. Because Gandalf believed nothing was paused, it never turned it back on.
  • Outlet 13 still shows cycle_enabled: False, so Smart Power won't recover the modem if the internet drops.
  • The dashboard warning didn't fire either, because it only covers outlets Gandalf recorded as paused.

Fix:

  • Wait for confirmation: Gandalf waits up to 10 s (6 reads, 2 s apart) for UniFi to show the change before calling it a failure.
  • Always restore: every outlet Gandalf tried to pause is recorded as paused before the write. Whatever UniFi does afterwards, the restore runs when the modem is back, and the dashboard warning covers it if the restore fails. Turning on an outlet that is already on sends nothing, so this is always safe.

This doesn't fix the current state of outlet 13. That needs a one-time turn-on, which I've asked about in chat.

Restarts during planned maintenance aren't "needed"

Today's slowdown ticket (796656152) said "the modem has needed 3 restarts in the last 7 days". One of those was the planned rack UPS update on 11-25, which cut the modem's power on purpose.

  • A restart inside a Gandalf "silence everything" window is now shown as during planned maintenance (Gandalf silenced): "<reason>" and isn't counted.
  • Gandalf's own modem-restart silence is excluded, so the button's restarts stay the button's.
  • This uses the suppression history added in #68.

Replayed against prod's real data and Gandalf's real suppression history, read-only:

- 2026-11-24 04:03 UTC: Smart Power power-cycled it, next restart 23 h 27 min later
- 2026-11-25 03:30 UTC: during planned maintenance (Gandalf silenced): "switch update", next restart 1 d 13 h later
- 2026-11-26 16:57 UTC: Gandalf's Restart modem button, 10 h 52 min ago
The modem has needed 2 restarts in the last 7 days. ...

Before this change, the 11-25 line read "restarted outside Gandalf" and the advice said 3 restarts.

Verification

  • 707 tests pass. New tests replay a change UniFi only shows on a later read, an unconfirmed pause that still gets restored, the timeout message, maintenance windows (including skipping Gandalf's own restart silence), and the restart labels and advice.
  • flake8 is clean. No em or en dashes.

🤖 Generated with Claude Code

## Bug: the Restart modem button left Smart Power off (2026-11-26) **What happened:** - At 16:57 UTC the button asked UniFi to pause auto power-cycle on RPDU outlet 13 ("AT&T Modem"). - UniFi accepted the request. Gandalf read the setting back immediately, it still showed the old value, and Gandalf logged `Smart Power paused on 0 outlet(s)`. - UniFi then applied the change. Because Gandalf believed nothing was paused, it never turned it back on. - Outlet 13 still shows `cycle_enabled: False`, so Smart Power won't recover the modem if the internet drops. - The dashboard warning didn't fire either, because it only covers outlets Gandalf recorded as paused. **Fix:** - **Wait for confirmation:** Gandalf waits up to 10 s (6 reads, 2 s apart) for UniFi to show the change before calling it a failure. - **Always restore:** every outlet Gandalf *tried* to pause is recorded as paused before the write. Whatever UniFi does afterwards, the restore runs when the modem is back, and the dashboard warning covers it if the restore fails. Turning on an outlet that is already on sends nothing, so this is always safe. This doesn't fix the current state of outlet 13. That needs a one-time turn-on, which I've asked about in chat. ## Restarts during planned maintenance aren't "needed" Today's slowdown ticket (796656152) said "the modem has needed 3 restarts in the last 7 days". One of those was the planned rack UPS update on 11-25, which cut the modem's power on purpose. - A restart inside a Gandalf "silence everything" window is now shown as `during planned maintenance (Gandalf silenced): "<reason>"` and isn't counted. - Gandalf's own modem-restart silence is excluded, so the button's restarts stay the button's. - This uses the suppression history added in #68. Replayed against prod's real data and Gandalf's real suppression history, read-only: ``` - 2026-11-24 04:03 UTC: Smart Power power-cycled it, next restart 23 h 27 min later - 2026-11-25 03:30 UTC: during planned maintenance (Gandalf silenced): "switch update", next restart 1 d 13 h later - 2026-11-26 16:57 UTC: Gandalf's Restart modem button, 10 h 52 min ago The modem has needed 2 restarts in the last 7 days. ... ``` Before this change, the 11-25 line read "restarted outside Gandalf" and the advice said 3 restarts. ## Verification - 707 tests pass. New tests replay a change UniFi only shows on a later read, an unconfirmed pause that still gets restored, the timeout message, maintenance windows (including skipping Gandalf's own restart silence), and the restart labels and advice. - flake8 is clean. No em or en dashes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-26 22:51:01 -05:00
Smart Power: never leave auto power-cycle off; restarts in maintenance aren't "needed"
Lint / Python (flake8) (push) Successful in 1m11s
Lint / JS (eslint) (push) Successful in 14s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Lint / JS (eslint) (pull_request) Successful in 11s
Lint / Python (flake8) (pull_request) Successful in 1m8s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m9s
Test / Python Tests (pytest) (pull_request) Successful in 1m20s
Security / Python Security (bandit) (push) Successful in 1m2s
Test / Python Tests (pytest) (push) Successful in 1m23s
b8d45648ea
2026-11-26: the Restart modem button asked UniFi to pause auto power-cycle
on the modem's outlet. Read back at once, UniFi still showed the old
setting, so Gandalf recorded nothing paused; UniFi then applied the
change, and nothing turned it back on. Now Gandalf waits up to 10 s for
UniFi to show the change, and lists every outlet it tried to pause, so
the restore always runs (turning on an outlet that is on is a no-op).

A modem restart inside a Gandalf silence for everything (the planned
2026-11-25 UPS update cut the rack's power) is shown as planned
maintenance and no longer counts toward "the modem has needed N
restarts".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared scheduled this pull request to auto merge when all checks succeed 2026-11-26 22:54:01 -05:00
jared merged commit bf392a5114 into main 2026-11-26 22:54:05 -05:00
jared deleted branch smart-power-confirm 2026-11-26 22:54:11 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/gandalf#69