{"record":{"id":"7fc7d4d27f1d38d8","repo":"gastownhall/beads","slug":"failed-to-inspect-opened-directory-s-w","errorCode":null,"errorMessage":"failed to inspect opened directory %s: %w","messagePattern":"failed to inspect opened directory (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/permissions.go","lineNumber":75,"sourceCode":"\t\treturn false, fmt.Errorf(\"refusing to chmod %s: path is a symbolic link\", path)\n\t}\n\tif !info.IsDir() {\n\t\treturn false, fmt.Errorf(\"refusing to chmod %s: path is not a directory\", path)\n\t}\n\tperm := info.Mode().Perm()\n\tif perm&0077 == 0 {\n\t\treturn false, nil // no group or world-accessible bits\n\t}\n\n\tdir, err := openDir(path)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to open %s securely: %w\", path, err)\n\t}\n\tdefer func() { _ = dir.Close() }()\n\n\topenedInfo, err := dir.Stat()\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to inspect opened directory %s: %w\", path, err)\n\t}\n\tif !openedInfo.IsDir() || !os.SameFile(info, openedInfo) {\n\t\treturn false, fmt.Errorf(\"refusing to chmod %s: path changed during permission repair\", path)\n\t}\n\tif err := dir.Chmod(BeadsDirPerm); err != nil {\n\t\treturn false, fmt.Errorf(\"failed to chmod %s to %04o: %w\", path, BeadsDirPerm, err)\n\t}\n\treturn true, nil\n}\n","sourceCodeStart":57,"sourceCodeEnd":85,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/config/permissions.go#L57-L85","documentation":"After opening the directory securely, the code calls dir.Stat() on the handle to verify the opened target. This error wraps a failure of that stat — the opened directory handle could not be inspected, so the safety comparison against the original Lstat info cannot proceed.","triggerScenarios":"Calling FixBeadsDirPermissions where fstat on the opened directory descriptor fails — extremely rare; typically caused by the descriptor becoming invalid (close racing), fd exhaustion, or filesystem errors on exotic mounts.","commonSituations":"EMFILE/ENFILE (file descriptor table exhausted) so the handle is in a bad state; kernel or FUSE errors; heavily sandboxed environments blocking fstat.","solutions":["Re-run after checking system resource limits (ulimit -n) for fd exhaustion.","Retry the permission fix; the failure is usually transient.","As a fallback, chmod the directory directly from the shell: chmod 700 <path>."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"changed, err := config.FixBeadsDirPermissions(beadsDir)\nif err != nil && strings.Contains(err.Error(), \"failed to inspect opened directory\") {\n    // usually transient (fd pressure / fs hiccup): retry once after freeing resources\n    runtime.GC()\n    changed, err = config.FixBeadsDirPermissions(beadsDir)\n}","preventionTips":["Watch for fd leaks in long-running processes (ulimit -n).","Retry transient stat failures before surfacing to users."],"tags":["permissions","filesystem","syscall"],"backgroundTag":"stat-failed-on-open-handle","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}