{"record":{"id":"2283ea5ddc635087","repo":"coleam00/Archon","slug":"detached-run-control-directory-is-owned-by-another","errorCode":null,"errorMessage":"Detached run control directory is owned by another user: ${directory}","messagePattern":"Detached run control directory is owned by another user: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/cli/src/utils/detached-run-control.ts","lineNumber":65,"sourceCode":"\nfunction endpointToken(runId: string): string {\n  return createHash('sha256').update(runId).digest('hex').slice(0, 32);\n}\n\nfunction controlDirectory(): string {\n  const uid = process.getuid?.();\n  const directory =\n    process.platform === 'win32'\n      ? join(tmpdir(), 'archon-run-control')\n      : `/tmp/archon-${uid === undefined ? 'user' : String(uid)}`;\n  mkdirSync(directory, { recursive: true, mode: 0o700 });\n  if (process.platform !== 'win32') {\n    const stat = lstatSync(directory);\n    if (!stat.isDirectory() || stat.isSymbolicLink()) {\n      throw new Error(`Detached run control path is not a directory: ${directory}`);\n    }\n    if (uid !== undefined && stat.uid !== uid) {\n      throw new Error(`Detached run control directory is owned by another user: ${directory}`);\n    }\n    if ((stat.mode & 0o077) !== 0) {\n      throw new Error(`Detached run control directory must have mode 0700: ${directory}`);\n    }\n  }\n  return directory;\n}\n\n/** Prove the marked POSIX owner has the process group that active cancellation will signal. */\nexport function assertDetachedRunProcessOwner(): void {\n  if (process.platform !== 'win32' && !processGroupExists(process.pid)) {\n    throw new Error(\n      `Refusing detached run control because process ${String(process.pid)} does not own process group ${String(process.pid)}`\n    );\n  }\n}\n\n/** A bounded, user-scoped endpoint: Unix socket on POSIX, named pipe on Windows. */","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/utils/detached-run-control.ts#L47-L83","documentation":"After creating the detached-run control directory, controlDirectory() verifies on POSIX that the directory's owning uid matches the current process uid. If another user owns the path, the runtime refuses to use it, since control files there (lock, socket) could be manipulated by that owner. This is a hardening check against pre-created or hijacked control directories in shared /tmp.","triggerScenarios":"stat.uid from lstatSync(directory) differs from process.getuid() while resolving a detached-run control path or lock path on a non-Windows platform.","commonSituations":"Another local user created /tmp/archon-<your-uid> first (spoofing the fixed per-uid name); running Archon under sudo after a first run created the directory as root; a shared container where the directory was created by a different uid mapping.","solutions":["Check ownership: ls -ln /tmp/archon-* and compare the uid with id -u.","Remove the mis-owned directory if no run is active: sudo rm -rf /tmp/archon-<uid>, then re-run as your user.","Avoid mixing sudo and non-sudo invocations of detached Archon runs; use a consistent user."],"exampleFix":"// before\n$ ls -ln /tmp | grep archon\ndrwx------ root root archon-1000\n// after\n$ sudo rm -rf /tmp/archon-1000\n$ archon run ...   # recreated as uid 1000","handlingStrategy":"try-catch","validationCode":"import { lstatSync } from 'node:fs';\nfunction ownedByMe(dir: string): boolean {\n  try { return lstatSync(dir).uid === process.getuid(); }\n  catch { return true; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const dir = controlDirectory();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('owned by another user')) {\n    console.error('Control dir mis-owned; remove it as its owner and re-run as your user.');\n  } else throw err;\n}","preventionTips":["Do not mix sudo and non-sudo Archon invocations.","Remove stale /tmp/archon-<uid> dirs when switching users.","Avoid shared multi-uid container setups for the same home/tmp."],"tags":["security","filesystem","posix","permissions"],"backgroundTag":"directory-owned-by-another-user","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}