Repository navigation
fix(bin): stop a finished task's Docker containers at teardown - #16
Merged
Merged
Conversation
Docker keeps a stack running after the worker that started it exits, and teardown returned the worktree without looking at containers, so finished tasks' demo, end-to-end, and identity-provider stacks kept loading the machine. bin/fm-task-containers.sh proves ownership from what Docker records for each container - the compose working dir and config files labels and bind mount sources - against the task's worktree (bounded by the slot claim time for a reused pool slot), its temp root, and the no-mistakes run worktrees of this repo whose run is on the task branch. Teardown stops (never removes) only those, reports each, and carries on when Docker is missing or down. Ship and scout briefs now tell workers to start stacks from their worktree and stop them before reporting done. Also isolates the endpoint-safety suite's tmux servers from the operator's tmux.conf, whose automatic-rename broke its window-name lookups.
…hed containers on inspect
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.
Intent
The captain's laptop nearly died under load (load average around 50). Among the causes were Docker stacks that workers started and that kept running after their tasks were finished and cleaned up: a demo stack started 2026-10-15 from a demo worker's worktree (compose project odshow3-app/-cp/-dbs, config under ~/.treehouse/owndivision-demo-/2/), a no-mistakes end-to-end stack from 2026-10-15 (project nm01m4, config under ~/.owndivision-demo-9 and /tmp/nm01M4), a Keycloak container from a no-mistakes run worktree (odkc-nm-k1, mounts under ~/.no-mistakes/worktrees///), a local-CI Postgres (localci-be-pg), and an example-databases stack from a torn-down worktree (project owndivision-example-dbs, config under ~/.treehouse/owndivision-example-dbs-/1/). Firstmate stopped them by hand.
The captain's words: "I think these were spin-up by workers. And if we don't need them, we are closing the workers, we are closing their stack. Why is that? I think we should probably have a look at this and fix it."
What Changed
bin/fm-task-containers.sh(list/stop). It finds the running Docker containers a task provably owns by checking Docker's own records: the compose working dir, the compose config-file labels, and bind-mount sources. A container counts only if one of those paths is in the task worktree, the task temp root, or a no-mistakes run worktree on the worktree's branch. For a reused pool slot, containers started before this task took the slot don't count. It only runsdocker stop(never rm, never removes volumes). Containers it can't attribute are left running. Missing or unreachable Docker is reported, not treated as a failure.bin/fm-teardown.shnow calls it before returning the worktree, for every non-secondmate task, as a best-effort step that never blocks teardown. For a pool slot it passes the worktree only when this task holds the owner claim, with the claim's time as the start bound; it always passes the task temp root.bin/fm-brief.sh) gain a rule: start Docker stacks from compose files and bind mounts inside the worktree, and stop every container you started before reporting done. Docs (architecture.md,scripts.md) and tests cover the new script, the teardown wiring and the brief text.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change only runs
docker stop, never rm or volume removal, and it acts only on containers proved by Docker-recorded paths, with a pool-slot time bound. It is best effort in teardown, both round-1 fixes (parent-shell cache and tolerating partial inspect output) are correctly in place, and behavior tests cover the cases.Testing
I ran four targeted suites against the fake Docker: fm-task-containers, fm-teardown, fm-teardown-endpoint-safety and fm-brief. All passed, including the regression tests for the run-lookup cache and the container that exits between
psandinspect. Then I ran the script against the live Docker engine (29.5.3).listnamed the three containers the task owns (two from the worktree compose stack, one bind-mounted from the temp root) and changed nothing.stopstopped only those three; the compose stack outside the task and the container with only a named volume kept running. The stopped containers remain as exited (stop only, no rm, no volume removal), and a secondstopwas a no-op. The full transcript is saved as evidence. After capture I stopped the two control containers by hand. My attempt to remove the test containers and volume was denied, so they remain as stopped, harmless leftovers.Evidence: Real-Docker transcript: list and stop pick out only the task's containers
Source: Real-Docker transcript: list and stop pick out only the task's containers
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-task-containers.sh:137- The no-mistakes run proof matches any run of this repo whose branch equals the worktree's current branch, with no slot-time bound. If teardown ever runs on a worktree checked out on a shared branch, it would treat every no-mistakes run on that branch as the task's. Example: a scout makes no branch, so its slot could sit onmain, and then the captain's own gated runs onmainwould match. Containers mounted under those run worktrees would then be stopped. Stop is non-destructive and I could not prove that a scout slot is ever on a named default branch rather than a detached HEAD, so this is informational. A cheap guard would be to leave NM_WORKTREES empty when BRANCH is the repo's default branch (origin/HEAD).✅ **Test** - passed
✅ No issues found.
bash tests/fm-task-containers.test.sh(covers the parent-shell no-mistakes cache (one lookup per run), a container that exits betweendocker psanddocker inspect, the reused-slot time bound, symlinked /tmp paths, Docker missing or unreachable, a container that will not stop)bash tests/fm-teardown.test.sh(includes 'teardown stops the Docker containers started from the task's worktree and temp root, and only those' and 'teardown finishes and reports it when Docker is unreachable')bash tests/fm-teardown-endpoint-safety.test.sh(includes 'worktree containers count only from the task's own slot claim onward')bash tests/fm-brief.test.sh(crewmate briefs tell workers to start stacks from their worktree and stop them before reporting done)Real-Docker run: started compose projectfmtce2e-taskfrom a temp worktree, adocker runbind-mounted from a temp task root, plus controls (a compose project outside the task and a container with only a named volume), then ranbin/fm-task-containers.sh listandstop --task e2e1 --worktree $WT --tasktmp $TT, checked states withdocker ps -a, and repeated the stop to show it does nothing the second time✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.