Yeachan-Heo/oh-my-codex · critical · Error
Refusing cancellation through non-regular run state target:
Error message
Refusing cancellation through non-regular run state target: ${path}. What it means
Before unlinking a mode-state file, the code lstats it and requires a regular, non-symlink file; anything else (symlink, fifo, directory) is refused.
Source
Thrown at src/cli/index.ts:8176
}
candidates.push({ sessionDir, sessionId: record.session_id, record });
} catch (err) {
throw new Error(`Refusing cancellation because detached run authority is invalid: ${record.run_dir}.`, { cause: err });
}
}
if (candidates.length > 1) throw new Error("Refusing cancellation because multiple detached run authorities match.");
if (candidates.length === 0) return null;
const [{ sessionDir, sessionId, record }] = candidates;
const refs: ModeStateFileRef[] = [];
const stateFiles = await readdir(sessionDir).catch(() => [] as string[]);
for (const file of stateFiles) {
if (!isModeStateFilename(file)) continue;
const path = join(sessionDir, file);
try {
const fileStat = lstatSync(path);
if (!fileStat.isFile() || fileStat.isSymbolicLink()) {
throw new Error(`Refusing cancellation through non-regular run state target: ${path}.`);
}
const canonicalFile = realpathSync(path);
if (!isCanonicalPathWithin(sessionDir, canonicalFile)) {
throw new Error(`Refusing cancellation outside authorized run session: ${path}.`);
}
refs.push({
mode: file.slice(0, -"-state.json".length),
path: canonicalFile,
scope: "session",
});
} catch (err) {
throw new Error(`Refusing cancellation because detached run state authority is invalid: ${path}.`, { cause: err });
}
}
return { refs: refs.sort((a, b) => a.mode.localeCompare(b.mode)), sessionId, sessionDir, record };
}
function assertCancellationAuthorityPath(baseStateDir: string, authorityRoot: string): string {View on GitHub (pinned to 3ad79a8a6f)
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
Defensive patterns
Strategy: validation
Validate before calling
const st = lstatSync(p);
if (!st.isFile() || st.isSymbolicLink()) throw new Error(`${p} is not a regular file — refusing`); Type guard
function isRegularFile(p: string): boolean {
const st = lstatSync(p);
return st.isFile() && !st.isSymbolicLink();
} Prevention
- Don't symlink state files for sharing
- Check for special files after sync/restore tooling runs
- Keep session dirs owned by one user/process
When it happens
Trigger: 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.
Common situations: Users sharing state via symlinks, backup tools converting files to symlinks, or tampered session dirs.
Related errors
- Refusing cancellation through non-regular state target ${ref
- Refusing to use unsafe backup ancestor ${currentPath}.
- Unsafe Autopilot context directory: .omx is a symbolic link
- Unsafe Autopilot context directory: .omx/context is a symbol
- run directory escapes the authorized runs root
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/f171d5496c663992.
Report an issue: GitHub.