{"record":{"id":"791698a2fcd379af","repo":"vxcontrol/pentagi","slug":"failed-to-create-exec-process-w","errorCode":null,"errorMessage":"failed to create exec process: %w","messagePattern":"failed to create exec process: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/terminal.go","lineNumber":233,"sourceCode":"\n\t// Format command with working directory and ANSI styling\n\tstyledCommand := fmt.Sprintf(\"%s $ %s%s%s%s\", cwd, ansiColorInputCmd, command, ansiColorReset, ansiLineTerminator)\n\t_, err = t.tlp.PutMsg(ctx, database.TermlogTypeStdin, styledCommand, t.containerID, t.taskID, t.subtaskID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to put terminal log (stdin): %w\", err)\n\t}\n\n\ttimeout = t.normalizeExecTimeout(timeout)\n\n\tcreateResp, err := t.dockerClient.ContainerExecCreate(ctx, containerName, client.ExecCreateOptions{\n\t\tCmd:          cmd,\n\t\tAttachStdout: true,\n\t\tAttachStderr: true,\n\t\tWorkingDir:   cwd,\n\t\tTTY:          true,\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create exec process: %w\", err)\n\t}\n\n\tif detach {\n\t\tresultChan := make(chan execResult, 1)\n\t\tdetachedCtx := context.WithoutCancel(ctx)\n\n\t\tgo func() {\n\t\t\toutput, err := t.getExecResult(detachedCtx, createResp.ID, timeout)\n\t\t\tresultChan <- execResult{output: output, err: err}\n\t\t}()\n\n\t\tselect {\n\t\tcase result := <-resultChan:\n\t\t\tif result.err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"command failed: %w: %s\", result.err, result.output)\n\t\t\t}\n\t\t\tif result.output == \"\" {\n\t\t\t\treturn \"Command completed in background with exit code 0\", nil","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/terminal.go#L215-L251","documentation":"ExecCommand calls dockerClient.ContainerExecCreate to spawn the sh -c process inside the terminal container. If the Docker API rejects the exec creation, the call fails with \"failed to create exec process: %w\" wrapping the Docker error.","triggerScenarios":"ContainerExecCreate failing because the container name doesn't resolve (container removed/renamed), the container just stopped between the running-check and this call, an invalid working directory (cwd doesn't exist in the container), or the Docker daemon erroring/being unreachable.","commonSituations":"Race where the container exits between IsContainerRunning and exec creation; PrimaryTerminalName container removed externally; cwd pointing to a path not present in the image; Docker daemon OOM or restarting; malformed command leading to API rejection.","solutions":["Read the wrapped Docker error for the specific API cause","Confirm the container (PrimaryTerminalName result) still exists and is running right before exec","Validate that the cwd path exists inside the container image","Recreate the terminal container and retry; check daemon health (docker info)"],"exampleFix":"// before\nExecCreateOptions{WorkingDir: \"/nonexistent\", ...} // failed to create exec process: ... no such directory\n// after\ncwd := docker.WorkFolderPathInContainer // guaranteed to exist in the image\ncreateResp, err := dockerClient.ContainerExecCreate(ctx, containerName, client.ExecCreateOptions{WorkingDir: cwd, ...})","handlingStrategy":"retry","validationCode":"exists, err := dockerClient.IsContainerRunning(ctx, containerLID)\nif err != nil || !exists {\n    return fmt.Errorf(\"container not ready for exec: %w\", err)\n}\nif cwd != \"\" {\n    if err := ensureDirInContainer(ctx, containerName, cwd); err != nil {\n        return fmt.Errorf(\"cwd %q missing in container: %w\", cwd, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"out, err := term.ExecCommand(ctx, cwd, cmd, false, timeout)\nif err != nil && strings.HasPrefix(err.Error(), \"failed to create exec process:\") {\n    // likely a race with container exit or bad cwd — recreate sandbox, then retry once\n    if rerr := term.EnsureRunning(ctx); rerr == nil {\n        out, err = term.ExecCommand(ctx, cwd, cmd, false, timeout)\n    }\n}","preventionTips":["Re-verify container state immediately before exec to narrow the race window","Default cwd to docker.WorkFolderPathInContainer and validate any custom path exists in the image","Monitor Docker daemon health and restarts (exec creation fails while the daemon is down)","Keep the PrimaryTerminalName naming scheme stable across the codebase so lookups don't miss"],"tags":["docker","exec","container","api"],"backgroundTag":"docker-exec-create-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}