openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
92 lines (91 loc) • 4.59 kB
JavaScript
import { s as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-R3ArRCcz.mjs";
import { t as stateEngineInput } from "./openclaw-state-db-engine-input-Dy8v5WSG.mjs";
import { n as agentEngineInput } from "./openclaw-agent-db-engine-CFD02117.mjs";
import { t as CronStoreSelectionRequiredError } from "./selection-error-CCb6S-v3.mjs";
import { t as backupDoctorMigrationDatabases } from "./doctor-migration-backup-DwSvhlqi.mjs";
import { existsSync } from "node:fs";
import { isDeepStrictEqual } from "node:util";
//#region src/commands/doctor-heartbeat-migration-backup.ts
/** Version migrations settle before retirement captures its same-schema rollback group. */
async function prepareDoctorMigrationBackups(e) {
const { schemas: t, env: n, check: r, verifiedSnapshots: i, automaticRepair: a, runtime: o, measure: s } = e;
const { prepareDoctorDatabaseMigrations: c } = await import("./doctor-schema-migrations-DXJxWq4T.mjs");
const { createOpenClawAgentDatabasePathMatcher: l } = await import("./openclaw-agent-db.paths-DKj26rDI.mjs");
const { normalizeAgentId: u } = await import("./session-key-Dy5IGO7x.mjs");
const d = l();
const f = t.agentDatabaseMigrationDiscovery?.discovery;
const p = f?.schemaTargets.filter(({ agentId: e, path: n, realPath: r }) => !t.agentRefusals?.some((t) => u(t.agentId) === u(e) && t.paths.some((e) => d(e, n))) && !t.indeterminate.some((e) => e.kind === "agent" && (e.path === n || f.sourceIdentities.get(e.path)?.realPath === r)));
const m = await s("doctor.database-migrations", () => c({
env: n,
check: r,
databasePaths: p?.map((e) => e.path) ?? [],
agentDatabaseTargets: p,
pendingDatabasePaths: t.pendingMigrations?.map((e) => e.path) ?? [],
pendingMigrations: t.pendingMigrations,
verifiedSnapshots: i
}));
for (const e of [...m.changes, ...m.warnings]) o.log(e);
if (t.agentDatabaseMigrationDiscovery && m.versionMigrations) t.agentDatabaseMigrationDiscovery.versionMigrations = m.versionMigrations;
const h = await s("doctor.heartbeat-migration-backups", () => backupHeartbeatMigrationDatabases({
env: n,
check: r,
databasePaths: p?.map((e) => e.path) ?? [],
agentDatabaseTargets: p,
verifiedSnapshots: i,
automaticRepair: a,
schemaPreparationPending: hasUnpreparedSchemas(t, m.versionMigrations)
}));
for (const e of [...h.changes, ...h.warnings]) o.log(e);
}
/**
* Report stores that canonical readers still cannot open. The version phase commits
* every migration it returns, so those stores are current and need no conservative
* full backup; refused, unreadable, or unmigrated stores still do.
*/
function hasUnpreparedSchemas(e, t) {
const n = new Set(t?.map((e) => e.path));
return Boolean(e.pendingMigrations?.some((e) => !n.has(e.path))) || Boolean(e.agentRefusals?.length) || e.indeterminate.length > 0;
}
async function hasPendingHeartbeatMigration(e, t) {
const [{ createConfigIO: n }, { tryProjectRetiredHeartbeatConfig: r }, { hasPendingHeartbeatCadenceMigration: i }, { collectHeartbeatScratchMigrationFindings: a }, { hasPendingHeartbeatOutcomes: o }] = await Promise.all([
import("./io.factory-D2IOIn7d.mjs"),
import("./doctor-heartbeat-legacy-COP4rUJ3.mjs"),
import("./doctor-heartbeat-cadence-migration-DjSAsyvP.mjs"),
import("./doctor-heartbeat-scratch-migration-C0ieo2Fx.mjs"),
import("./doctor-heartbeat-outcome-migration-DfJsbWIQ.mjs")
]);
const { sourceConfig: s } = await n({
env: t,
observe: false,
pluginValidation: "core-only"
}).readConfigFileSnapshot();
const c = r(s);
try {
return Boolean(c && (!isDeepStrictEqual(c, s) || i(s, t) || (await a(s, t)).length > 0 || o(e, t)));
} catch (e) {
if (e instanceof CronStoreSelectionRequiredError) return true;
throw e;
}
}
/** Heartbeat retirement changes current-schema data too; preserve the complete rollback group. */
async function backupHeartbeatMigrationDatabases(e) {
if (!e.schemaPreparationPending && !e.automaticRepair && !await hasPendingHeartbeatMigration(e.agentDatabaseTargets?.map((e) => ({
agentId: e.agentId,
storePath: e.path,
sqlitePath: e.path
})) ?? [], e.env)) return {
changes: [],
warnings: []
};
const t = resolveOpenClawStateSqlitePath(e.env);
return backupDoctorMigrationDatabases({
env: e.env,
check: e.check,
databasePaths: e.databasePaths,
agentDatabaseTargets: e.agentDatabaseTargets,
verifiedSnapshots: e.verifiedSnapshots,
pendingDatabasePaths: [t, ...e.databasePaths].filter((e) => existsSync(e) || Boolean(e === t ? stateEngineInput() : agentEngineInput()))
});
}
//#endregion
export { prepareDoctorMigrationBackups };