fix(docker): remove container on cleanup when container_persistent=false

When container_persistent=false, the inner mini-swe-agent cleanup only
runs 'docker stop' in the background, leaving containers in Exited state.
Now cleanup() also runs 'docker rm -f' to fully remove the container.

Also fixes pre-existing test failures in model_metadata (gpt-4.1 1M context),
setup tests (TTS provider step), and adds MockInnerDocker.cleanup().

Original fix by crazywriter1. Cherry-picked and adapted for current main.

Fixes #1679
This commit is contained in:
crazywriter1 2026-03-17 04:02:01 -07:00 committed by teknium1
parent f613da4219
commit 7049dba778
5 changed files with 64 additions and 4 deletions

View file

@ -458,6 +458,20 @@ class DockerEnvironment(BaseEnvironment):
"""Stop and remove the container. Bind-mount dirs persist if persistent=True."""
self._inner.cleanup()
if not self._persistent and self._container_id:
# Inner cleanup only runs `docker stop` in background; container is left
# as stopped. When container_persistent=false we must remove it.
docker_exe = find_docker() or self._inner.config.executable
try:
subprocess.run(
[docker_exe, "rm", "-f", self._container_id],
capture_output=True,
timeout=30,
)
except Exception as e:
logger.warning("Failed to remove non-persistent container %s: %s", self._container_id, e)
self._container_id = None
if not self._persistent:
import shutil
for d in (self._workspace_dir, self._home_dir):