{"record":{"id":"fba3760a36e038f8","repo":"paperclipai/paperclip","slug":"migration-journal-is-not-a-prefix-of-this-papercli","errorCode":null,"errorMessage":"Migration journal is not a prefix of this Paperclip checkout's migration journal.","messagePattern":"Migration journal is not a prefix of this Paperclip checkout's migration journal\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":1478,"sourceCode":"  deploymentMode: PaperclipConfig[\"server\"][\"deploymentMode\"],\n): boolean {\n  return deploymentMode === \"authenticated\";\n}\n\nexport function resolveWorktreeSeedMigrationRevision(\n  migrationState: Awaited<ReturnType<typeof inspectMigrations>>,\n  requirement: \"sourcePrefix\" | \"upToDate\",\n): string {\n  const expectedAppliedPrefix = migrationState.availableMigrations.slice(\n    0,\n    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","sourceCodeStart":1460,"sourceCodeEnd":1496,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/cli/src/commands/worktree.ts#L1460-L1496","documentation":"resolveWorktreeSeedMigrationRevision() validates that the migrations applied in a database form a contiguous prefix of this checkout's migration journal (packages/db drizzle migrations). It builds expectedAppliedPrefix = availableMigrations sliced to appliedMigrations.length and requires the applied set to match it exactly. A mismatch means the database's journal diverged from this checkout (extra, renamed, reordered, or skipped migrations), so seed/legacy-adoption logic cannot map it to a revision.","triggerScenarios":"Calling resolveWorktreeSeedMigrationRevision(migrationState, 'sourcePrefix' | 'upToDate') during worktree seed validation or inspectLegacyWorktreeDatabase when the database's applied-migration names are not exactly the first N entries of the checkout's journal — e.g. the DB was created by a fork or branch with different/reordered migration files.","commonSituations":"Worktree databases created from a different branch with reordered migration filenames; cherry-picked commits that changed journal order; a database migrated out of band; a checkout after migration files were renamed.","solutions":["Reseed the worktree from the canonical registered source instead of adopting the divergent database","Check out the exact Paperclip version whose migration journal matches the database, then retry","Diff applied vs available journal entries (drizzle meta/_journal) to find the divergent entry; if the DB is disposable, drop and reseed it"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const state = await inspectMigrations(/* target connection */);\nconst prefixOk =\n  state.appliedMigrations.length <= state.availableMigrations.length\n  && state.appliedMigrations.every((name, i) => name === state.availableMigrations[i]);\nif (!prefixOk) {\n  // journal diverged: do not adopt this database; provision a fresh seed\n}","typeGuard":null,"tryCatchPattern":"Wrap the adopt path in try-catch; on 'not a prefix' fall back to fresh provisioning (markWorktreeSeedPending + clone from the registered source).","preventionTips":["Never rename or reorder migration files after they ship","Reseed worktrees after switching to a branch with a different migration history","Treat journal divergence as proof the database came from a different lineage"],"tags":["migrations","worktree","seed","drizzle","database"],"backgroundTag":"database-migration-mismatch","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-21T17:58:32.592Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}