Fission-AI/OpenSpec · error · Error

Cannot fork schema with a linked directory cycle

Error message

Cannot fork schema with a linked directory cycle: ${src}

What it means

Cycle guard in copyDirRecursive during schema fork: the canonical path of the directory being copied is already in the ancestors set, meaning symlinked directories form a loop that would recurse forever. Thrown to stop the copy instead of exhausting the filesystem.

Solutions

  1. Remove the cyclic symlinks inside the schema directory before forking
  2. Flatten the schema directory so it contains no directory symlink loops
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/commands/schema.ts:271 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Fission-AI/OpenSpec@6926ccb18a (2026-08-25). Data as JSON: /api/errors/48614aef97aa615a. Report an issue: GitHub.

Appendix: source

Thrown at src/commands/schema.ts:271

    return canonicalPath;
  } catch (error) {
    const detail = error instanceof Error ? error.message : String(error);
    throw new Error(
      `Cannot fork schema with linked or unsupported entry: ${sourcePath}: ${detail}`,
      { cause: error }
    );
  }
}

function copyDirRecursive(
  src: string,
  dest: string,
  allowedRoot = src,
  ancestors = new Set<string>()
): void {
  const canonicalSrc = resolveSchemaCopyPath(allowedRoot, src);
  if (ancestors.has(canonicalSrc)) {
    throw new Error(`Cannot fork schema with a linked directory cycle: ${src}`);
  }
  ancestors.add(canonicalSrc);
  fs.mkdirSync(dest, { recursive: true });

  try {
    const entries = fs.readdirSync(src, { withFileTypes: true });
    for (const entry of entries) {
      const srcPath = path.join(src, entry.name);
      const destPath = path.join(dest, entry.name);
      const canonicalEntry = resolveSchemaCopyPath(allowedRoot, srcPath);
      const stats = fs.statSync(canonicalEntry);

      if (stats.isDirectory()) {
        copyDirRecursive(canonicalEntry, destPath, allowedRoot, ancestors);
      } else if (stats.isFile()) {
        // Dereference confined links so the fork is an independent schema.
        fs.copyFileSync(canonicalEntry, destPath);
      } else {

View on GitHub (pinned to 6926ccb18a)