Skip to content

fix(sandbox): remove the worker container in Delete - #778

Closed
sresarehumantoo wants to merge 1 commit into
BaaRai:mainfrom
sresarehumantoo:fix/delete-removes-worker
Closed

sresarehumantoo wants to merge 1 commit into
BaaRai:mainfrom
sresarehumantoo:fix/delete-removes-worker

Conversation

@sresarehumantoo

Copy link
Copy Markdown
Contributor

Follow-up to #737.

Problem

DockerBackend.Delete no longer removes the worker container. The worker stays running and attached to the task network, so the network delete fails and Delete returns an error:

Delete(e2ea-52617) failed: delete task e2ea-52617: remove network artex-test-task-e2ea-52617: HTTP 403: {"message":"error while removing network: network artex-test-task-e2ea-52617 has active endpoints (name:\"artex-worker-e2ea-52617\" id:\"b605a419c90a\")"}

Because Delete now keeps the task entry until every resource is proven gone, each retry hits the same error. server_mgmt.go logs the error and deletes the task anyway, so the worker container and task network are left behind. The uid 10001 processes are still killed by the proc scan, so this is a resource leak, not a surviving agent process.

Cause

49c4511 (#737) rewrote Delete (sandbox/docker.go) to call killCaptured. When killWorkerByProcScan succeeds, killCaptured returns nil and intentionally leaves the worker running so Kill (pause) can reuse it. The previous Delete followed Kill with b.removeContainer(ctx, tc.workerID); that line was dropped in the rewrite, so the worker is only removed on the proc-scan failure fallback.

Fix

After killCaptured, Delete removes the worker container the same way it removes the proxy: the error is joined, and workerID is cleared via clearWorkerID only once removal is proven. The worker goes before the network, and the task stays in the map for retry on any failure. Kill is unchanged.

Tests

  • TestDeleteRemovesWorkerBeforeNetwork: Delete issues DELETE /containers/worker-1 before DELETE /networks/artex-task-t1.
  • TestDeleteKeepsStateWhenWorkerRemovalFails: a 500 on the worker delete returns an error and keeps the task and workerID.

Both fail on main and pass with this change. The existing fake Docker tests missed the bug because none asserted a worker DELETE after a successful kill.

The Docker e2e is opt-in and not run in CI, which is how this got through. With artex-worker:local and artex-egress-proxy:local built from this branch:

$ ARTEX_SANDBOX_DOCKER_TEST=1 go test ./sandbox/ -run TestDockerSandboxE2EContainment -count=1 -v
...
    docker_e2e_test.go:258: post-Kill egress audit lines stable at 7 (zero post-Kill egress)
--- PASS: TestDockerSandboxE2EContainment (5.42s)
ok  	github.com/Autumn-27/artex/sandbox	5.430s

On main the same run fails at the Delete step with the error above.

go build ./..., go vet ./..., gofmt -l . (clean) and go test ./... pass.

@thecorporatetractor

Copy link
Copy Markdown
Contributor

Reproduced the bug on main and checked the fix against a real Docker Engine (27.5.1):

  • main: ARTEX_SANDBOX_DOCKER_TEST=1 go test ./sandbox/ -run TestDockerSandboxE2EContainment fails at Delete with remove network artex-test-task-…: HTTP 403 … has active endpoints, and leaves artex-worker-<id> plus the task network behind. We hit the same thing through artex-runner: DELETE /v1/tasks/{id} returned 500 and the worker stayed attached to the task network.
  • this branch: the same e2e passes, and no container or network is left.
  • go test -race ./sandbox/ passes. The two new tests fail on main (copied onto main) and pass here.

Heads-up: #764 also rewrites Delete to remove the worker. The two branches merge without a textual conflict, but you end up with two consecutive removeContainer(workerID) calls in Delete, so whichever lands second should drop its hunk.

@BaaRai

BaaRai commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Closing as a duplicate of #764, which is merged.

#764's Delete path removes the worker and keeps the task entry when removal fails, and it also covers workers left behind by failed execs, timeouts, cancelled streams and truncated demux responses, with the cleanup mutex. Merging both would leave a second, dead removeContainer block in Delete and contradictory cleanup tests.

If #778 has a case #764 misses, say which one and reopen with a focused test.

@BaaRai BaaRai closed this Dec 1, 2026
@sresarehumantoo

Copy link
Copy Markdown
Contributor Author

Agreed, #764 covers it, including the keep-on-failure case #778 tested. With #764 on main, the live e2e on #777 passes without #778.

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.

3 participants