fix(setup): reap orphaned agent containers on service stop#2708
Open
danilomendonca wants to merge 1 commit into
Open
fix(setup): reap orphaned agent containers on service stop#2708danilomendonca wants to merge 1 commit into
danilomendonca wants to merge 1 commit into
Conversation
KillMode=process spares agent containers from systemd's cgroup kill so in-flight work survives a host restart, but it left them orphaned until the next startup's cleanupOrphans() reaped them — emitting a "left-over process / unclean termination" warning in between. Add an ExecStopPost that reaps this install's containers when the host stops, scoped by the nanoclaw-install=<slug> label so peer installs are untouched, matching the host's `docker stop -t 1`. Startup cleanupOrphans() stays as a fallback for crash cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
.claude/skills/<name>/, no source changes)Description
What — The generated Linux systemd unit now reaps this install's agent containers when the host service stops, via an
ExecStopPosthook insetup/service.ts.Why — The unit runs with
KillMode=process, which deliberately spares the agent containers from systemd's cgroup kill so in-flight work can survive a host restart. The side effect is that onstop/restartthose containers are orphaned until the next startup'scleanupOrphans()reaps them. In the meantime systemd logs aFound left-over process <pid> (docker) in control group while starting unit ... unclean terminationwarning on every restart, and a container lingers during the gap.How it works —
ExecStopPostrunsdocker stop -t 1against containers carrying this install'snanoclaw-install=<slug>label (slug interpolated viagetInstallSlug). This reuses the exact label scoping and stop command the host already uses incleanupOrphans()/stopContainer, so:KillMode=processis kept, so the host still gets a clean SIGTERM shutdown,cleanupOrphans()stays in place as a fallback for crash (non-graceful) exits.Only the systemd path is affected; macOS/launchd and the nohup fallback are unchanged.
How it was tested —
nanoclaw-install=<slug>, ransystemctl --user stop, and confirmedExecStopPostran (code=exited status=0) and reaped it — container list empty afterward.left-over process/unclean terminationwarning in the journal.pnpm run build(tsc) passes.