{"record":{"id":"f171d5496c663992","repo":"Yeachan-Heo/oh-my-codex","slug":"refusing-cancellation-through-non-regular-run-stat","errorCode":null,"errorMessage":"Refusing cancellation through non-regular run state target: ${path}.","messagePattern":"Refusing cancellation through non-regular run state target: (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/cli/index.ts","lineNumber":8176,"sourceCode":"      }\n      candidates.push({ sessionDir, sessionId: record.session_id, record });\n    } catch (err) {\n      throw new Error(`Refusing cancellation because detached run authority is invalid: ${record.run_dir}.`, { cause: err });\n    }\n  }\n\n  if (candidates.length > 1) throw new Error(\"Refusing cancellation because multiple detached run authorities match.\");\n  if (candidates.length === 0) return null;\n  const [{ sessionDir, sessionId, record }] = candidates;\n  const refs: ModeStateFileRef[] = [];\n  const stateFiles = await readdir(sessionDir).catch(() => [] as string[]);\n  for (const file of stateFiles) {\n    if (!isModeStateFilename(file)) continue;\n    const path = join(sessionDir, file);\n    try {\n      const fileStat = lstatSync(path);\n      if (!fileStat.isFile() || fileStat.isSymbolicLink()) {\n        throw new Error(`Refusing cancellation through non-regular run state target: ${path}.`);\n      }\n      const canonicalFile = realpathSync(path);\n      if (!isCanonicalPathWithin(sessionDir, canonicalFile)) {\n        throw new Error(`Refusing cancellation outside authorized run session: ${path}.`);\n      }\n      refs.push({\n        mode: file.slice(0, -\"-state.json\".length),\n        path: canonicalFile,\n        scope: \"session\",\n      });\n    } catch (err) {\n      throw new Error(`Refusing cancellation because detached run state authority is invalid: ${path}.`, { cause: err });\n    }\n  }\n  return { refs: refs.sort((a, b) => a.mode.localeCompare(b.mode)), sessionId, sessionDir, record };\n}\n\nfunction assertCancellationAuthorityPath(baseStateDir: string, authorityRoot: string): string {","sourceCodeStart":8158,"sourceCodeEnd":8194,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/cli/index.ts#L8158-L8194","documentation":"Before unlinking a mode-state file, the code lstats it and requires a regular, non-symlink file; anything else (symlink, fifo, directory) is refused.","triggerScenarios":"A file in the session dir that passes isModeStateFilename but lstat shows it is a symlink or non-regular (fifo/socket/dir), e.g. someone symlinked a state file.","commonSituations":"Users sharing state via symlinks, backup tools converting files to symlinks, or tampered session dirs.","solutions":["Remove the offending symlink/special file from the session state dir manually","Ensure no tooling replaces state files with links (check backup/sync configs)","Retry cancellation after cleanup"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const st = lstatSync(p);\nif (!st.isFile() || st.isSymbolicLink()) throw new Error(`${p} is not a regular file — refusing`);","typeGuard":"function isRegularFile(p: string): boolean {\n  const st = lstatSync(p);\n  return st.isFile() && !st.isSymbolicLink();\n}","tryCatchPattern":null,"preventionTips":["Don't symlink state files for sharing","Check for special files after sync/restore tooling runs","Keep session dirs owned by one user/process"],"tags":["security","symlink","filesystem"],"backgroundTag":"refusing-non-regular-file","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}