{"record":{"id":"d4a7f6a673add312","repo":"paperclipai/paperclip","slug":"target-worktree-database-appears-to-be-running-pi","errorCode":null,"errorMessage":"Target worktree database appears to be running (pid ${runningTargetPid}). Stop Paperclip in ${targetEndpoint.rootPath} before reseeding, or re-run with --allow-live-target if you want to override this guard.","messagePattern":"Target worktree database appears to be running \\(pid (.+?)\\)\\. Stop Paperclip in (.+?) before reseeding, or re-run with --allow-live-target if you want to override this guard\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":3431,"sourceCode":"    throw new Error(`Source config not found at ${source.configPath}.`);\n  }\n\n  const targetConfig = readConfig(targetEndpoint.configPath);\n  if (!targetConfig) {\n    throw new Error(`Target config not found at ${targetEndpoint.configPath}.`);\n  }\n  const sourceConfig = readConfig(source.configPath);\n  if (!sourceConfig) {\n    throw new Error(`Source config not found at ${source.configPath}.`);\n  }\n\n  const targetPaths = resolveWorktreeReseedTargetPaths({\n    configPath: targetEndpoint.configPath,\n    rootPath: targetEndpoint.rootPath,\n  });\n  const runningTargetPid = resolveRunningEmbeddedPostgresPid(targetConfig);\n  if (runningTargetPid && !opts.allowLiveTarget) {\n    throw new Error(\n      `Target worktree database appears to be running (pid ${runningTargetPid}). Stop Paperclip in ${targetEndpoint.rootPath} before reseeding, or re-run with --allow-live-target if you want to override this guard.`,\n    );\n  }\n\n  const confirmed = opts.yes\n    ? true\n    : await p.confirm({\n      message: `Overwrite the isolated Paperclip DB for ${targetEndpoint.label} from ${source.label} using ${seedMode} seed mode?`,\n      initialValue: false,\n    });\n  if (p.isCancel(confirmed) || !confirmed) {\n    p.log.warn(\"Reseed cancelled.\");\n    return;\n  }\n\n  if (runningTargetPid && opts.allowLiveTarget) {\n    p.log.warning(`Proceeding even though the target embedded PostgreSQL appears to be running (pid ${runningTargetPid}).`);\n  }","sourceCodeStart":3413,"sourceCodeEnd":3449,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/worktree.ts#L3413-L3449","documentation":"Thrown by runWorktreeReseed when resolveRunningEmbeddedPostgresPid(targetConfig) returns a live pid and --allow-live-target is not set. resolveRunningEmbeddedPostgresPid only applies to embedded-postgres mode targets and reads postmaster.pid, and readRunningPostmasterPid additionally verifies liveness via process.kill(pid, 0). The guard prevents overwriting a running database, which could corrupt data or fail mid-copy. --allow-live-target is the documented escape hatch.","triggerScenarios":"Calling `worktree reseed` against a target worktree whose embedded PostgreSQL is currently running (the Paperclip server in that worktree is up), without --allow-live-target. The pid in postmaster.pid must belong to a live process.","commonSituations":"A developer left `paperclipai dev` (or a server) running in the target worktree and tries to reseed it from another terminal. Or a background agent runtime holds the embedded DB open.","solutions":["Stop Paperclip in the target worktree (e.g. stop the dev server / agent runtime) and retry.","Re-run with --allow-live-target if you accept the risk of overwriting a live DB.","Check for the live pid with `ps -p <pid>` to confirm which process holds it before deciding."],"exampleFix":"// before\npaperclipai worktree reseed --from-config src.json --to /path/to/target\n// after (stop the target first)\n# in target worktree: stop paperclipai dev, then\npaperclipai worktree reseed --from-config src.json --to /path/to/target\n// or override the guard\npaperclipai worktree reseed --from-config src.json --to /path/to/target --allow-live-target","handlingStrategy":"validation","validationCode":"import fs from \"node:fs\";\nimport path from \"node:path\";\n\nfunction readLivePostmasterPid(dataDir: string): number | null {\n  const pidFile = path.resolve(dataDir, \"postmaster.pid\");\n  if (!fs.existsSync(pidFile)) return null;\n  const pid = Number(fs.readFileSync(pidFile, \"utf8\").split(\"\\n\")[0]?.trim());\n  if (!Number.isInteger(pid) || pid <= 0) return null;\n  try { process.kill(pid, 0); return pid; } catch { return null; }\n}\n\n// before reseed, read targetConfig.database.embeddedPostgresDataDir and check:\nconst livePid = readLivePostmasterPid(targetConfig.database.embeddedPostgresDataDir);\nif (livePid && !opts.allowLiveTarget) {\n  throw new Error(`Stop the target embedded PostgreSQL (pid ${livePid}) before reseeding, or pass --allow-live-target.`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stop `paperclipai dev` and any agent runtime in the target worktree before reseeding.","Script a pre-check using readRunningPostmasterPid semantics (pid alive via process.kill(pid,0)) before invoking reseed.","Use --allow-live-target only when you understand the data-loss risk."],"tags":["worktree","cli","reseed","postgres","safety-guard"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}