Repository navigation
feat(bin): cap crew memory in a systemd user slice - #4
Conversation
config/crew-memory-max opts every worker launch into its own MemoryMax-capped transient user scope under fm-crew.slice, so an out-of-memory kill stays inside the fleet instead of taking down the host.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f929908b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ! command -v systemd-run >/dev/null 2>&1; then | ||
| echo "error: config/crew-memory-max is set but systemd-run is not available; remove the file or launch on a systemd host" >&2 | ||
| exit 1 |
There was a problem hiding this comment.
Preflight the cap before stopping a relaunch
When fm-control relaunch encounters a malformed cap or a missing systemd-run, the old worker has already been stopped by do_exit() before this new validation runs in fm-spawn.sh. The control path deliberately checks other predictable launch refusals in resolve_relaunch_profile() before stopping, so this validation also needs a shared pre-stop preflight; otherwise a configuration typo or unavailable dependency unnecessarily leaves a healthy task stopped.
Useful? React with 👍 / 👎.
| # environment because it needs the pane's user-bus variables, and the launch is | ||
| # re-wrapped in /bin/sh because it may begin with shell assignments. | ||
| if [ -n "$CREW_MEMORY_MAX" ]; then | ||
| LAUNCH="systemd-run --user --scope --quiet --collect --slice=fm-crew.slice --unit=$(shell_quote "fm-crew-$ID-$SPAWN_GEN") -p MemoryMax=$CREW_MEMORY_MAX -- /bin/sh -c $(shell_quote "$LAUNCH")" |
There was a problem hiding this comment.
Observe systemd-run failures before declaring spawn success
On hosts where the binary exists but the user manager is unreachable, the memory controller/property is unavailable, or the pane has a different PATH, the earlier command -v check passes while this command fails in the pane. (systemd-run --help describes --user as “Run as user unit,” so binary presence alone does not establish that the operation can succeed.) For most harnesses the spawn process only sends this line and does not observe its exit status, after already publishing the endpoint and task record, so it reports a successful capped spawn even though no agent started; the launch must either validate the target execution context or acknowledge the wrapper result before returning success.
AGENTS.md reference: AGENTS.md:L41-L42
Useful? React with 👍 / 👎.
Resolve AGENTS.md by keeping upstream's version, which moved the home layout listing into the operational-home-layout skill, and carry the config/crew-memory-max entry into that skill's listing instead. Resolve bin/fm-spawn.sh by keeping both the upstream and fork header and config-read blocks, and keeping only the systemd-run memory wrap where upstream moved the launch-home-token block earlier.
Why
The host ran out of memory with a full fleet. The kernel OOM killer then picked processes across the whole box, and a hard reboot was needed.
What
config/crew-memory-max(one systemd size, such as6G).bin/fm-spawn.shwraps every launch (ship, scout, secondmate, relaunch) insystemd-run --user --scope --slice=fm-crew.slice -p MemoryMax=<size>.The agent and everything it starts share one capped scope, so an OOM kill stays inside that worker.
systemd-runsits outside anyenv -ilaunch filter so it keeps the user-bus variables. The launch is re-wrapped in/bin/sh -cbecause it may start with shell assignments.systemd-run, refuses the spawn before anything is created. When the file is absent, launches are unchanged.fm-crew.sliceitself, documented indocs/configuration.md.Tests
tests/fm-spawn-crew-memory-max.test.shdrives the real spawn and executes the delivered launch with asystemd-runprobe. It covers a capped launch, an absent file leaving the launch unchanged, and a malformed value refusing.bin/fm-lint.shpasses.[email protected]/fm-crew.slice/fm-crew-<id>-<token>.scopewith a 6G cap, inside a 32G slice.🤖 Generated with Claude Code