bug: devcontainer associates with a stale stopped container, leaving the running one permanently without a sub-agent
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
- #29882 de @pujitha24 — cerrado sin fusionar
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 65/100
Línea de trabajo
The bug is in agent/agentcontainers/containers_dockercli.go and api.go. Start by reading the container listing logic at line 247 and the association loop around line 982. The fix likely involves filtering for running containers or matching on both devcontainer labels. Run the existing tests for agentcontainers and add a test that reproduces the stale container scenario. Verify the fix by building the agent and testing with the steps in the issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
A devcontainer can be left permanently without a sub-agent while its container runs
normally, with Coder reporting the devcontainer as stopped and naming a container that
exited hours earlier.
When two containers carry the same devcontainer.local_folder label -- e.g. a stale one
left behind beside a freshly created one -- the agent associates the devcontainer with
the oldest match, regardless of state. coder show then displays that dead
container's name and a stopped status, and because injection is gated on Running,
no sub-agent is ever injected into the container that is actually running. That
container has no agent process at all.
It never recovers on its own: the refresh loop recomputes the same association every
interval. It is also silent -- no error, no warning, and no container_id in the agent
log, because the injection function is never entered. Removing the stale container is
the only fix; the next refresh then injects normally.
Three pieces compose into it:
-
agent/agentcontainers/containers_dockercli.go:247lists containers with
docker ps --all --quiet --no-trunc-- stopped containers included -- and appends ids
in output order.docker pssorts newest-first. -
agent/agentcontainers/api.go:~982, in the container -> devcontainer association loop:if dc, ok := api.knownDevcontainers[workspaceFolder]; ok { ... dc.Container = container // last write wins; no check on Running api.knownDevcontainers[dc.WorkspaceFolder] = dc continue }Newest-first input plus last-write-wins means the oldest matching container ends
up indc.Container. -
Injection is then gated on the status derived from that container:
if dc.Status == codersdk.WorkspaceAgentDevcontainerStatusRunning {
err := api.maybeInjectSubAgentIntoContainerLocked(ctx, dc)
Note the asymmetry that makes this reachable: @devcontainers/cli decides whether to
reuse a container by matching both id labels (devcontainer.local_folder and
devcontainer.config_file), but the association loop above keys on
devcontainer.local_folder alone. A container the CLI correctly declines to
reuse is still adopted by the agent.
Relevant Log Output
coder show -- the devcontainer is bound to affectionate_euclid, which exited the
previous day, and is reported stopped:
└─ main (linux, amd64) ⦿ connected ✔ healthy v2.36.4+10fd510
└─ Devcontainers
└─ myproject [affectionate_euclid] ⏹ stopped
docker ps -a on the workspace pod -- the bound container is long dead, while the real
devcontainer has been up for 21 minutes (unrelated containers trimmed):
CONTAINER ID IMAGE CREATED STATUS NAMES
c96d64aede24 vsc-myproject-<hash>-uid 23 minutes ago Up 21 minutes hungry_albattani
931085ca94fc <untagged older image> 20 hours ago Exited (255) 20 hours ago affectionate_euclid
Both carry devcontainer.local_folder=/workspace/myproject.
The running container had no agent process and no agent logs at all.
Agent log for the same period. The agent started at 18:57:21 with the real container
already running since 18:56:17, and created no sub-agent for 24 minutes. There is no
error, and no container_id field appears anywhere in that window, because the
injection function is never entered:
2026-09-22 18:57:21.075 [info] agent is starting now
... 24 minutes: no devcontainer errors or warnings, no container_id logged ...
The stale container was then removed by hand, and the next refresh recovered
immediately:
# docker rm affectionate_euclid
2026-09-22 19:21:19.146 [info] containers: detected container architecture
2026-09-22 19:21:19.513 [info] containers: copied agent binary to container
2026-09-22 19:21:19.655 [debu] containers: checking if sub agent should be deleted
2026-09-22 19:21:19.655 [debu] containers: creating new subagent
2026-09-22 19:21:19.674 [info] containers: starting subagent in devcontainer
# docker exec hungry_albattani ps aux | grep coder
node 3789 /.coder-agent/coder agent # started 19:21
The only container id that ever appears in the agent log is the surviving one, first
mentioned at 19:21:19.
Expected Behavior
When several containers match a devcontainer's workspace folder, the agent should
associate the one the devcontainer CLI would actually use -- ideally by matching on the
same pair of id labels the CLI matches on, rather than on devcontainer.local_folder
alone. Preferring a running container, or the newest, would also avoid this particular
failure.
Steps to Reproduce
These steps are a way to recreate the scenario by launching a container, bringing up one and
stopping it, and then relaunching the original one in order to make the stopped one "older".
Coder will then not be able to inject the agent into the newer running container, and we will
be in a silently stuck state until the "older" container is deleted, leading to recovery.
-
Create a workspace whose template declares a
coder_devcontainerresource. Let the
agent bring the devcontainer up and confirm a sub-agent is injected. -
On the workspace host, create a decoy container carrying the same workspace-folder
label, and stop it. We are going to make this one the "older" container:
docker run -d --name decoy
--label devcontainer.local_folder=/workspace/myproject
alpine sleep infinity
docker stop decoy -
Recreate the real devcontainer so that it is newer than the decoy -- the Rebuild
action in the UI, ordevcontainer up --remove-existing-container. -
Wait one refresh interval (10s default).
coder showreports the devcontainer asstoppedand namesdecoy, although the
real container is running. No sub-agent is injected into it, and nothing is logged. -
docker rm decoyWithin one refresh interval the sub-agent is created and injected.
The ordering in step 3 matters: the decoy must be the older of the two, since the oldest
matching container is the one that wins.
Environment
- Host OS: Ubuntu (workspace container), Kubernetes-hosted workspaces
- Coder version: v2.36.0 (server), agent v2.36.4
Not tested on the latest release, but the relevant code is unchanged on main as of
this writing: containers_dockercli.go:246 still lists with --all, and api.go:982
still assigns dc.Container with no Running check.
Additional Context
The issue occurs consistently
- Lenguaje dominante
- Go
- Estrellas
- 17.5k
- Forks
- 1.7k
- Merge medio
- 2 d 23 h
- PR fusionados (30 d)
- 575
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de coder/coder
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
coder/coder#33007 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug: token allow-list with a specific template ID returns 500 "column reference \"id\" is ambiguous"Posiblemente ocupada @stirby la tomó hace 22 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
coder/coder#32059 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
feat(cli): add `--agents-allowed` to `coder templates push`Posiblemente ocupada @jeremyruppel la tomó hace 4 días. Abiertocli
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
coder/coder#32005 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
feat(cli): add `--require-active-version` to `coder templates push`Posiblemente ocupada @jeremyruppel la tomó hace 4 días. Abiertocli
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
coder/coder#32004 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
feat(cli): add `--dormancy-auto-deletion` to `coder templates push`Posiblemente ocupada @jeremyruppel la tomó hace 4 días. Abiertocli
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
coder/coder#32003 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de coder/coder
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
keyxmakerx/Chronicle#3048 ·
Los mantenedores suelen responder en 1 día
-
triage/needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cozystack/cozystack#5590 · 1 reacción ·
Los mantenedores suelen responder en 2 días
-
[Bug] DSL formatter drops required quotes from names that start with a digit, hyphen, dot or slashAbiertoneeds-acceptance wg/mom-routing
Dificultad 2/5 1-3 horas Aptitud para principiantes 81/100
vllm-project/semantic-router#8079 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: v4.0.0-rc.12 result_unknown on MySQL 5.7 — information_schema.statistics.expression 不存在Abiertobug triage v4
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100