You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(sandbox): remove workers on failed execs and task deletion - #764
Deleting a task can leave its worker container attached to the task network: the process scan stops application processes but preserves PID 1 and the network endpoint. Exec timeouts, interrupted streams, and unverifiable completion responses can also return without removing the worker that ran the command.
This change removes the worker before its proxy and network on task deletion. For execution cleanup, it captures the container ID and force-removes that container after a timeout, cancellation, stream/start error, or a completion status that cannot be confirmed. Removal uses a fresh bounded context; failures remain visible and retain the state needed for retry. Task creation and cleanup share the lifecycle lock, and delayed cleanup preserves replacement workers.
Task-level behavior: removing a worker terminates all concurrent commands and background services in that task. Other tasks keep running, /workspace is preserved, and the next exec recreates the worker. Successful commands retain their worker. This behavior is documented in docs/SANDBOX.md.
Validation on macOS with Go 1.26.11:
TMPDIR=/tmp go test -race -count=1 ./sandbox ./cmd/artex-runner ./cmd/artex-egress-proxy ./cmd/artex-exec-wrap: passed; 22 top-level sandbox tests passed, 3 skipped. The command packages have no test files.
Concurrent sibling termination, another task remaining active, deletion versus recreation, and delayed cleanup preserving a replacement worker are covered. The three concurrency/replacement tests also passed 10 repetitions under -race.
The same focused cleanup regression tests fail on unmodified 613ae14; the successful-exec control passes on both versions.
go vet on the affected packages, gofmt, and git diff --check passed. The packages build for Linux amd64/arm64, macOS amd64/arm64, and Windows amd64 with CGO_ENABLED=0.
Not yet validated locally: Docker Engine and the Docker CLI are unavailable here, so the two live Docker tests and the Compose check were skipped. The new opt-in TestDockerTimeoutRemovesDetachedChild uses a local file canary to check that a detached child stops after timeout cleanup. Full repository CI has not been run locally.
Ran go test -race -count=1 ./sandbox/ on the branch: pass. Against Docker Engine 27.5.1, TestDockerSandboxE2EContainment and the new TestDockerTimeoutRemovesDetachedChild both pass, and Delete no longer fails on the task network (it fails on main with "has active endpoints").
One behaviour change worth a look. sandbox/docker.go:703-704 treats any exit code 124 as a runner timeout and now removes the worker:
So an ordinary inner timeout tears down the worker and every background job/service of the task. The TimedOut:true misreport was already there on main; removing the container is new. Could exec-wrap report its own timeout out-of-band (a distinct exit code or marker), or could the runner at least require DurationMS >= TimeoutMS before removing?
Two smaller points:
ensureTask now inserts a placeholder taskContainers into b.tasks before anything is created (docker.go:446). If creation fails, the entry stays and WorkerCount() counts it. That is harmless for Delete, and it arguably helps by keeping the network around for cleanup, but it is worth a comment.
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
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.
Deleting a task can leave its worker container attached to the task network: the process scan stops application processes but preserves PID 1 and the network endpoint. Exec timeouts, interrupted streams, and unverifiable completion responses can also return without removing the worker that ran the command.
This change removes the worker before its proxy and network on task deletion. For execution cleanup, it captures the container ID and force-removes that container after a timeout, cancellation, stream/start error, or a completion status that cannot be confirmed. Removal uses a fresh bounded context; failures remain visible and retain the state needed for retry. Task creation and cleanup share the lifecycle lock, and delayed cleanup preserves replacement workers.
Task-level behavior: removing a worker terminates all concurrent commands and background services in that task. Other tasks keep running,
/workspaceis preserved, and the next exec recreates the worker. Successful commands retain their worker. This behavior is documented indocs/SANDBOX.md.Validation on macOS with Go 1.26.11:
TMPDIR=/tmp go test -race -count=1 ./sandbox ./cmd/artex-runner ./cmd/artex-egress-proxy ./cmd/artex-exec-wrap: passed; 22 top-level sandbox tests passed, 3 skipped. The command packages have no test files.-race.613ae14; the successful-exec control passes on both versions.go veton the affected packages,gofmt, andgit diff --checkpassed. The packages build for Linux amd64/arm64, macOS amd64/arm64, and Windows amd64 withCGO_ENABLED=0.Not yet validated locally: Docker Engine and the Docker CLI are unavailable here, so the two live Docker tests and the Compose check were skipped. The new opt-in
TestDockerTimeoutRemovesDetachedChilduses a local file canary to check that a detached child stops after timeout cleanup. Full repository CI has not been run locally.