Repository navigation
Default OOM avoidance for installed bb systemd units - #7823
Merged
Merged
Conversation
…avoid The unit's cgroup holds the bb server, host daemon and every agent thread, so a systemd-oomd kill ends all of them at once. Marking it avoid makes oomd pick another candidate first, matching the drop-in we had been applying by hand on affected machines. Server moves keep the line because they rewrite only ExecStart.
Contributor
|
Thanks for the pull request, @smsunarto. It was closed automatically because it does not meet the requirements below yet. This is an automated check, not a review of the change. Linked issue. Every pull request must close an open issue in this repository. The issue keeps the problem tracked even if this pull request closes or we take a different approach. Open an issue for the change, or find an existing one, and add See CONTRIBUTING.md for details. |
ymichael
pushed a commit
that referenced
this pull request
Dec 1, 2026
…them (#8298) ## Human comments ## What was wrong `install-machine.sh` writes `OOMPolicy=continue` (#7039) and `ManagedOOMPreference=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 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 #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` b0ddaad) | 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 #8297 > AGENT GENERATED
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
Generated bb systemd units had no preference against selection by systemd-oomd, so memory pressure could terminate the host daemon and its agent processes.
What changed
Add
ManagedOOMPreference=avoidbesideOOMPolicy=continuein generated user and system units. Assert the setting in both installer test paths. Existing installations need the installer rerun to receive it. User units retain systemd's limitation that swap-triggered selection ignores this preference for non-root-owned cgroups.How you verified
The implementation thread ran the targeted installer suite through Turbo: 54 tests passed. It also verified the unit with systemd-analyze on systemd 262. A live reinstall was skipped because it would restart the daemon hosting active threads.
Fixes #7824