#3909·nanoclaw

[bug] Host starts a session container for an agent group deleted mid-spawn

Author: glifocatCreated Sep 25, 2026Updated Sep 25, 2026
Labelskind/bugarea/containers

Affected NanoClaw version or commit

main @ c313d061

Host platform

Any (host-side logic, not platform-specific)

What happened?

spawnContainer (src/container-runner.ts) reads the agent group once (getAgentGroup, ~L359) and then awaits several steps before the container starts: initGroupFilesystem (~L383), ensureGatewaySession (~L397), the session claim, and driver.prepare (~L458). None of them rechecks that the group still exists. If the group's rows are deleted in that window (setup's scripts/delete-cli-agent.ts after the ping test, or any admin delete), the host still starts the container, and initGroupFilesystem can recreate the groups/<folder>/ directory the delete just removed.

https://github.com/nanocoai/nanoclaw/pull/3878 narrows this from the cleanup side: the script sweeps the group's containers for a few seconds after deleting the rows and reports any survivor. It cannot close the window: a spawn slower than the sweep still starts.

What did you expect?

A spawn whose group (or session) was deleted mid-spawn aborts before starting a container, releases its claim and gateway lease, and does not recreate the group folder.

How can we reproduce it?

Timing-dependent. In a unit test: start spawnContainer for a group, delete the group's rows while ensureGatewaySession is pending, then let it resolve. Today driver.prepare is still called and a container starts.

Proposed fix: recheck the group and the session row right before driver.prepare, after the claim; if either is gone, release the claim and gateway session and abort. Optionally recheck once more before initGroupFilesystem so a deleted folder is not recreated.

Acceptance: a unit test that deletes the group while ensureGatewaySession is pending asserts driver.prepare is never called and the claim and gateway lease are released.

Last version that worked

None known; the window has existed since spawns became multi-step.