openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
42 lines (41 loc) • 2.69 kB
JavaScript
import { c as isRecord } from "./record-coerce-TIsquoVR.mjs";
import { d as readDatabasePathIdentitySync, r as assertExistingDatabaseIdentity } from "./sqlite-worker-identity-BRNRpRyc.mjs";
import { t as createSubsystemLogger } from "./subsystem-4NzR43uz.mjs";
import { c as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-CmKkMYdo.mjs";
import { isDeepStrictEqual } from "node:util";
//#region src/state/agent-database-startup-fts.ts
const attempts = /* @__PURE__ */ new Map();
function listAgentDatabaseStartupFtsRepairs() {
const statePath = resolveOpenClawStateSqlitePath(process.env);
return [...attempts.values()].flatMap((entry) => entry.statePath === statePath && entry.message ? [entry.message] : []);
}
/** Validate every repair checkpoint against the live source, journal, lease and file. */
function createAgentDatabaseStartupFtsAdmission(context) {
let attemptedKey;
return (facts) => {
if (!isRecord(facts) || facts.kind !== "agent-startup-fts") return false;
context.assertCurrent();
const lease = context.getLease();
if (!context.assertPreparationJournal || !lease || !isDeepStrictEqual(facts.lease, lease) || facts.phase !== "begin" && facts.phase !== "check" && facts.phase !== "complete" || facts.phase === "complete" && (typeof facts.message !== "string" || !facts.message)) throw new Error("FTS repair requires live Gateway startup admission and its exact lease");
context.assertPreparationJournal(facts.agentDeletionJournalPresent);
const identity = readDatabasePathIdentitySync(context.pathname);
if (!identity.key.startsWith("file:")) throw new Error("Startup FTS repair requires an existing physical file");
const expected = context.expectedIdentity;
if (expected) assertExistingDatabaseIdentity(context.pathname, "file:" + expected.physicalIdentity, expected.birthtime);
const key = JSON.stringify([identity.key, identity.birthtime]);
if (facts.phase === "begin") {
if (attempts.has(key)) throw new Error("Startup FTS repair was already attempted. Run openclaw doctor --fix.");
attempts.set(key, { statePath: context.sharedStatePath });
attemptedKey = key;
} else if (!attemptedKey || attemptedKey !== key || !attempts.has(key)) throw new Error("Startup FTS repair lost its physical-generation attempt");
else if (facts.phase === "complete") {
const entry = attempts.get(key);
if (entry.message) throw new Error("Startup FTS repair completion was already published");
entry.message = facts.message;
createSubsystemLogger("state/agent-db").warn(entry.message);
}
return true;
};
}
//#endregion
export { listAgentDatabaseStartupFtsRepairs as n, createAgentDatabaseStartupFtsAdmission as t };