Skip to content

feat(bin): cap crew memory in a systemd user slice - #4

Merged
Profreshor merged 1 commit into
mainfrom
fm/crew-memory-cap
Oct 16, 2026
Merged

Profreshor merged 1 commit into
mainfrom
fm/crew-memory-cap

Conversation

@Profreshor

Copy link
Copy Markdown
Owner

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

  • New optional config/crew-memory-max (one systemd size, such as 6G).
  • When present, bin/fm-spawn.sh wraps every launch (ship, scout, secondmate, relaunch) in systemd-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-run sits outside any env -i launch filter so it keeps the user-bus variables. The launch is re-wrapped in /bin/sh -c because it may start with shell assignments.
  • A malformed value, or a host without systemd-run, refuses the spawn before anything is created. When the file is absent, launches are unchanged.
  • The fleet-wide ceiling lives on fm-crew.slice itself, documented in docs/configuration.md.

Tests

  • tests/fm-spawn-crew-memory-max.test.sh drives the real spawn and executes the delivered launch with a systemd-run probe. It covers a capped launch, an absent file leaving the launch unchanged, and a malformed value refusing.
  • bin/fm-lint.sh passes.
  • Live: the wrapper was used to relaunch this home's fleet. Workers run under [email protected]/fm-crew.slice/fm-crew-<id>-<token>.scope with a 6G cap, inside a 32G slice.

🤖 Generated with Claude Code

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T16:58:07.776151Z 8f92990 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread bin/fm-spawn.sh
Comment on lines +588 to +590
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread bin/fm-spawn.sh
# 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")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@Profreshor
Profreshor merged commit c375907 into main Oct 16, 2026
Profreshor added a commit that referenced this pull request Oct 16, 2026
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.
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