{"record":{"id":"99b3f10788c3c235","repo":"paperclipai/paperclip","slug":"opencode-target-executable-is-not-a-regular-file","errorCode":null,"errorMessage":"OpenCode target executable is not a regular file","messagePattern":"OpenCode target executable is not a regular file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/paperclip-runner/scripts/materialize-opencode-binary.mjs","lineNumber":64,"sourceCode":"  }\n\n  const packageRoot = realpathSync(\n    options.packageRoot ??\n      resolve(import.meta.dirname, \"../node_modules/opencode-ai\"),\n  );\n  const dependencyRoot = dirname(packageRoot);\n  const baselineRoot = realpathSync(join(dependencyRoot, BASELINE_PACKAGE));\n  assertPackage(packageRoot, \"opencode-ai\");\n  assertPackage(baselineRoot, BASELINE_PACKAGE);\n\n  const source = join(baselineRoot, \"bin\", \"opencode\");\n  const target = join(packageRoot, \"bin\", \"opencode.exe\");\n  if (!lstatSync(source).isFile()) {\n    throw new Error(\"Pinned OpenCode source executable is not a regular file\");\n  }\n  if (existsSync(target)) {\n    if (!lstatSync(target).isFile()) {\n      throw new Error(\"OpenCode target executable is not a regular file\");\n    }\n    unlinkSync(target);\n  }\n  try {\n    linkSync(source, target);\n  } catch (error) {\n    const code = error?.code;\n    if (!new Set([\"EACCES\", \"EMLINK\", \"EPERM\", \"EXDEV\"]).has(code)) {\n      throw error;\n    }\n    copyFileSync(source, target);\n  }\n  chmodSync(target, 0o755);\n\n  const sourceDigest = sha256(source);\n  const targetDigest = sha256(target);\n  if (sourceDigest !== targetDigest) {\n    throw new Error(\"Materialized OpenCode executable digest mismatch\");","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/paperclip-runner/scripts/materialize-opencode-binary.mjs#L46-L82","documentation":"When the materialized target bin/opencode.exe already exists, the script requires it to be a regular file before unlinking and re-linking. If the existing target is a symlink, directory, or other non-regular file, it refuses to delete it blindly and throws.","triggerScenarios":"A previous failed/partial materialization or an external tool left opencode.exe in the package's bin directory as a symlink or directory, and materializePinnedOpenCodeBinary runs again.","commonSituations":"A leftover directory named opencode.exe from a bad unzip; a wrapper script or tool replaced the binary with a symlink; an interrupted prior run left corrupt node_modules state.","solutions":["Inspect 'ls -la <packageRoot>/bin/' and manually remove the non-regular opencode.exe ('rm -rf' for a directory/symlink).","Re-run materializePinnedOpenCodeBinary so it creates a fresh hard link from the verified source.","If node_modules state is suspect, reinstall the opencode-ai package to reset its bin directory.","Audit what created the non-file target and stop it from writing into the package bin dir."],"exampleFix":"# before (broken state)\n$ ls -la bin/opencode.exe  # symlink or directory\n# after\n$ rm -rf bin/opencode.exe\n$ node scripts/materialize-opencode-binary.mjs","handlingStrategy":"validation","validationCode":"import { existsSync, lstatSync, rmSync } from 'node:fs';\nconst target = join(pkgRoot, 'bin', 'opencode.exe');\nif (existsSync(target) && !lstatSync(target).isFile()) {\n  rmSync(target, { recursive: true }); // clear non-regular stale target first\n}","typeGuard":"function isClearableTarget(p) {\n  try { return !existsSync(p) || lstatSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":"try {\n  materializePinnedOpenCodeBinary();\n} catch (err) {\n  if (err.message === 'OpenCode target executable is not a regular file') {\n    rmSync(join(pkgRoot, 'bin', 'opencode.exe'), { recursive: true, force: true });\n    materializePinnedOpenCodeBinary();\n  } else throw err;\n}","preventionTips":["Clean node_modules/bin state after interrupted builds.","Do not let wrapper scripts write files named opencode.exe into package bin dirs.","Reinstall the package when bin contents look suspicious.","Check 'ls -la bin/' before re-running materialization."],"tags":["filesystem","state","binary"],"backgroundTag":"invalid-state-transition","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}