Repository navigation
M5 (1/3): start at logon as a scheduled task, keep the computer awake - #10
Merged
Merged
Conversation
…r awake (M5) `botloftd service install|status|restart|uninstall` registers a per-user scheduled task through the Task Scheduler COM API (schtasks output is localized). A logon trigger starts the daemon at logon; a time trigger that repeats every minute with IgnoreNew brings it back after a crash. Tested on Windows 11 25H2: RestartOnFailure does not restart a process that exits with an error, and a logon trigger's repetition only begins at the next logon, so neither can be the watchdog. `service install` copies the running binary to <home>\bin and the task runs that copy, so the app's installer can replace its own files while the daemon runs. A busy exe is renamed aside instead of overwritten. One task per data folder, so a dev BOTLOFT_HOME never replaces the real installation; `--home` overrides BOTLOFT_HOME for every subcommand. The daemon's manifest asks for long paths and no console (consoleAllocationPolicy), embedded as a resource because the linker's manifest tool warns about the new element. Older Windows gets FreeConsole. Fatal start-up errors now reach the log file, since nobody sees the task's stderr. Keep-awake holds a power request while any bot is busy. Unlike SetThreadExecutionState it belongs to a handle, not a thread, which fits Tokio's worker pool. The spec is updated to match.
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.
First slice of M5 (spec section 17): the daemon side of "bots come back on their own after a reboot".
What changes
botloftd service install | status | restart | uninstallmanages a per-user scheduled task through the Task Scheduler COM API (schtasks.exeoutput is localized, so it cannot be parsed).IgnoreNew, brings it back within a minute if it dies.installcopies the running binary to<home>\bin\botloftd.exeand the task runs that copy. This way the app's NSIS installer can replace its own sidecar while the daemon runs (next PR). A busy exe gets renamed aside instead of overwritten. If the same binary already runs from the task,installleaves it alone and the bots keep going.Botloft, orBotloft-<hash>for a devBOTLOFT_HOME). A new global--homeflag overridesBOTLOFT_HOME; the task passes it.longPathAwareandconsoleAllocationPolicy = detached, so a daemon started by the task gets no console window. It is embedded as a resource (embed-resource) because the linker's manifest tool warns about the new element. On Windows before 24H2,servecallsFreeConsolewhen it is the only process on its console.PowerCreateRequest/PowerSetRequest) is held while any bot isbusyandkeep_awake = true. The supervisor now tracks a busy count, and a new test covers turns, approvals and crashes.Tested on Windows 11 25H2 (recorded in spec 14)
RestartOnFailuredoes not restart a task whose process exits with an error code, neither after a time trigger nor after an on-demand run. I checked this with throwaway tasks, which are now deleted.install→ running with no console host attached;restart→ back in about 4 s; runninginstallagain → "already running", nothing restarted;uninstall→ task and binary gone, data kept;restartwithout a task → clear error.Manual test (needs a real logon)
botloftd service install(default data folder, or--homefor a scratch one).botloftd service statusshows the task running and the daemon answering; bots are back.powercfg /requestslistsbotloftd.exeunder SYSTEM with "Botloft bots are working", and the entry goes away when the turn ends.botloftd service uninstall.