{"record":{"id":"15a6e596400e3c9d","repo":"JuliusBrussee/caveman","slug":"native-runtime-chmod-dir-w","errorCode":null,"errorMessage":"native runtime chmod dir: %w","messagePattern":"native runtime chmod dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/nativeruntime/server_unix.go","lineNumber":40,"sourceCode":"}\n\n// Serve binds runtime transport for current platform.\nfunc Serve(ctx context.Context, home string, runtime *Runtime) error {\n\treturn ServeUnix(ctx, SocketPath(home), runtime)\n}\n\n// ServeUnix exposes one-request-per-connection JSON over a user-only Unix\n// socket. Runtime errors close or fail-open the individual call; they never stop\n// the coding agent or the provider proxy.\nfunc ServeUnix(ctx context.Context, path string, runtime *Runtime) error {\n\tif runtime == nil || runtime.store == nil {\n\t\treturn errors.New(\"native runtime: store is required\")\n\t}\n\tif err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {\n\t\treturn fmt.Errorf(\"native runtime mkdir: %w\", err)\n\t}\n\tif err := os.Chmod(filepath.Dir(path), 0o700); err != nil {\n\t\treturn fmt.Errorf(\"native runtime chmod dir: %w\", err)\n\t}\n\tif _, err := os.Stat(path); err == nil {\n\t\tconn, dialErr := net.DialTimeout(\"unix\", path, 50*time.Millisecond)\n\t\tif dialErr == nil {\n\t\t\t_ = conn.Close()\n\t\t\treturn errors.New(\"native runtime: socket already active\")\n\t\t}\n\t\tif err := os.Remove(path); err != nil {\n\t\t\treturn fmt.Errorf(\"native runtime remove stale socket: %w\", err)\n\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"native runtime inspect socket: %w\", err)\n\t}\n\tlistener, err := net.Listen(\"unix\", path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"native runtime listen: %w\", err)\n\t}\n\tdefer listener.Close()","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/nativeruntime/server_unix.go#L22-L58","documentation":"After creating the socket parent directory, ServeUnix explicitly Chmods it to 0700 so only the current user can access the socket. Failure to set this permission is wrapped as \"native runtime chmod dir\". It enforces the security boundary between the runtime and other local users.","triggerScenarios":"os.Chmod(filepath.Dir(path), 0o700) returns an error: the directory is owned by another user, the filesystem does not support chmod (some network mounts), or the process lacks ownership.","commonSituations":"Socket directory created earlier by root or another account; NFS/CIFS or Windows-mounted filesystems where chmod is unsupported; running the runtime under a service account after a manual setup as root.","solutions":["Take ownership of the socket directory: chown/chmod it so the runtime user can set 0700","Remove the stale directory created by another user and let ServeUnix recreate it","Use a socket path on a local filesystem that supports permission changes"],"exampleFix":"// shell fix, then rerun\nsudo chown -R \"$USER\" ~/.caveman && chmod 700 ~/.caveman","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(socketPath)\nif st, err := os.Stat(dir); err != nil {\n\treturn err\n} else if st.Mode().Perm() != 0o700 {\n\tos.Chmod(dir, 0o700) // normalize beforehand\n}","typeGuard":null,"tryCatchPattern":"if err := nativeruntime.ServeUnix(ctx, path, rt); err != nil {\n\tif strings.Contains(err.Error(), \"chmod dir\") {\n\t\t// fall back to a fresh user-owned temp dir\n\t\tpath = filepath.Join(os.TempDir(), \"nativeruntime.sock\")\n\t\treturn nativeruntime.ServeUnix(ctx, path, rt)\n\t}\n\treturn err\n}","preventionTips":["Always run the runtime as the same user that owns the socket directory","Avoid network filesystems (NFS/CIFS) for socket paths","Reset directory ownership after running setup as root"],"tags":["filesystem","permissions","chmod"],"backgroundTag":"permission-denied","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}