Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(sandbox): rebind a file op when the container has already stopped (#4749)
AsanoReo30ffee8c4ea1
diff --git a/internal/sandbox/docker_remote_client.go b/internal/sandbox/docker_remote_client.goindex 7b6bf1164..62522d245 100644--- a/internal/sandbox/docker_remote_client.go+++ b/internal/sandbox/docker_remote_client.go@@ -1049,13 +1049,30 @@ func (c *DockerRemoteClient) dockerFileOpFailed(}}-// containerVanished reports whether the Engine confirms the container is-// gone (404). A transport or daemon error returns false — only a confirmed-// disappearance may reclassify, keeping unknown errors on the safe side of-// CanReplaceRemoteBinding's allow-list.+// containerVanished reports whether the Engine confirms the container can no+// longer run this filesystem op. A 404 means the idle sweep already removed+// it. exited, dead, and removing mean the sweep stopped it and has not+// finished deleting it yet: exec then dies with a non-zero status while+// inspect still succeeds, which used to stay InvalidRequest and block the+// rebind (#4336). A transport or daemon error returns false — only a+// confirmed disappearance may reclassify, keeping unknown errors on the safe+// side of CanReplaceRemoteBinding's allow-list. paused and created stay+// put so a container that can be resumed is not replaced.func (c *DockerRemoteClient) containerVanished(ctx context.Context, id, op string) bool {- _, err := c.api.ContainerInspect(ctx, id, client.ContainerInspectOptions{})- return err != nil && IsRemoteNotFound(dockerError(op, err))+ inspected, err := c.api.ContainerInspect(ctx, id, client.ContainerInspectOptions{})+ if err != nil {+ return IsRemoteNotFound(dockerError(op, err))+ }+ state := inspected.Container.State+ if state == nil {+ return false+ }+ switch strings.ToLower(strings.TrimSpace(string(state.Status))) {+ case "exited", "dead", "removing":+ return true+ default:+ return false+ }}// MakeDir creates a directory (and its parents) inside the sandbox.diff --git a/internal/sandbox/docker_remote_client_test.go b/internal/sandbox/docker_remote_client_test.goindex 4fc11703e..6c17d088d 100644--- a/internal/sandbox/docker_remote_client_test.go+++ b/internal/sandbox/docker_remote_client_test.go@@ -1349,6 +1349,49 @@ func TestFileOpAgainstVanishedContainerRebinds(t *testing.T) {"the exit code must survive in the message (#3942 diagnostic gap)")}+// The idle sweep stops a container before it deletes it (#4336). Inspect+// still finds the container, so a 404-only check leaves the exec's exit 128+// as InvalidRequest and the session binding cannot be replaced.+func TestFileOpAgainstStoppedContainerRebinds(t *testing.T) {+ for _, status := range []string{"exited", "dead", "removing"} {+ t.Run(status, func(t *testing.T) {+ engine := newFakeDockerEngine()+ engine.execExit = 128+ engine.execStderr = ""+ engine.inspect["stopped-1"] = container.InspectResponse{+ ID: "stopped-1",+ State: &container.State{Status: container.ContainerState(status)},+ }+ docker := newTestDockerClient(t, engine)+ err := docker.MakeDir(context.Background(), testHandle("stopped-1"), "/workspace/input/b528f57f52be")+ require.True(t, IsRemoteNotFound(err), "got %+v", err)+ require.True(t, CanReplaceRemoteBinding(err), "got %+v", err)+ require.Contains(t, err.Error(), "vanished")+ })+ }+}++// A non-zero exec in a container that is still running, or only paused, is+// the command's own failure. Rebinding would throw away a sandbox that can+// still be used.+func TestFileOpOnLiveContainerKeepsBinding(t *testing.T) {+ for _, status := range []string{"running", "paused", "created"} {+ t.Run(status, func(t *testing.T) {+ engine := newFakeDockerEngine()+ engine.execExit = 128+ engine.execStderr = ""+ engine.inspect["container-1"] = container.InspectResponse{+ ID: "container-1",+ State: &container.State{Status: container.ContainerState(status)},+ }+ docker := newTestDockerClient(t, engine)+ err := docker.MakeDir(context.Background(), testHandle("container-1"), "/data/out")+ require.True(t, IsRemoteInvalidRequest(err), "got %+v", err)+ require.False(t, CanReplaceRemoteBinding(err))+ })+ }+}+// A genuine command failure with the container still alive keeps the// InvalidRequest classification — and with it the binding.func TestFileOpGenuineFailureKeepsBinding(t *testing.T) {