Skip to content

Default OOM avoidance for installed bb systemd units - #7823

Merged
ymichael merged 1 commit into
get-bb:mainfrom
smsunarto:scott/oomd-avoid-default
Nov 19, 2026
Merged

ymichael merged 1 commit into
get-bb:mainfrom
smsunarto:scott/oomd-avoid-default

Conversation

@smsunarto

@smsunarto smsunarto commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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=avoid beside OOMPolicy=continue in 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

AGENT GENERATED

…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.
@github-actions github-actions Bot added the needs-issue PR does not close an open issue label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
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 Fixes #<number> to the pull request description. Feature requests and UI changes need a maintainer's sign-off on the issue first. This pull request reopens on its own once you save the description.

See CONTRIBUTING.md for details.

@github-actions github-actions Bot closed this Nov 19, 2026
@github-actions github-actions Bot removed the needs-issue PR does not close an open issue label Nov 19, 2026
@github-actions github-actions Bot reopened this Nov 19, 2026
@ymichael
ymichael merged commit 0a8cb4a into get-bb:main Nov 19, 2026
59 checks passed
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
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.

fix(install-machine): generated units lack systemd-oomd avoidance preference

2 participants