openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
77 lines (76 loc) • 3.51 kB
JavaScript
import { a as getOpenClawDatabaseMaintenanceScope } from "./openclaw-state-maintenance-context-D6i7Zdhn.mjs";
import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs";
import { i as executeSqliteQuerySync, s as getNodeSqliteKysely } from "./kysely-sync-YJo2lmGV.mjs";
import "./openclaw-state-db-async-lifecycle-CH8q4Sdl.mjs";
import { a as captureGatewayStateOwner } from "./gateway-state-owner-Bnv5owvG.mjs";
import { l as runOpenClawStateWriteTransaction } from "./openclaw-state-db-ARhwdPJg.mjs";
import { t as DoctorMaintenanceRefusalError } from "./update-doctor-result-DwaI51On.mjs";
import { t as prepareCronRunReceiptWriteSchema } from "./run-receipt-write-admission-CFr_ZnYD.mjs";
import { r as receiptFromRow } from "./run-receipt-read-D39wuF7K.mjs";
import { n as cloneCronJobForMutation } from "./jobs-mutation-CCvBO39N.mjs";
import { t as createCronMutationLogger } from "./runtime-mutation.worker-CnJDZp_q.mjs";
import { t as recoverCronJobInDatabase } from "./run-recovery.kernel-budps8KO.mjs";
//#region src/commands/doctor-heartbeat-run-recovery.ts
var DoctorHeartbeatMigrationDeferredError = class extends DoctorMaintenanceRefusalError {
constructor(e) {
super(e, {
kind: "deferred",
reason: "admission-unavailable"
});
this.name = "DoctorHeartbeatMigrationDeferredError";
}
};
/** Doctor adapts the retired payload; cron's startup owner alone settles the run. */
function recoverDoctorHeartbeatRun(e) {
const { database: t, storeKey: n, job: r, cfg: i, nowMs: a } = e;
const o = getOpenClawDatabaseMaintenanceScope();
const s = captureGatewayStateOwner(t.path);
if (!o?.ownsSchemaMaintenance || s?.role !== "sqlite-maintenance") throw new DoctorHeartbeatMigrationDeferredError(`Heartbeat migration deferred: automation ${r.id} is running or its runtime owner is unproved. Its job and configuration were retained; stop the Gateway and rerun openclaw doctor --fix.`);
o.assertAdmission();
s.assertCurrent();
const c = cloneCronJobForMutation({
...r,
payload: r.payload.kind === "heartbeat" ? {
...r.payload,
kind: "systemEvent",
text: ""
} : r.payload
});
const l = executeSqliteQuerySync(t.db, getNodeSqliteKysely(t.db).selectFrom("cron_run_receipts").selectAll().where("store_key", "=", n).where("job_id", "=", r.id).where("status", "=", "running")).rows[0];
const u = [];
const d = [];
const f = /* @__PURE__ */ new Error("Cron recovery requires Gateway notification dispatch");
let p;
try {
p = runOpenClawStateWriteTransaction(() => {
const e = recoverCronJobInDatabase({
database: t,
storeKey: n,
job: c,
receipt: l ? receiptFromRow(l) : void 0,
receiptSchema: prepareCronRunReceiptWriteSchema(t.db),
state: { deps: {
nowMs: () => a,
cronConfig: i.cron,
log: createCronMutationLogger(d)
} },
notifications: u
});
if (u.length) throw f;
return e;
}, { database: t }, { operationLabel: "doctor.heartbeat-run-recovery" });
} catch (e) {
if (e !== f) throw e;
createSubsystemLogger("cron").warn(`Automation ${r.id} converted; run recovery and its notifications will complete at the next Gateway start.`);
return r;
}
const m = createSubsystemLogger("cron");
for (const e of d) m[e.level](e.message ?? "cron: heartbeat run recovery", { fields: e.fields });
if (p.removed) return;
return r.payload.kind === "heartbeat" ? {
...c,
payload: r.payload
} : c;
}
//#endregion
export { recoverDoctorHeartbeatRun as n, DoctorHeartbeatMigrationDeferredError as t };