Repository navigation
Conversation
DockerSandbox reached the daemon from four places: inspect and container creation each built their own ProcessBuilder with its own stream draining, while start/stop/rm went through runDockerCliBlocking. Only the blocking helper was overridable, so the container lifecycle could not be exercised without a live daemon. Every call now goes through runDockerCli, which returns the exit code plus both streams, and runDockerCliBlocking keeps its contract on top of it. Behaviour is unchanged; this is the seam the container reconciliation needs.
… one The container name is derived from the session id, so the daemon can still hold a container under that name while no usable id is persisted: docker run can succeed with only persisting its id failing. doEnsureContainerRunning only ever looked at the persisted id, concluded "container missing", and issued docker run with a name the daemon had already claimed. That fails with exit 125, nothing corrects the state, and every later turn repeats the same decision, so the session can never start again. The probe also conflated "the daemon says the container does not exist" with "the probe could not answer", so a transient inspect failure was read as evidence that the container was gone. Before creating anything the sandbox now reconciles with the daemon by name: a container found there is adopted or started and its id recorded, and only a name the daemon does not know results in docker run. A probe that cannot answer no longer destroys the persisted id, because it is not evidence of absence; the next command reports the transport failure instead. DockerSandboxContainerReconcileTest drives the lifecycle through a fake daemon that refuses a claimed name like the real CLI. Against the previous code the three reconcile cases fail with "docker run failed (exit=125): ... container name \"/agentscope-sandbox-wedge\" is already in use", which is the reported symptom.
|
[P2] Container adoption reports success even when it did not obtain a usable container ID.
Please require a usable ID before reporting adoption success, propagate an actionable probe failure, or obtain ID and running state in a single inspect response. Add a regression where the name/state probe succeeds and the subsequent ID probe fails, exercising the public start path rather than only the private reconciliation helper. Reviewed head: |
Problem
DockerSandboxderives the container name from the session id, but decides whether a container is usable only from the persistedcontainerId. When the two stop agreeing the code concludes "container missing" and issuesdocker runwith a name the daemon still claims:Nothing corrects the state, so every later turn repeats the same decision and the sandbox session can never start again. The realistic trigger is
docker runsucceeding while persisting the returned id fails — the container exists under the deterministic name, but no id was ever recorded.The probe made this worse by collapsing "the daemon says this does not exist" and "the probe could not answer" into one
UNKNOWNstate, so a failedinspectwas treated as evidence that the container was gone.Change
agentscope-sandbox-<sessionId>first: a running container is adopted (its id recorded), a stopped one is started, and only a name the daemon does not know leads todocker run.inspectContainerStatenow distinguishesMISSING(the daemon explicitly reports no such object) fromUNKNOWN(transport failure). A stale id is cleared only in theMISSINGcase; onUNKNOWNthe persisted id is kept, because a probe that cannot answer is not evidence of absence — the next command surfaces the transport failure instead of the sandbox silently building a second container.inspectand container creation each used to build their ownProcessBuilderwith their own stream draining, while start/stop/rm went throughrunDockerCliBlocking. Everything now goes throughrunDockerCli, which returns the exit code plus both streams;runDockerCliBlockingkeeps its contract on top of it. This is what makes the lifecycle testable without a live daemon.shutdown()is untouched:docker rmon a container that is already gone is already tolerated.Tests
DockerSandboxContainerReconcileTestruns the lifecycle against a fake daemon that refuses a claimed name the way the real CLI does:Against the previous code the first three fail with the reported
exit=125conflict; the fourth creates a duplicate container under the claimed name.Verification
mvn -B -pl agentscope-harness "-Dtest=DockerSandbox*" test: 30 tests, 0 failures (9 daemon-backed integration tests skipped as before).mvn -B -pl agentscope-harness test: full module suite.spotless:check: BUILD SUCCESS.Addresses #3644.