{"record":{"id":"3dc659e54a885499","repo":"gastownhall/beads","slug":"beadsdir-no-longer-exists-s","errorCode":null,"errorMessage":"BeadsDir no longer exists: %s","messagePattern":"BeadsDir no longer exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/beads/context.go","lineNumber":535,"sourceCode":"\t// 6. Get CWD's repo root (same as workspace in this case)\n\tcwdRepoRoot := git.GetRepoRoot()\n\n\treturn &RepoContext{\n\t\tBeadsDir:     beadsDir,\n\t\tRepoRoot:     repoRoot,\n\t\tCWDRepoRoot:  cwdRepoRoot,\n\t\tIsRedirected: false, // Workspace-specific context is never \"redirected\"\n\t\tIsWorktree:   isWorktree,\n\t}, nil\n}\n\n// Validate checks if the cached context is still valid.\n//\n// Returns an error if BeadsDir or RepoRoot no longer exist. This is useful\n// for long-running processes that need to detect when context becomes stale (DMN-002).\nfunc (rc *RepoContext) Validate() error {\n\tif _, err := os.Stat(rc.BeadsDir); os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"BeadsDir no longer exists: %s\", rc.BeadsDir)\n\t}\n\tif _, err := os.Stat(rc.RepoRoot); os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"RepoRoot no longer exists: %s\", rc.RepoRoot)\n\t}\n\treturn nil\n}\n\n// GitOutput runs a git command in the beads repository and returns its output.\n//\n// This is a convenience wrapper around GitCmd that captures stdout.\n// Returns an error if the command fails or produces no output.\n//\n// Pattern:\n//\n//\toutput, err := rc.GitOutput(ctx, \"config\", \"--get\", \"beads.role\")\n//\tif err != nil {\n//\t    // Config key not set or git error\n//\t}","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/beads/context.go#L517-L553","documentation":"RepoContext.Validate() re-checks that the cached BeadsDir still exists on disk; if os.Stat reports it missing, the cached context is stale and this error is returned. It exists for long-running processes (per DMN-002) that must detect when the beads directory was deleted or moved after the context was built. The caller should rebuild the context.","triggerScenarios":"Calling rc.Validate() on a RepoContext whose rc.BeadsDir path no longer exists — the .beads directory was deleted, renamed, or unmounted after the context was cached.","commonSituations":"A long-running daemon holding a RepoContext while the repo was deleted or moved; an unmounted network/external drive hosting the beads dir; a container restart with an ephemeral filesystem; tests deleting temp dirs while a cached context still points at them.","solutions":["Re-run GetRepoContextForWorkspace (or bd init) to rebuild the context after confirming where the beads dir went","Check whether the path was deleted/moved (`ls <reported path>`) and restore or re-create it with `bd init`","In long-running processes, catch this error and invalidate the cache, then re-resolve the context before the next operation","Verify mounts/volumes that host the beads directory are attached"],"exampleFix":"// before\ncachedCtx.DoWork()\n// after\nif err := cachedCtx.Validate(); err != nil {\n    cachedCtx, err = beads.GetRepoContextForWorkspace(cwd) // rebuild stale context\n}\n","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(cached.BeadsDir); os.IsNotExist(err) {\n    cached, err = beads.GetRepoContextForWorkspace(cwd) // rebuild\n}","typeGuard":null,"tryCatchPattern":"if err := rc.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"BeadsDir no longer exists\") {\n        rc, err = beads.GetRepoContextForWorkspace(cwd)\n    }\n}","preventionTips":["Call Validate() before each use in long-running processes (DMN-002 pattern)","Avoid deleting/relocating .beads while daemons hold a context","Keep beads dirs on stable, always-mounted storage","Rebuild context after any repo move or unmount"],"tags":["beads","stale-context","filesystem","cache"],"backgroundTag":"stale-context-path-missing","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}