{"record":{"id":"f29b559fd6ac1535","repo":"gastownhall/beads","slug":"inspect-quarantine-target-s-w","errorCode":null,"errorMessage":"inspect quarantine target %s: %w","messagePattern":"inspect quarantine target (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dbproxy/proxy/endpoint.go","lineNumber":702,"sourceCode":"\tdefault:\n\t\treturn fmt.Errorf(\"cannot spawn from proxy discovery status %s\", discovery.status)\n\t}\n\ttarget, err := quarantineRecord(rootDir, PIDFileName, time.Now())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"quarantine proxy record: %w\", err)\n\t}\n\tlog.Printf(\"dbproxy: preserved proxy record as %s\", target)\n\treturn nil\n}\n\nfunc quarantineRecord(rootDir, name string, now time.Time) (string, error) {\n\tsource := pidfile.Path(rootDir, name)\n\tfor stamp := now.Unix(); ; stamp++ {\n\t\ttarget := filepath.Join(rootDir, name+\".stale-\"+strconv.FormatInt(stamp, 10))\n\t\tif _, err := os.Lstat(target); err == nil {\n\t\t\tcontinue\n\t\t} else if !errors.Is(err, fs.ErrNotExist) {\n\t\t\treturn \"\", fmt.Errorf(\"inspect quarantine target %s: %w\", target, err)\n\t\t}\n\t\tif err := os.Rename(source, target); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"rename %s to %s: %w\", source, target, err)\n\t\t}\n\t\treturn target, nil\n\t}\n}\n\nfunc sweepOldQuarantines(rootDir string, now time.Time) error {\n\tentries, err := os.ReadDir(rootDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\tcutoff := now.Add(-quarantineRetention).Unix()\n\tprefixes := []string{\n\t\tPIDFileName + \".stale-\",\n\t\tserver.PIDFileName + \".stale-\",\n\t}","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dbproxy/proxy/endpoint.go#L684-L720","documentation":"quarantineRecord probes candidate target names <name>.stale-<unix-ts> with os.Lstat to find a free one; this error is returned when Lstat fails with something other than 'not exists', meaning it could not determine whether the target path is free. The quarantine rename is abandoned.","triggerScenarios":"os.Lstat(target) returns e.g. EACCES, ELOOP, or ENAMETOOLONG while iterating candidate stale-file names in the workspace root.","commonSituations":"Search-index or AV interfering with stat calls on Windows; a symlink loop or oddly-permissioned directory entry named like a stale quarantine file; an extremely long workspace path hitting ENAMETOOLONG.","solutions":["Inspect the wrapped Lstat error (ls -la the workspace for symlink loops or odd entries matching *.stale-*)","Remove or fix the problematic entry (broken symlink, wrong ownership) in the workspace root","Shorten the workspace path if ENAMETOOLONG is the cause","Re-run the command after the filesystem settles (transient EACCES from AV/indexers usually clears)"],"exampleFix":"// before\nif _, err := os.Lstat(target); err == nil {\n    continue\n} else if !errors.Is(err, fs.ErrNotExist) {\n    return \"\", fmt.Errorf(\"inspect quarantine target %s: %w\", target, err)\n}\n// after\nif _, err := os.Lstat(target); err == nil {\n    continue\n} else if errors.Is(err, fs.ErrNotExist) || errors.Is(err, syscall.EACCES) { // treat denied stat as free\n    _ = err\n} else {\n    return \"\", fmt.Errorf(\"inspect quarantine target %s: %w\", target, err)\n}","handlingStrategy":"validation","validationCode":"for _, e := range staleCandidates(root, PIDFileName) {\n    if fi, err := os.Lstat(e); err != nil && !errors.Is(err, fs.ErrNotExist) {\n        return fmt.Errorf(\"precheck: %s: %w\", e, err) // fix perms/symlinks first\n    }\n}","typeGuard":null,"tryCatchPattern":"target, err := quarantineRecord(root, PIDFileName, time.Now())\nif err != nil && strings.Contains(err.Error(), \"inspect quarantine target\") {\n    // broken symlink or EACCES on a stale-<ts> name: remove/fix it, then retry\n}","preventionTips":["Don't create symlink loops or directories named like *.stale-* in the workspace","Keep workspace paths short enough to avoid ENAMETOOLONG","Exclude workspace from AV/indexers that interfere with stat calls","Periodically remove abandoned .stale-* files from long-lived workspaces"],"tags":["filesystem","lstat","quarantine"],"backgroundTag":"file-stat-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}