Make the state wipe after battery event configurable - #54
Open
lipusal wants to merge 2 commits into
Open
Conversation
When wolnut starts and finds `ups_on_battery` set in the state file, it logs "resuming from a UPS battery event" and immediately calls `ClientStateTracker.reset()`, which clears `was_online_before_battery` for every client. The restoration branch then skips every client with "was not online before power loss", so no WOL packet is ever sent. That only matters when wolnut's own host was shut down by the outage -- exactly the case where the state file is the only surviving record of who was online. When wolnut stays up through the outage the in-memory path is used and the wipe is harmless, which is why this has gone unnoticed. Make the wipe configurable via a new top-level `reset_state_on_resume` boolean. It defaults to `true`, which is byte-for-byte the current behaviour, so upgrading without touching the config changes nothing. When set to `false`, the loaded state is kept and `on_battery` is set instead: the main loop then takes the normal power restoration branch on the first "OL" reading with `was_online_before_battery` intact, and does not re-snapshot an offline fleet if the UPS is still reporting "OB". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTXBZgVFTjfbQd1Npk8Sgf
Add the new top-level option to the configuration guide and the example config, including when you would want to turn it off. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTXBZgVFTjfbQd1Npk8Sgf
Author
|
Alright, Claude clearly went ham with this PR description, let me simplify it |
reset_state_on_resume)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In its current state, after the host running wolnut goes down from a drained battery, on restart it will wipe its state file of hosts that were online before the outage. So in a situation like this, wolnut won't send WoL packets to hosts, i.e. nothing will be brought back online.
Other forks change this behavior, and #47 removes it altogether. This PR does similar changes, the main difference being that it makes this behavior configurable - by default, it will behave as it does now (i.e. state is wiped after a reset), but it can be changed to persist the state file. Happy to discuss with @JcMinarro where we want to go between the 2 PRs.
The change
A new top-level boolean config option,
reset_state_on_resume:true(default) — unchanged behavior.false— the loaded state is preserved andon_battery = Trueis set instead. The main loop then takes the normal power restoration branch on the firstOLreading, withwas_online_before_batteryintact, and wakes the clients that were actually up before the outage. If the UPS is still reportingOBat boot, wolnut simply waits for power to come back.Added tests, and all 53 tests pass.
Disclaimer: 🤖 Generated with Claude Code