Skip to content

fix: keep workers disarmed at boot while autostart is off - #1534

Open
geodro wants to merge 2 commits into
mainfrom
fix/1531-autostart-worker-arming
Open

fix: keep workers disarmed at boot while autostart is off#1534
geodro wants to merge 2 commits into
mainfrom
fix/1531-autostart-worker-arming

Conversation

@geodro

@geodro geodro commented Aug 19, 2026

Copy link
Copy Markdown
Member

Enabling a worker armed its systemd unit for start at login regardless of the autostart switch. lerd autostart disable disabled every unit that was on disk at that moment, but anything written afterwards went straight back to being wanted by default.target: a worker enabled in the dashboard, or a unit rewritten by a later lerd start. So a machine with autostart off still tried to run that worker at every boot.

What the reporter saw follows from there. Horizon came up at login, BindsTo pulled the FPM container along with it, and nothing pulled up Redis, whose quadlet correctly has its [Install] section stripped while autostart is off. Horizon died on getaddrinfo for lerd-redis failed, Restart=always brought it back, and the loop ran for the whole session, filling the journal.

Arming a worker unit now goes through a single place that consults the autostart flag, and disarms the unit instead when the flag is off. Disarming also clears an arming an older build left behind, so an install that is already looping heals itself the next time that worker's unit is written, without the user having to know that toggling autostart off a second time would have fixed it. Nothing about starting changes: callers start the unit themselves, so a worker that should be running right now still runs.

On macOS launchctl enable is also what lifts the flag that blocks bootstrapping a label at all, so skipping it would stop a worker from starting now rather than only at the next login. A platform var keeps the autostart flag out of that path, and macOS behaviour is unchanged.

Two other places were reading "is the unit enabled" as "does the user want this worker", which stops being a fair proxy once a running worker can sit disarmed. The PHP image rebuild now snapshots which workers were up before it restarts FPM and brings exactly those back, instead of trusting an enable state that the restart had just invalidated, which also means it stops resurrecting workers the user had deliberately stopped. A node runtime switch now regenerates the unit of a worker that is merely running, not only of an armed one.

The four MCP tools that write their own worker units follow the same rule through a helper in the systemd package.

Refs #1531

Enabling a worker armed its systemd unit for login start no matter what the
autostart switch said. Turning autostart off disabled every unit on disk at that
moment, but anything written afterwards, a worker enabled in the dashboard, a
unit rewritten by lerd start, went back to being wanted by default.target. At
the next boot systemd started it, BindsTo pulled the FPM container up with it,
and nothing pulled up the databases and caches behind it, so the worker died on
a connection error and Restart=always looped it for as long as the session
lasted.

Arming a worker unit now goes through one place that consults the autostart flag
and disarms instead when it is off, which also clears an arming left behind by an
older build. The unit is still started by whoever asked for it, so a worker that
should be running now still runs. On macOS launchctl enable is also what lifts
the flag that blocks bootstrapping a label at all, so the gate stays out of that
path and the platform keeps its current behaviour.

Two places read "is the unit enabled" as "does the user want this worker", which
that flag no longer answers once a running worker can be disarmed. The PHP image
rebuild now snapshots which workers were up before it restarts FPM and brings
exactly those back, rather than trusting the enable state it had just invalidated.
A node runtime switch regenerates the unit of a worker that is merely running,
not only an armed one.
@geodro
geodro requested a review from a team as a code owner August 19, 2026 07:52
The arming guard now treats a running worker as installed, so it reaches for IsActive whenever IsEnabled comes back false. The double in the regeneration test only answered IsEnabled and embedded a nil manager for everything else, which left that second call landing on the nil interface and taking the process down with it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant