Repository navigation
fix(run): a failed run removes the containers its own agents created - #1241
Merged
Merged
Conversation
A codefly run that fails partway leaves its half-started containers running, and they hold the ports the next run needs (#1233, part B). A failed run now force-removes the containers its own agents created since it started, in its recovery scope. A run stopped on purpose keeps them, as before, so the next run reuses their dev data. A container counts as the run's own only when it is codefly-owned, carries one of the run's agent pids as its session, was created after the run started, and is not a ledgered data container. While another run is live in the workspace nothing is removed, since nothing records that it adopted one of these containers. Co-Authored-By: Claude Opus 5.5 <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.
Part B of #1233. Part A, which keeps an undecidable process group without stopping the rest, landed in #1236.
Problem
A
codefly runthat fails partway leaves its half-started containers running. Containers outliving a run is deliberate:dockerrun.shouldReapContainerkeeps a running container whose owner is gone, so the next run can reuse its dev data. But a failed run holds no such data, and its containers keep the ports the next run needs. The next run then refuses those ports.Change
A failed run now force-removes the containers that its own agents created since it started, within its recovery scope. A run that is stopped on purpose (by a signal) keeps its containers, as before.
A container counts as the run's own only when all of these hold (
createdByRun):codefly.owner=true);codefly.invocation);codefly.sessionis the pid of one of this run's agents, recorded as each agent loads;While another run's managed process groups are live in the workspace, nothing is removed. Nothing records whether that run adopted one of these containers.
The cleanup runs only for runtime contexts that already sweep stale containers (
shouldSweepStaleContainers). It has a 30 s budget, and its errors are joined onto the run's error.Classification: a fix at its owner. The leak is in the CLI's run lifecycle, and this is where it is closed.
Reused:
listOwnedContainersand the recovery scope fromcontainerRecoveryIdentity;processgroup.PreviewManagedProcessGroupsfor the live-run check;There is no new label and no Core change.
Tests
pkg/orchestration/run_containers_test.go:TestOnlyContainersThisRunsAgentsCreatedAreItsOwn, a table covering ours, another agent's, created before the run, ledgered, unowned, and a non-pid session;TestAFailedRunRemovesOnlyTheContainersItCreated;TestAFailedRunKeepsItsContainersWhileAnotherRunIsLive.go test ./pkg/orchestration ./cmd/runpasses, andgolangci-lintreports 0 issues.Live run: I started module-robin's playground with this CLI while a port it needs (127.0.0.1:10310) was held, so startup failed partway, at tracing/evidence, with exit 1. The run logged
removed 2 containers the failed run started: [codefly-robin-playground-documents-object-storage-gateway codefly-robin-playground-documents-object-storage-minio], and no robin-playground containers remained afterwards.Not covered
🤖 Generated with Claude Code