Skip to content

Add OOMPolicy=continue drop-in to installed host daemon units on start - #573

Merged
albrand merged 11 commits into
oursfrom
bb/wsl-hostd-oom-bb-host-daemon-grows-to-44-gb-and-thr_8mp3faezeu
Nov 25, 2026
Merged

albrand merged 11 commits into
oursfrom
bb/wsl-hostd-oom-bb-host-daemon-grows-to-44-gb-and-thr_8mp3faezeu

Conversation

@albrand

@albrand albrand commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Root cause

Host daemon units installed before get-bb#7039 never got OOMPolicy=continue (apps/server/src/assets/install-machine.sh:1178 only runs on an explicit install). With the systemd default OOMPolicy=stop, the kernel OOM-killing one child stops the whole unit; this took down the hsrpc-wsl daemon and its sessions on 2026-11-24.

Change

On every daemon start (apps/host-daemon/src/app.ts:1212, in onStart, which also runs after a self-update restart), ensureUnitOomPolicy finds this daemon's systemd user unit with the existing findServiceDefinition and:

  1. Runs systemctl --user cat <unit>, which prints the unit and every drop-in from every systemd search path in load order. If any [Service] section outside bb's own file sets OOMPolicy=, it does nothing. If cat fails it writes nothing and the failure is logged.
  2. Otherwise writes bb's own drop-in <unit>.service.d/50-bb-oom-policy.conf (OOMPolicy=continue) atomically when it is missing or differs.
  3. Runs systemctl --user daemon-reload when systemctl --user show -p OOMPolicy <unit> is not continue.

No restart, no rollback, no file is ever deleted, other drop-ins are never touched. A failed reload is logged and retried on the next start.

Threat model (owner ruling): one writer, bb at daemon start. A concurrent edit of ~/.config/systemd by another process is out of scope.

Not included: per-CLI memory scope (follow-up).

Verification

  • unit-oom-policy.test.ts (11 tests), including a fixture whose cat output has /etc/systemd/user/<unit>.d/10-admin.conf with OOMPolicy=kill (no write, no reload) and a failing cat (no write). All fail against 0265e95; all 11 pass at head.
  • Real systemd on hsrpc-wsl, throwaway units, at df103ea. Base case: OOMPolicy=stop before, migrated, OOMPolicy=continue after, unit stayed active, second call a no-op, only daemon-reload ran. /etc case (passwordless sudo): /etc/systemd/user/<unit>.d/10-admin.conf with OOMPolicy=kill, outcome already-current, show kill before and after, no bb drop-in written, no commands. Everything removed afterwards (LoadState=not-found, no /etc leftovers, 8 other unit-dir files unchanged).
  • pnpm exec turbo run typecheck test --filter=@bb/host-daemon on hsrpc-wsl: see PR comment.

No issue: fork issues are disabled.

AGENT GENERATED

Units installed before get-bb#7039 default to OOMPolicy=stop, so one OOM-killed child stops the whole daemon. On start, a systemd user unit that sets no OOMPolicy gets a 50-oom-policy.conf drop-in and a daemon-reload, with no restart and no other drop-in touched.

test-change-reason: new module covered by a new test file; no existing test changed.
A drop-in such as 10-custom.conf with OOMPolicy=kill would be overridden by the later 50-oom-policy.conf. The migration now skips when any .conf in the unit's drop-in directory sets OOMPolicy.

test-change-reason: new test for the sibling drop-in case; existing tests unchanged.
…ives

When the target drop-in name exists without an OOMPolicy directive, write the policy to the first free 50-oom-policy-N.conf instead of renaming over it.

test-change-reason: new regression test for the pre-existing unrelated drop-in; existing tests unchanged.
…art retries

The drop-in alone made later starts report already-current without a reload.

test-change-reason: new regression test for reload failure then retry; existing tests unchanged.
…s the drop-in

A directive under [Unit], [Install] or a comment is ignored by systemd, so it must not suppress the migration.

test-change-reason: new regression tests for misplaced-section and comment cases; existing tests unchanged.
…he scan is never overwritten or removed

test-change-reason: new deterministic collision-race tests (file created between scan and write, and reload failure with a colliding file); existing tests unchanged.
…he scan

test-change-reason: new deterministic interleaving test (sibling OOMPolicy appears after the scan); existing tests unchanged.
… call created

test-change-reason: new test where a replacement file appears before a failed reload; existing tests unchanged.
… and rollback

test-change-reason: owner ruling on PR 573 simplifies the migration (one bb-owned file, reload keyed on systemctl show); tests rewritten for the new contract and the race and rollback tests removed with their code.
@albrand

albrand commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Final-head check at 0265e95: turbo run typecheck test --filter=@bb/host-daemon on hsrpc-wsl: 9/9 tasks, 1335 tests passed, prettier clean. Hermes round 9 rejected on one coverage gap: drop-ins under other systemd search paths (e.g. /etc/systemd/user/.d) are not scanned. Classified as a heuristic coverage gap (follow-up per the merge rule), not a regression, correctness or data-loss defect within the one-writer threat model. Follow-up: use systemctl --user cat <unit> as the OOMPolicy source of truth.

AGENT GENERATED

…arch path count

test-change-reason: Hermes found drop-ins outside the unit directory were missed; the skip decision now reads systemctl cat output, with new tests for a non-adjacent admin drop-in and a failing cat.
@albrand

albrand commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Head df103ea: turbo run typecheck test --filter=@bb/host-daemon on hsrpc-wsl: 9/9 tasks, 1337 tests passed, prettier clean. Real-systemd base and /etc drop-in checks passed (see PR body).

AGENT GENERATED

test-change-reason: Hermes found a drop-in path with a space was not recognised as a header, so its OOMPolicy was missed; new regression test fails at df103ea.
@albrand
albrand merged commit 51aa2e7 into ours Nov 25, 2026
13 checks passed
@albrand
albrand deleted the bb/wsl-hostd-oom-bb-host-daemon-grows-to-44-gb-and-thr_8mp3faezeu branch November 25, 2026 04:29
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