{"record":{"id":"e8db79a000e3ffee","repo":"paperclipai/paperclip","slug":"migration-journal-has-no-applied-revision","errorCode":null,"errorMessage":"Migration journal has no applied revision.","messagePattern":"Migration journal has no applied revision\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":1489,"sourceCode":"    migrationState.appliedMigrations.length,\n  );\n  const appliedMigrationNames = new Set(migrationState.appliedMigrations);\n  if (\n    appliedMigrationNames.size !== expectedAppliedPrefix.length ||\n    expectedAppliedPrefix.some((migration) => !appliedMigrationNames.has(migration))\n  ) {\n    throw new Error(\"Migration journal is not a prefix of this Paperclip checkout's migration journal.\");\n  }\n\n  if (requirement === \"upToDate\" && migrationState.status !== \"upToDate\") {\n    throw new Error(\n      `Migration journal is not current (${migrationState.pendingMigrations.length} pending migration(s)).`,\n    );\n  }\n\n  const migrationRevision = expectedAppliedPrefix.at(-1);\n  if (!migrationRevision) {\n    throw new Error(\"Migration journal has no applied revision.\");\n  }\n  return migrationRevision;\n}\n\n/**\n * Markerless worktrees predate the versioned seed manifest. Adopt one only\n * after proving that its configured database already has a compatible\n * migration journal and the core Paperclip tables. The physical PG_VERSION\n * check prevents this read-only probe from initializing a missing embedded\n * database and then mistaking that empty cluster for legacy evidence.\n */\nexport async function inspectLegacyWorktreeDatabase(\n  configPath: string,\n): Promise<LegacyWorktreeDatabaseEvidence | null> {\n  const config = readConfig(configPath);\n  if (!config) return null;\n\n  const envEntries = readPaperclipEnvEntries(resolvePaperclipEnvFile(configPath));","sourceCodeStart":1471,"sourceCodeEnd":1507,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/cli/src/commands/worktree.ts#L1471-L1507","documentation":"Final rule of resolveWorktreeSeedMigrationRevision(): expectedAppliedPrefix is empty, i.e. the database has zero applied migrations. Legacy worktree adoption (inspectLegacyWorktreeDatabase, per its doc comment) must prove the cluster was previously seeded by finding at least one applied revision; an empty journal means there is no legacy evidence to adopt. A physical PG_VERSION check upstream prevents this probe from initializing a missing cluster and mistaking it for legacy.","triggerScenarios":"Adopting a markerless worktree whose embedded database has an empty migration journal — a cluster that exists on disk but was never migrated (interrupted first seed, manually pre-created data dir).","commonSituations":"A worktree data dir left behind by a failed first seed; someone manually initialized the embedded cluster; a wiped database inside an old data directory.","solutions":["Provision a fresh seed (markWorktreeSeedPending + seed from the registered source) instead of adopting this database","Point the worktree at its real previously-seeded data dir if one exists","If the data dir is disposable, remove it and let the seed initialize a new one"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const state = await inspectMigrations(/* target connection */);\nif (state.appliedMigrations.length === 0) {\n  // no legacy evidence: skip adoption and provision a fresh seed\n}","typeGuard":null,"tryCatchPattern":"On 'no applied revision' during legacy adoption, switch to fresh provisioning — an empty cluster is a new worktree, not a legacy one.","preventionTips":["Do not pre-create or manually initialize worktree embedded data dirs","Treat an empty migration journal as 'new', never as 'legacy'"],"tags":["migrations","worktree","seed","legacy-adoption","database"],"backgroundTag":"no-applied-migrations","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-21T17:58:32.592Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}