{"record":{"id":"1e43c4a962df7531","repo":"coleam00/Archon","slug":"permission-denied-accessing-repository-at-repopa","errorCode":null,"errorMessage":"Permission denied accessing repository at ${repoPath}. Check file permissions and try again.","messagePattern":"Permission denied accessing repository at (.+?)\\. Check file permissions and try again\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/isolation/src/providers/worktree.ts","lineNumber":956,"sourceCode":"      // Only hard-reset for Archon-managed clones when creating isolated worktrees.\n      // Locally-registered repos keep the non-destructive fast-forward mode.\n      const isManagedClone = repoPath\n        .replace(/\\\\/g, '/')\n        .startsWith(getArchonWorkspacesPath().replace(/\\\\/g, '/'));\n      const { branch } = await syncWorkspace(\n        repoPath,\n        configuredBaseBranch ? toBranchName(configuredBaseBranch) : undefined,\n        { mode: isManagedClone ? 'reset' : 'fast-forward', remote }\n      );\n      getLog().debug({ repoPath, branch, remote }, 'workspace_synced');\n      return branch;\n    } catch (error) {\n      const err = error as Error & { code?: string };\n      const errorMessage = err.message.toLowerCase();\n\n      // Fatal errors - throw to prevent confusing downstream failures\n      if (err.code === 'EACCES' || errorMessage.includes('permission denied')) {\n        throw new Error(\n          `Permission denied accessing repository at ${repoPath}. ` +\n            'Check file permissions and try again.'\n        );\n      } else if (errorMessage.includes('not a git repository')) {\n        throw new Error(\n          `${repoPath} is not a valid git repository. ` +\n            'Ensure the workspace was cloned correctly.'\n        );\n      } else if (errorMessage.includes('configured base branch')) {\n        // Configured branch errors are fatal - user needs to fix their config\n        throw err;\n      } else {\n        // Network errors, timeouts — cannot guarantee correct start-point\n        throw new Error(\n          `Failed to fetch base branch from '${remote}': ${err.message}. ` +\n            'Check your network connection and remote configuration.'\n        );\n      }","sourceCodeStart":938,"sourceCodeEnd":974,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/isolation/src/providers/worktree.ts#L938-L974","documentation":"syncWorkspaceBeforeCreate wraps the workspace sync (fetch/reset against the base branch) and classifies failures. When the underlying git operation fails with EACCES or a 'permission denied' message, it rethrows a dedicated, human-readable permission error so the user fixes filesystem access before retrying rather than seeing a raw git failure.","triggerScenarios":"WorktreeProvider.create → syncWorkspaceBeforeCreate where reading/writing the repo at repoPath fails with err.code 'EACCES' or a message containing 'permission denied' (e.g. during `git fetch`, object writes, or lock-file creation).","commonSituations":"Workspace cloned by root but Archon runs as another user; read-only mounts; SSH key or credential-file permissions causing git to report access denied; group-write restrictions on `.git` inside the workspace.","solutions":["Fix ownership: `chown -R $(whoami) <repoPath>` or align the user Archon runs as with the workspace owner","Restore read/write permissions on the repo directory: `chmod -R u+rw <repoPath>`","Check for root-owned `.git` lock files or objects and re-own them","If the workspace lives on a read-only mount, move the Archon workspace path to a writable location"],"exampleFix":"# before\nls -l .git/HEAD  # owned by root, mode 644\n# after\nsudo chown -R $(id -u):$(id -g) /path/to/repo && chmod -R u+rw /path/to/repo","handlingStrategy":"try-catch","validationCode":"import { accessSync, constants } from 'node:fs';\nexport function assertRepoWritable(repoPath: string): void {\n  accessSync(repoPath, constants.R_OK | constants.W_OK);\n  accessSync(`${repoPath}/.git`, constants.R_OK | constants.W_OK);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const env = await provider.create(request);\n} catch (e) {\n  const msg = (e as Error).message;\n  if (msg.startsWith('Permission denied accessing repository')) {\n    console.error('Fix ownership/permissions on the repo and .git, then retry:', msg);\n  }\n  throw e;\n}","preventionTips":["Run Archon as the same user that owns the workspace clone","Avoid cloning workspaces with sudo","Watch for root-owned `.git` lock files after runs with elevated privileges","Ensure the Archon workspace path is on a writable mount"],"tags":["permissions","filesystem","git","sync"],"backgroundTag":"permission-denied","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}