{"record":{"id":"cb8d220cf02035f5","repo":"paperclipai/paperclip","slug":"invalid-worktree-seed-manifest-at-manifestpath","errorCode":null,"errorMessage":"Invalid worktree seed manifest at ${manifestPath}: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Invalid worktree seed manifest at (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":1901,"sourceCode":"  return nonEmpty(envEntries.PAPERCLIP_INSTANCE_ID)\n    ?? sanitizeWorktreeInstanceId(path.basename(path.dirname(path.resolve(configPath))));\n}\n\nfunction writeWorktreeSeedManifest(filePath: string, manifest: WorktreeSeedManifest): void {\n  mkdirSync(path.dirname(filePath), { recursive: true });\n  const temporaryPath = `${filePath}.${process.pid}.${randomUUID()}.tmp`;\n  writeFileSync(temporaryPath, `${JSON.stringify(manifest, null, 2)}\\n`, { mode: 0o600 });\n  renameSync(temporaryPath, filePath);\n}\n\nexport function readWorktreeSeedManifest(configPath: string): WorktreeSeedManifest | null {\n  const manifestPath = resolveWorktreeSeedMarkerPaths(configPath).manifest;\n  if (!existsSync(manifestPath)) return null;\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(readFileSync(manifestPath, \"utf8\"));\n  } catch (error) {\n    throw new Error(\n      `Invalid worktree seed manifest at ${manifestPath}: ${error instanceof Error ? error.message : String(error)}`,\n    );\n  }\n  const value = parsed as Partial<WorktreeSeedManifest>;\n  const diagnosticsValid = Array.isArray(value.diagnostics) && value.diagnostics.every((diagnostic) => (\n    diagnostic\n    && typeof diagnostic === \"object\"\n    && WORKTREE_SEED_PHASES.includes(diagnostic.phase)\n    && [\"started\", \"succeeded\", \"failed\"].includes(diagnostic.status)\n    && typeof diagnostic.at === \"string\"\n    && (diagnostic.message === undefined || typeof diagnostic.message === \"string\")\n  ));\n  const verifiedTerminalValid = value.state !== \"verified\" || (\n    value.phase === \"complete\"\n    && typeof value.snapshotAt === \"string\"\n    && value.snapshotAt.length > 0\n    && typeof value.migrationRevision === \"string\"\n    && value.migrationRevision.length > 0","sourceCodeStart":1883,"sourceCodeEnd":1919,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/cli/src/commands/worktree.ts#L1883-L1919","documentation":"readWorktreeSeedManifest() parses the seed manifest JSON next to the worktree config (resolved by resolveWorktreeSeedMarkerPaths). If the file exists but JSON.parse fails, the underlying parse error is wrapped with the manifest path. Manifest writes are atomic (temp file + rename, mode 0600), so corruption is external: manual edits, a non-atomic writer, or truncation.","triggerScenarios":"Any seed operation (ensureWorktreeSeeded, updateWorktreeSeedManifest, startWorktreeSeedAttempt) reading a manifest file whose bytes are not valid JSON — e.g. the file was hand-edited, truncated on crash, or rewritten by tooling that did partial writes.","commonSituations":"An operator edited the marker JSON to 'fix' a seed state; a disk-full event truncated the file; an external sync tool copied the file mid-write; a different CLI version wrote a format the parser chokes on at the JSON level.","solutions":["Delete the corrupt manifest file (path is in the error) and re-run the seed — it re-provisions from the registered source","Restore the manifest from a worktree backup if seed state must be preserved","Stop hand-editing or externally rewriting seed marker files; they are agent-writable diagnostics only"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import { readWorktreeSeedManifest, resolveWorktreeSeedMarkerPaths } from './worktree-lib';\n\nlet manifest = null;\ntry {\n  manifest = readWorktreeSeedManifest(configPath);\n} catch (error) {\n  // corrupt JSON: treat as absent, drop the marker, let the seed re-provision\n  rmSync(resolveWorktreeSeedMarkerPaths(configPath).manifest, { force: true });\n}","typeGuard":null,"tryCatchPattern":"Catch the 'Invalid worktree seed manifest' error, log the wrapped parse error, delete the named file, and re-run ensureWorktreeSeeded.","preventionTips":["Never hand-edit or externally rewrite seed marker files","Exclude worktree marker dirs from sync tools that can copy files mid-write"],"tags":["worktree","seed","manifest","json","corruption"],"backgroundTag":"malformed-json-file","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-21T17:58:32.592Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}