Repository navigation
Add the installer's OOM settings to host daemon units written before them - #8298
Merged
Merged
Conversation
…them install-machine.sh writes OOMPolicy=continue (get-bb#7039) and ManagedOOMPreference=avoid (get-bb#7823) into the host daemon's systemd unit, but only on a new install. A unit written before 2026-11-04 keeps systemd's default OOMPolicy=stop, so one OOM kill of an agent process stops the whole service and interrupts every thread on the machine. At startup, before a server move resumes, the daemon now adds each missing setting to the [Service] section of its own unit and runs systemctl daemon-reload. The update runs on the same queue as server-moved notices, so the two never write the unit at the same time. Settings that the unit already sets are kept, also when written with spaces around the equals sign. The installer tests and the daemon read the same list from @bb/host-daemon-contract, and the installer test fails if the unit gains a [Service] setting that is not in the list.
scowalt
pushed a commit
to scowalt/bb
that referenced
this pull request
Dec 1, 2026
…them (get-bb#8298) ## Human comments ## What was wrong `install-machine.sh` writes `OOMPolicy=continue` (get-bb#7039) and `ManagedOOMPreference=avoid` (get-bb#7823) into the host daemon's systemd unit. But only a new install writes the unit. A unit from before 2026-11-04 keeps the systemd default `OOMPolicy=stop`, so one kernel OOM kill of an agent process stops the whole service. Every thread on the machine stops with it. No part of bb updates a unit that exists, and `--auto-update` changes only the bb-app package. ## What changed ```diff host daemon startup (apps/host-daemon/src/app.ts) + serverMove.updateServiceDefinition() # add missing [Service] settings, daemon-reload serverMove.resumeActivation() # unchanged, now runs after the update ``` - **`packages/host-daemon-contract/src/server-move.ts`**: one list, `HOST_DAEMON_SYSTEMD_SERVICE_DIRECTIVES`, holds the two settings. The daemon and the installer tests both read it. - **`apps/host-daemon/src/server-move/service-definition.ts`**: `addMissingSystemdServiceDirectives(content)` adds each missing setting at the end of `[Service]`. A setting that the unit sets already stays as it is, also `OOMPolicy = stop` with spaces. `systemdDirective` now accepts spaces around `=`, as systemd does. - **`apps/host-daemon/src/server-move/service.ts`**: `updateServiceDefinition()` finds the daemon's own unit with the same lookup a server move uses (`BB_DATA_DIR` must match this data dir), writes the file, and runs `systemctl <scope> daemon-reload`. It does not restart the service. The update uses the same queue as server-moved notices, so the two never write the unit at the same time. A launchd plist and `BB_SERVER_MOVE_SERVICE_MANAGER=none` are not changed. - **`apps/host-daemon/src/server-move/service-manager.ts`**: `reloadSystemdService` comes out of `restartService`, which now calls it. - **`apps/server/test/app/install-machine-script.test.ts`**: the user and system unit tests compare the `[Service]` settings of the generated unit with the shared list, in both directions. A new setting in the installer that is not in the list fails the test. - No wire change, so `HOST_DAEMON_PROTOCOL_VERSION` does not change. Choice: the daemon updates the unit at startup. Precedent: the daemon already rewrites the same file on a server move (`switchToMovedServer`, `writeServiceDefinition`). The alternative is to tell users to rerun the installer, as get-bb#7823 does. That restarts the daemon and most users do not know they need it. A maintainer can ask for the other choice in a comment or push commits to this branch. ## How you verified | Check | Before (`main` a8c3228) | After | | --- | --- | --- | | `service-definition.test.ts`: 6 cases for `addMissingSystemdServiceDirectives` (old unit, partial, other section, spaces, CRLF, no `[Service]`) | fail: `addMissingSystemdServiceDirectives is not a function` | pass | | `service-update.test.ts`: old unit gets the settings and one `daemon-reload`, no restart, file mode kept; failed reload is logged; a server move during the update keeps both changes; unit settings are kept; `none` service manager is not touched | fail | pass | | Installer test with `MemoryHigh=90%` added only to `install-machine.sh` | - | fails as expected | Live check on systemd 262 (Arch Linux), with a scratch user unit `bb-host-daemon-oom-live-check.service` (`ExecStart=/usr/bin/sleep infinity`, no OOM settings) and the real `ServerMoveService`: ```text before: MainPID=3079403 OOMPolicy=stop ManagedOOMPreference=none info Added the current OOM settings to the bb service definition after: MainPID=3079403 OOMPolicy=continue ManagedOOMPreference=avoid ``` A second run changed nothing. The script removed the scratch unit. On the machine that found this, an old unit restarted the daemon on each of four OOM kills of agent processes in nine minutes. With the same two settings in a drop-in, five more OOM kills did not restart it. `pnpm exec turbo run typecheck test lint lint:type-aware --continue --filter=@bb/host-daemon --filter=@bb/host-daemon-contract --filter=@bb/server`: all typecheck and lint tasks pass with 0 warnings. `@bb/server` tests pass. Two tests fail locally and also fail on unchanged `main` on this machine: `payload-size.test.ts` (Node 26 gzip sizes) and `protocol-self-update.test.ts` (Arch keeps npm outside the Node directory). CI uses Node 22. An Opus review found no blocking defect. Its points are fixed here: the update now runs before `resumeActivation` and on the server-moved queue, a failed reload is logged as such, settings with spaces are kept, and the drift test checks both directions. Not covered by a test: the one `app.ts` line that starts the update. `resumeActivation` at the same place has no test either. Fixes get-bb#8297 > AGENT GENERATED
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.
Human comments
What was wrong
install-machine.shwritesOOMPolicy=continue(#7039) andManagedOOMPreference=avoid(#7823) into the host daemon's systemd unit. But only a new install writes the unit. A unit from before 2026-11-04 keeps the systemd defaultOOMPolicy=stop, so one kernel OOM kill of an agent process stops the whole service. Every thread on the machine stops with it. No part of bb updates a unit that exists, and--auto-updatechanges only the bb-app package.What changed
host daemon startup (apps/host-daemon/src/app.ts) + serverMove.updateServiceDefinition() # add missing [Service] settings, daemon-reload serverMove.resumeActivation() # unchanged, now runs after the updatepackages/host-daemon-contract/src/server-move.ts: one list,HOST_DAEMON_SYSTEMD_SERVICE_DIRECTIVES, holds the two settings. The daemon and the installer tests both read it.apps/host-daemon/src/server-move/service-definition.ts:addMissingSystemdServiceDirectives(content)adds each missing setting at the end of[Service]. A setting that the unit sets already stays as it is, alsoOOMPolicy = stopwith spaces.systemdDirectivenow accepts spaces around=, as systemd does.apps/host-daemon/src/server-move/service.ts:updateServiceDefinition()finds the daemon's own unit with the same lookup a server move uses (BB_DATA_DIRmust match this data dir), writes the file, and runssystemctl <scope> daemon-reload. It does not restart the service. The update uses the same queue as server-moved notices, so the two never write the unit at the same time. A launchd plist andBB_SERVER_MOVE_SERVICE_MANAGER=noneare not changed.apps/host-daemon/src/server-move/service-manager.ts:reloadSystemdServicecomes out ofrestartService, which now calls it.apps/server/test/app/install-machine-script.test.ts: the user and system unit tests compare the[Service]settings of the generated unit with the shared list, in both directions. A new setting in the installer that is not in the list fails the test.HOST_DAEMON_PROTOCOL_VERSIONdoes not change.Choice: the daemon updates the unit at startup. Precedent: the daemon already rewrites the same file on a server move (
switchToMovedServer,writeServiceDefinition). The alternative is to tell users to rerun the installer, as #7823 does. That restarts the daemon and most users do not know they need it. A maintainer can ask for the other choice in a comment or push commits to this branch.How you verified
mainb0ddaad)service-definition.test.ts: 6 cases foraddMissingSystemdServiceDirectives(old unit, partial, other section, spaces, CRLF, no[Service])addMissingSystemdServiceDirectives is not a functionservice-update.test.ts: old unit gets the settings and onedaemon-reload, no restart, file mode kept; failed reload is logged; a server move during the update keeps both changes; unit settings are kept;noneservice manager is not touchedMemoryHigh=90%added only toinstall-machine.shLive check on systemd 262 (Arch Linux), with a scratch user unit
bb-host-daemon-oom-live-check.service(ExecStart=/usr/bin/sleep infinity, no OOM settings) and the realServerMoveService:A second run changed nothing. The script removed the scratch unit.
On the machine that found this, an old unit restarted the daemon on each of four OOM kills of agent processes in nine minutes. With the same two settings in a drop-in, five more OOM kills did not restart it.
pnpm exec turbo run typecheck test lint lint:type-aware --continue --filter=@bb/host-daemon --filter=@bb/host-daemon-contract --filter=@bb/server: all typecheck and lint tasks pass with 0 warnings.@bb/servertests pass. Two tests fail locally and also fail on unchangedmainon this machine:payload-size.test.ts(Node 26 gzip sizes) andprotocol-self-update.test.ts(Arch keeps npm outside the Node directory). CI uses Node 22.An Opus review found no blocking defect. Its points are fixed here: the update now runs before
resumeActivationand on the server-moved queue, a failed reload is logged as such, settings with spaces are kept, and the drift test checks both directions.Not covered by a test: the one
app.tsline that starts the update.resumeActivationat the same place has no test either.Fixes #8297