{"record":{"id":"2b334588463989f8","repo":"Tencent/WeKnora","slug":"daemon-returned-no-container-state","errorCode":null,"errorMessage":"daemon returned no container state","messagePattern":"daemon returned no container state","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/docker_remote_client.go","lineNumber":388,"sourceCode":"\t}\n\treturn \"bridge\"\n}\n\n// Connect re-attaches to an existing container, resuming it when the daemon\n// or the host stopped it. This is the docker equivalent of E2B's auto-resume:\n// a stopped container keeps its filesystem, so the session continues where it\n// left off instead of losing everything it installed.\nfunc (c *DockerRemoteClient) Connect(\n\tctx context.Context,\n\tsandboxID string,\n) (RemoteSandboxHandle, error) {\n\tinspected, err := c.api.ContainerInspect(ctx, sandboxID, client.ContainerInspectOptions{})\n\tif err != nil {\n\t\treturn nil, dockerError(\"Connect\", err)\n\t}\n\tstate := inspected.Container.State\n\tif state == nil {\n\t\treturn nil, dockerError(\"Connect\", errors.New(\"daemon returned no container state\"))\n\t}\n\tswitch dockerStateOf(state.Status) {\n\tcase RemoteStateTerminal:\n\t\treturn nil, &RemoteError{\n\t\t\tKind:     RemoteErrorKindTerminal,\n\t\t\tProvider: SandboxTypeDocker,\n\t\t\tOp:       \"Connect\",\n\t\t\tMessage:  \"container is dead\",\n\t\t}\n\tcase RemoteStatePaused:\n\t\tif err := c.resume(ctx, inspected.Container.ID, string(state.Status), \"Connect\"); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := c.waitUntilRunning(ctx, inspected.Container.ID, \"Connect\"); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\tc.sweepInBackground(ctx)","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/docker_remote_client.go#L370-L406","documentation":"Connect inspects the container via the Docker API and switches on its State to decide whether to restart, unpause, or adopt it. If the daemon's inspect response has a nil State, there is no status to act on, so Connect fails with this error wrapped by dockerError. It indicates a daemon/consistency anomaly, not normal lifecycle states.","triggerScenarios":"Calling Connect (TestDockerClientConnect* paths) when ContainerInspect returns a Container whose State field is nil — e.g. a stubbed/fake API returning an incomplete inspect result, or a daemon race where the container record exists without state.","commonSituations":"Testing against mock ContainerInspect implementations that forget to populate State; Docker daemon version changes that alter inspect payload shape; transient daemon inconsistency right after container creation.","solutions":["Inspect the ContainerInspect response/daemon and ensure State is populated (the inspect payload should include state)","Retry Connect — a transient daemon race may resolve on a subsequent inspect","If this comes from a fake/test API, fix the stub to return a State (e.g. Status running/stopped)","Check Docker daemon version compatibility with the API client"],"exampleFix":"// stubbed inspect in tests\n// before\nreturn &client.ContainerInspectResult{Container: &client.ContainerData{}}, nil\n// after\nreturn &client.ContainerInspectResult{Container: &client.ContainerData{State: &client.ContainerState{Status: \"running\"}}}, nil","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func hasContainerState(c *client.ContainerData) bool { return c != nil && c.State != nil }","tryCatchPattern":"handle, err := sbx.Connect(ctx, id)\nvar rerr *sandbox.RemoteError\nif errors.As(err, &rerr) && strings.Contains(rerr.Error(), \"daemon returned no container state\") {\n    // transient daemon anomaly: retry once, then surface\n    handle, err = sbx.Connect(ctx, id)\n}\nif err != nil { return err }","preventionTips":["Retry Connect once on daemon-state anomalies before failing","In tests, make fake ContainerInspect responses fully populate State","Pin a Docker daemon version compatible with the API client and monitor daemon health"],"tags":["go","sandbox","docker","daemon","inspect"],"backgroundTag":"docker-daemon-unexpected-response","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}