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

  1. Remove the offending symlink/special file from the session state dir manually
  2. Ensure no tooling replaces state files with links (check backup/sync configs)
  3. 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

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


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/f171d5496c663992. Report an issue: GitHub.