paperclipai/paperclip · error · Error

Migration journal has no applied revision.

Error message

Migration journal has no applied revision.

What it means

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.

Source

Thrown at cli/src/commands/worktree.ts:1489

    migrationState.appliedMigrations.length,
  );
  const appliedMigrationNames = new Set(migrationState.appliedMigrations);
  if (
    appliedMigrationNames.size !== expectedAppliedPrefix.length ||
    expectedAppliedPrefix.some((migration) => !appliedMigrationNames.has(migration))
  ) {
    throw new Error("Migration journal is not a prefix of this Paperclip checkout's migration journal.");
  }

  if (requirement === "upToDate" && migrationState.status !== "upToDate") {
    throw new Error(
      `Migration journal is not current (${migrationState.pendingMigrations.length} pending migration(s)).`,
    );
  }

  const migrationRevision = expectedAppliedPrefix.at(-1);
  if (!migrationRevision) {
    throw new Error("Migration journal has no applied revision.");
  }
  return migrationRevision;
}

/**
 * Markerless worktrees predate the versioned seed manifest. Adopt one only
 * after proving that its configured database already has a compatible
 * migration journal and the core Paperclip tables. The physical PG_VERSION
 * check prevents this read-only probe from initializing a missing embedded
 * database and then mistaking that empty cluster for legacy evidence.
 */
export async function inspectLegacyWorktreeDatabase(
  configPath: string,
): Promise<LegacyWorktreeDatabaseEvidence | null> {
  const config = readConfig(configPath);
  if (!config) return null;

  const envEntries = readPaperclipEnvEntries(resolvePaperclipEnvFile(configPath));

View on GitHub (pinned to a7e689b3c3)

Solutions

  1. Provision a fresh seed (markWorktreeSeedPending + seed from the registered source) instead of adopting this database
  2. Point the worktree at its real previously-seeded data dir if one exists
  3. If the data dir is disposable, remove it and let the seed initialize a new one
Defensive patterns

Strategy: fallback

Validate before calling

const state = await inspectMigrations(/* target connection */);
if (state.appliedMigrations.length === 0) {
  // no legacy evidence: skip adoption and provision a fresh seed
}

Try / catch

On 'no applied revision' during legacy adoption, switch to fresh provisioning — an empty cluster is a new worktree, not a legacy one.

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of paperclipai/paperclip@a7e689b3c3 (2026-08-21). Data as JSON: /api/errors/e8db79a000e3ffee. Report an issue: GitHub.