{"record":{"id":"9580543208ace2ec","repo":"gastownhall/beads","slug":"discover-proxy-from-s-w","errorCode":null,"errorMessage":"discover proxy from %s: %w","messagePattern":"discover proxy from (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dbproxy/proxy/endpoint.go","lineNumber":231,"sourceCode":"\t\treturn Endpoint{}, fmt.Errorf(\"read proxy stop epoch: %w\", err)\n\t}\n\tdeadline := time.Now().Add(openDeadline)\n\n\ttimeout := time.NewTimer(openDeadline)\n\tdefer timeout.Stop()\n\tpoll := time.NewTicker(openPollInterval)\n\tdefer poll.Stop()\n\n\twant := intendedUpstreamID(opts)\n\n\tvar lastSpawnErr error\n\tfor {\n\t\tdiscovery := readAndDial(rootDir)\n\t\tswitch discovery.status {\n\t\tcase adoptionAdopted:\n\t\t\treturn adoptedEndpoint(rootDir, want, discovery)\n\t\tcase adoptionIOErr:\n\t\t\treturn Endpoint{}, fmt.Errorf(\"discover proxy from %s: %w\", pidfile.Path(rootDir, PIDFileName), discovery.err)\n\t\t}\n\n\t\tlock, err := util.TryLock(filepath.Join(rootDir, LockFileName))\n\t\tswitch {\n\t\tcase err == nil:\n\t\t\t// Re-read under proxy.lock. Another opener may have replaced the\n\t\t\t// record after our lock-free discovery.\n\t\t\tdiscovery = readAndDial(rootDir)\n\t\t\tif discovery.status == adoptionAdopted {\n\t\t\t\tlock.Unlock()\n\t\t\t\treturn adoptedEndpoint(rootDir, want, discovery)\n\t\t\t}\n\t\t\tif discovery.status == adoptionIOErr {\n\t\t\t\tlock.Unlock()\n\t\t\t\treturn Endpoint{}, fmt.Errorf(\"discover proxy from %s under lock: %w\", pidfile.Path(rootDir, PIDFileName), discovery.err)\n\t\t\t}\n\n\t\t\tmarkerActive, markerErr := inspectSpawnMarkerLocked(rootDir)","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dbproxy/proxy/endpoint.go#L213-L249","documentation":"GetCreateDatabaseProxyServerEndpoint could not read or parse the proxy PID record in the workspace because of an I/O error. Before any locking or spawning happens, the library reads the pidfile to discover an already-running proxy; if that read fails (as opposed to the record simply being absent), it fails fast rather than attempting to spawn a new proxy, because a corrupt or unreadable record could hide a live proxy. The underlying cause (permission, stale record, etc.) is wrapped via %w so errors.Is works.","triggerScenarios":"Calling GetCreateDatabaseProxyServerEndpoint (e.g. via bd open/serve flows) when pidfile.Path(rootDir, PIDFileName) exists but readAndDial cannot read it: permissions changed, the record is being written concurrently, or the file is unreadable due to disk/filesystem issues. Note this is an IO error only — a missing record proceeds to spawn instead.","commonSituations":"Running bd as a different user than the one that created the proxy record (root vs user in containers/CI); NFS or Docker volume mounts with permission quirks; disk-full or read-only filesystem; antivirus/file-watcher holding the file open.","solutions":["Check permissions on the pidfile at <rootDir>/proxy.pid (or wherever pidfile.Path points) and the parent directory; chown/chmod so the current user can read it","If no proxy should be running, delete the unreadable record and retry","Verify the filesystem is writable and not full (df, mount -o ro checks)","If running in a container, ensure the same UID owns the workspace across invocations"],"exampleFix":"// before (running as wrong user)\n$ bd ready\nerror: discover proxy from /work/.beads/proxy.pid: open ...: permission denied\n// after\n$ ls -l /work/.beads/proxy.pid\n$ sudo chown -R $(id -u) /work/.beads\n$ bd ready","handlingStrategy":"validation","validationCode":"// Check the pidfile is readable before opening\npidPath := filepath.Join(rootDir, \"proxy.pid\")\nif _, err := os.Stat(pidPath); err == nil {\n    f, err := os.Open(pidPath)\n    if err != nil { return fmt.Errorf(\"proxy record unreadable: %w\", err) }\n    f.Close()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a single OS user for all bd invocations in a workspace","Add a preflight readability check of the .beads directory in CI","Avoid network filesystems for workspaces with background proxies"],"tags":["io","pidfile","proxy","filesystem"],"backgroundTag":"pidfile-io-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}