Skip to content

fix(systemd): KillMode=process preserves retained Codex sidecars across unit restarts - #847

Merged
danshapiro merged 1 commit into
mainfrom
fix/killmode-retention
Oct 14, 2026
Merged

danshapiro merged 1 commit into
mainfrom
fix/killmode-retention

Conversation

@danshapiro

Copy link
Copy Markdown
Owner

What

The server's graceful shutdown deliberately RETAINS adopted terminal-pane Codex sidecars across restarts (SAFE-11 — "killing sidecars at shutdown is NOT acceptable; surviving restarts is a feature", crates/freshell-server/src/main.rs). But systemd's default KillMode=control-group signals every remaining process in the unit's cgroup after the main process exits — so every systemctl --user restart freshell-rust slaughtered exactly the sidecars the server just saved, destroying in-flight Codex conversations. The live host's installed unit even pinned KillMode=control-group explicitly.

  • installers/systemd/freshell-rust.service: ship KillMode=process (signal only the main process). Accepted trade-off, documented in the unit: a CRASHED server's children are not reaped by systemd — matching the setsid launcher's crash semantics. Verified with systemd-analyze verify.
  • crates/freshell-server/src/main.rs: the SAFE-11 comment now points at the shipped setting (its old text said the unit "is NOT installed today" — stale, and this host's production server runs under the unit).
  • docs/development/self-hosted-launch-runbook.md: the unit-coupling note now says retention survives unit restarts when the installed copy carries the line, with verify/re-copy/daemon-reload guidance.

Config/comment/doc only — no executable behavior changed in-repo.

Validation

  • systemd-analyze verify passes on the modified unit.
  • Retention behavior itself is covered by the existing SAFE-11 cargo tests (workspace rust-tests/rust-gate run them).
  • The live host's installed unit was updated and daemon-reloadd (staged, no restart — effective at the next approved restart); systemctl --user show freshell-rust -p KillMode now reports process.

…ss unit restarts

The server's graceful shutdown deliberately retains adopted
terminal-pane Codex sidecars (SAFE-11), but systemd's default
KillMode=control-group (and the live host's explicit one) kills them
after the main process exits — every systemctl restart destroyed
in-flight Codex conversations.

- Ship KillMode=process in the unit (accepted trade-off, matching the
  setsid launcher's crash semantics: a crashed server's children are
  not reaped by systemd).
- Point the SAFE-11 comment in main.rs at the shipped setting instead
  of a hypothetical adoption note.
- Update the runbook's unit-coupling note: retention survives unit
  restarts when the installed copy carries the line; verify + re-copy
  + daemon-reload guidance included.

Config/comment/doc only; no executable behavior changed in-repo.
Host install staged separately (daemon-reload done; effective at the
next approved restart).
@danshapiro
danshapiro merged commit d7da08b into main Oct 14, 2026
7 checks passed
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