openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
470 lines (469 loc) • 22.6 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { n as safeParseJsonRecord } from "./json-coercion-CaJLaav-.mjs";
import { rt as OPENCLAW_STATE_SCHEMA_SQL } from "./sqlite-database-admission-DQIqro3d.mjs";
import { n as readProcessMachineIdentity } from "./current-machine-identity-DYZ3ln3p.mjs";
import { n as OPENCLAW_STATE_SCHEMA_VERSION } from "./openclaw-schema-versions-E_10NoI6.mjs";
import { l as runWithSqliteCleanup } from "./sqlite-lifecycle-errors-D8BU4VLa.mjs";
import { c as withSqlitePostCommitPublications } from "./sqlite-post-commit-BrUVQObC.mjs";
import { a as executeSqliteQueryTakeFirstSync, i as executeSqliteQuerySync, s as getNodeSqliteKysely } from "./kysely-sync-YJo2lmGV.mjs";
import { o as getAdmittedSqliteSchemaFacts } from "./sqlite-schema-facts-B1bVE8IB.mjs";
import { a as tableExists, f as throwSqliteSchemaMismatches, t as classifySqliteTableReadError } from "./openclaw-state-db-schema-helpers-nImZNMq_.mjs";
import "./openclaw-state-db-contract-DfPjvL0M.mjs";
import { t as VERSION } from "./version-GlxUMdxI.mjs";
import { i as getStateSchemaVersionAdmission, o as publishStateRuntimeSchemaAdmission, r as getStateRuntimeSchemaAdmission } from "./openclaw-state-db-admission-Bw1Mtc4x.mjs";
import { n as openNodeSqliteDatabase } from "./node-sqlite-CU4puofF.mjs";
import { o as runSqliteReadSnapshotSync, r as runSqliteDeferredTransactionSync } from "./sqlite-transaction-BHHu6P5-.mjs";
import { a as isPidDefinitelyDead, t as getFileLockProcessStartTime } from "./pid-alive-D899x-ak.mjs";
import { A as classifyGatewayOwnerProcessNamespace, E as GatewayProcessNamespaceSchema, F as predatesCurrentBoot, O as MachineIdentitySchema, P as createManagedHandoffBootIdentityReader, z as managedHandoffBootSchema } from "./gateway-state-owner-Bnv5owvG.mjs";
import { a as prepareSqliteReadOnlyLocationSync } from "./sqlite-snapshot-source-Q9S7_uQN.mjs";
import { n as OpenClawStateDatabaseSchemaMigrationRequiredError } from "./openclaw-state-db-schema-migration-required-D2P85VUd.mjs";
import { O as assertOpenClawStateRuntimeIntegrity } from "./openclaw-state-db-cache-CkwtTqzF.mjs";
import { r as assertSqliteIntegrity } from "./sqlite-integrity-CCmEgO_m.mjs";
import { o as hasUpdateDoctorMigrationCapture } from "./update-doctor-migration-attribution-Dp_N9vmd.mjs";
import { t as createSqliteTableContractReader } from "./sqlite-schema-catalog-BK5o5Jvf.mjs";
import { i as assertSupportedStateSchemaVersion, o as readStateSchemaContentVersion, r as admitStateSchemaFacts } from "./openclaw-state-db-schema-version-uNbDFl6T.mjs";
import { l as readSqliteSchemaCookie, t as assertSqliteSchemaContains } from "./sqlite-schema-contract-D3pR9vZs.mjs";
import { t as StateLeaseLossSchema } from "./state-lease-loss-CfM9y5At.mjs";
import { T as hasHistoricalImageReserveSnapshots, _ as findMissingLazyStateStartupColumn, g as STATE_RUNTIME_SCHEMA_COMPATIBILITY, n as assertOpenClawStateDatabaseForMaintenance } from "./openclaw-state-db-maintenance-Dvr7ztmv.mjs";
import { r as assertCanonicalStateSchemaShape } from "./openclaw-state-db-schema-repair-aWqRraBE.mjs";
import fs, { readlinkSync } from "node:fs";
import { createHash } from "node:crypto";
import { hostname } from "node:os";
//#region src/infra/state-lease-process-owner.ts
let selfNamespace;
function parseNamespace(e) {
try {
const t = JSON.parse(e ?? "null");
if (!Array.isArray(t) || t.length !== 4) return null;
const n = managedHandoffBootSchema.safeParse({
platform: t[0],
identity: t[1]
});
const r = t[2];
const i = t[3];
if (!n.success || (n.data.platform === "linux" ? typeof r !== "string" || !/^pid:\[\d+\]$/u.test(r) : r !== null) || i !== null && (typeof i !== "string" || !/^[a-f0-9]{64}$/u.test(i))) return null;
return {
...n.data,
identity: n.data.identity.toLowerCase(),
machineIdentity: i
};
} catch {
return null;
}
}
/** A PID is meaningful only in the original kernel and PID namespace. */
function captureNamespacedStateLeaseProcessOwner() {
let e = selfNamespace ?? null;
if (e === null) try {
const t = createManagedHandoffBootIdentityReader(process.env)();
const n = t.platform === "linux" ? readlinkSync("/proc/self/ns/pid") : null;
if (t.identity && (t.platform !== "linux" || n)) {
e = JSON.stringify([
t.platform,
t.identity,
n,
readProcessMachineIdentity()
]);
selfNamespace = e;
}
} catch {}
return {
pid: process.pid,
host: hostname(),
startedAt: getFileLockProcessStartTime(process.pid),
namespace: e
};
}
function readNamespacedStateLeaseProcessOwnerStatus(e, t) {
const n = parseNamespace(e.namespace);
const r = parseNamespace(t);
if (!n || !r || e.host !== hostname()) return "unknown";
if (e.namespace === t) return readSameNamespaceProcessOwnerStatus(e);
return n.platform === r.platform && n.machineIdentity !== null && n.machineIdentity === r.machineIdentity && n.identity !== r.identity ? "dead" : "unknown";
}
function parseStateLeaseProcessOwner(e) {
const t = safeParseJsonRecord(e ?? "")?.owner;
if (!isRecord(t)) return null;
const { pid: n, host: r, startedAt: i } = t;
if (typeof n !== "number" || !Number.isSafeInteger(n) || n <= 0 || typeof r !== "string" || !r || i !== null && (typeof i !== "number" || !Number.isSafeInteger(i) || i < 0)) return null;
return {
pid: n,
host: r,
startedAt: i,
...t.machineIdentity === void 0 ? {} : { machineIdentity: MachineIdentitySchema.safeParse(t.machineIdentity).data ?? null },
...t.processNamespace === void 0 ? {} : { processNamespace: GatewayProcessNamespaceSchema.safeParse(t.processNamespace).data ?? null }
};
}
function readStateLeaseProcessOwnerStatus(e, t) {
if (!e) return "unknown";
const n = classifyGatewayOwnerProcessNamespace(e.processNamespace, {
ownerHost: e.host,
machineIdentity: e.machineIdentity
});
if (n !== "same") return n;
return readSameNamespaceProcessOwnerStatus(e);
}
function readSameNamespaceProcessOwnerStatus(e) {
if (isPidDefinitelyDead(e.pid)) return "dead";
const t = getFileLockProcessStartTime(e.pid);
if (e.startedAt === null || t === null) return "unknown";
return t === e.startedAt ? "live" : "dead";
}
//#endregion
//#region src/state/openclaw-state-lease-store.ts
/** Publish owner facts in the caller's transaction without renewing or replacing its lease. */
function updateOpenClawStateLeasePayloadInTransaction(e, t, n) {
return executeSqliteQuerySync(e, getNodeSqliteKysely(e).updateTable("state_leases").set({ payload_json: n }).where("scope", "=", t.scope).where("lease_key", "=", t.key).where("owner", "=", t.owner)).numAffectedRows === 1n;
}
/** The caller owns the write transaction; only absent or expired leases can be acquired. */
function acquireOpenClawStateLeaseInTransaction(e, t, n, r = null, i) {
const a = i ?? Date.now();
const o = getNodeSqliteKysely(e);
executeSqliteQuerySync(e, o.deleteFrom("state_leases").where("scope", "=", t.scope).where("lease_key", "=", t.key).where("expires_at", "<=", a));
const s = a + n;
if (executeSqliteQuerySync(e, o.insertInto("state_leases").values({
scope: t.scope,
lease_key: t.key,
owner: t.owner,
expires_at: s,
heartbeat_at: a,
payload_json: r,
created_at: a,
updated_at: a
}).onConflict((e) => e.columns(["scope", "lease_key"]).doNothing())).numAffectedRows === 1n) return {
kind: "acquired",
expiresAt: s
};
const c = readOpenClawStateLease(e, t);
if (!c) throw new Error("Conflicting state lease disappeared inside its acquisition transaction");
return {
kind: "held",
holder: {
owner: c.owner,
epoch: c.createdAt,
expiresAt: c.expiresAt
}
};
}
function readOpenClawStateLease(e, t) {
return executeSqliteQueryTakeFirstSync(e, getNodeSqliteKysely(e).selectFrom("state_leases").select([
"owner",
"created_at as createdAt",
"expires_at as expiresAt",
"heartbeat_at as heartbeatAt",
"payload_json as payloadJson"
]).where("scope", "=", t.scope).where("lease_key", "=", t.key));
}
/** Observe only after authority has failed; diagnostics must never replace that failure. */
function readOpenClawStateLeaseLoss(e, t) {
try {
const n = readOpenClawStateLease(e, t);
const r = Date.now();
const i = !n ? { reason: "missing" } : n.owner !== t.owner ? {
reason: "replaced",
owner: "[redacted]"
} : n.expiresAt !== null && n.heartbeatAt !== null && n.expiresAt <= r ? {
reason: "expired",
expiresAt: n.expiresAt,
expiredByMs: r - n.expiresAt,
heartbeatAgeMs: Math.max(0, r - n.heartbeatAt)
} : void 0;
return StateLeaseLossSchema.safeParse(i).data;
} catch {
return;
}
}
/** Reclaim only a same-host owner whose process identity is provably gone. */
function reclaimDeadOpenClawStateLeaseInTransaction(e, t) {
const n = readOpenClawStateLease(e, t);
if (n && readStateLeaseProcessOwnerStatus(parseStateLeaseProcessOwner(n.payloadJson)) === "dead") {
releaseOpenClawStateLeaseInTransaction(e, {
...t,
owner: n.owner
});
return;
}
return n;
}
function readOpenClawStateLeaseExpiry(e, t, n) {
return executeSqliteQueryTakeFirstSync(e, getNodeSqliteKysely(e).selectFrom("state_leases").select("expires_at").where("scope", "=", t.scope).where("lease_key", "=", t.key).where("owner", "=", t.owner).where("expires_at", ">", n ?? Date.now()).$narrowType())?.expires_at;
}
function repairMissingProcessStartTime(e, t, n) {
if (n?.startedAt == null) return;
const r = readOpenClawStateLease(e, t);
const i = parseStateLeaseProcessOwner(r?.payloadJson ?? null);
if (r?.owner !== t.owner || i?.startedAt !== null || i.pid !== n.pid || i.host !== n.host || !r.payloadJson) return;
const a = JSON.parse(r.payloadJson);
if (!isRecord(a) || !isRecord(a.owner)) return;
return JSON.stringify({
...a,
owner: {
...a.owner,
startedAt: n.startedAt
}
});
}
/** The caller owns the write transaction; expired or replaced owners cannot renew. */
function renewOpenClawStateLeaseInTransaction(e, t, n, r, i) {
const a = i ?? Date.now();
const o = a + n;
const s = repairMissingProcessStartTime(e, t, r);
return executeSqliteQuerySync(e, getNodeSqliteKysely(e).updateTable("state_leases").set({
expires_at: o,
heartbeat_at: a,
updated_at: a,
...s === void 0 ? {} : { payload_json: s }
}).where("scope", "=", t.scope).where("lease_key", "=", t.key).where("owner", "=", t.owner).where("expires_at", ">", a)).numAffectedRows === 1n ? o : void 0;
}
/** Renew an unchanged grant while its owner excludes takeover with SQLite's writer lock. */
function renewOpenClawStateLeaseUnderWriteFence(e, t, n, r) {
const i = Date.now();
const a = i + r;
return executeSqliteQuerySync(e, getNodeSqliteKysely(e).updateTable("state_leases").set({
expires_at: a,
heartbeat_at: i,
updated_at: i
}).where("scope", "=", t.scope).where("lease_key", "=", t.key).where("owner", "=", t.owner).where("created_at", "=", n)).numAffectedRows === 1n ? a : void 0;
}
/** The caller owns write admission; a replaced owner cannot release its successor. */
function releaseOpenClawStateLeaseInTransaction(e, t) {
executeSqliteQuerySync(e, getNodeSqliteKysely(e).deleteFrom("state_leases").where("scope", "=", t.scope).where("lease_key", "=", t.key).where("owner", "=", t.owner));
}
//#endregion
//#region src/infra/gateway-owner-lease.read.ts
const gatewayOwnerKey = {
scope: "gateway-owner",
key: "global"
};
const GATEWAY_OWNER_LEASE_COLUMNS_SQL = `SELECT a.attname AS name, pg_catalog.format_type(a.atttypid, a.atttypmod) AS type
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
WHERE n.nspname = $1 AND c.relname = 'state_leases' AND c.relkind IN ('r', 'p')
AND a.attnum > 0 AND NOT a.attisdropped`;
function assertGatewayOwnerLeaseColumns(e) {
if (Object.entries({
scope: "text",
lease_key: "text",
owner: "text",
expires_at: "bigint",
heartbeat_at: "bigint",
payload_json: "text",
created_at: "bigint"
}).some(([t, n]) => !e.some((e) => e.name === t && e.type === n))) throw new Error("PostgreSQL Gateway owner lease table is missing or incompatible");
}
function parseSupervisor(e) {
if (e === null) return null;
if (!isRecord(e) || e.kind !== "launchd" && e.kind !== "systemd" && e.kind !== "schtasks" && e.kind !== "external" || e.name !== null && (typeof e.name !== "string" || !e.name.trim())) throw new Error("Gateway owner lease supervisor could not be verified");
return {
kind: e.kind,
name: e.name
};
}
/** Read through the caller's admitted connection when ownership guards a write. */
function readGatewayOwnerLeaseFromDatabase(e, t) {
if (!tableExists(e, "state_leases")) return;
return decodeGatewayOwnerLease(readOpenClawStateLease(e, gatewayOwnerKey), t);
}
function decodeGatewayOwnerLease(e, t) {
if (!e) return;
const n = parseStateLeaseProcessOwner(e.payloadJson);
const r = safeParseJsonRecord(e.payloadJson ?? "");
if (!n || !r || typeof r.port !== "number" || !Number.isInteger(r.port) || r.port <= 0 || r.port > 65535 || r.mode !== "foreground" && r.mode !== "supervised") throw new Error("Gateway owner lease identity could not be verified");
if (t !== void 0 && r.port !== t) return;
const i = parseSupervisor(r.supervisor);
if (r.mode === "foreground" !== (i === null)) throw new Error("Gateway owner lease supervisor does not match its listener mode");
return {
...n,
owner: e.owner,
heartbeatAt: e.heartbeatAt ?? e.createdAt,
port: r.port,
mode: r.mode,
supervisor: i,
...typeof r.listeningAt === "number" ? { listeningAt: r.listeningAt } : {},
...typeof r.stateDatabaseProvenance === "string" ? { stateDatabaseProvenance: r.stateDatabaseProvenance } : {},
state: readStateLeaseProcessOwnerStatus(n, e.heartbeatAt ?? e.createdAt),
expired: e.expiresAt === null || e.expiresAt <= Date.now()
};
}
//#endregion
//#region src/infra/state-legacy-cron-presence.ts
/** Runtime admission needs table presence, without loading the migration's history codecs. */
function hasLegacyCronRunLogs(e) {
const t = getAdmittedSqliteSchemaFacts(e);
if (t) return t.tables.has("cron_run_logs");
return Boolean(e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'cron_run_logs' LIMIT 1").get());
}
//#endregion
//#region src/state/openclaw-agent-db-lease-provenance.ts
let boot;
function mayShareAgentDatabaseFile(e, t) {
if (e === t) return true;
try {
const n = fs.statSync(e, {
bigint: true,
throwIfNoEntry: false
});
const r = fs.statSync(t, {
bigint: true,
throwIfNoEntry: false
});
return !n || !r || n.dev === r.dev && n.ino === r.ino;
} catch {
return true;
}
}
/** Observe boot identity at most once per scan, never retain it across repairs. */
function createAgentDatabaseLeaseStaleReasonReader() {
let e;
return (t) => {
if (isPidDefinitelyDead(t.owner_pid)) return "owner-pid-dead";
if (t.owner_start_time === null) {
if (t.opened_at <= 0) return;
if (e === void 0) try {
e = createManagedHandoffBootIdentityReader(process.env)();
} catch {
e = null;
}
return predatesCurrentBoot(t.opened_at, e ?? void 0) ? "owner-prior-boot" : void 0;
}
const n = getFileLockProcessStartTime(t.owner_pid);
return n !== null && t.owner_start_time !== n ? "owner-start-time-changed" : void 0;
};
}
function readAgentDatabaseLeaseProvenance(e) {
try {
if (boot === void 0) {
const e = process.platform === "linux" ? fs.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim() : "";
boot = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(e) ? [
hostname(),
e,
fs.readlinkSync("/proc/self/ns/pid"),
VERSION
].join("\0") : null;
}
if (!boot) return null;
const t = fs.statSync(e, { bigint: true });
return t.isFile() ? `process-v1:${createHash("sha256").update(`${boot}\0${t.dev}:${t.ino}`).digest("hex")}` : null;
} catch {
return null;
}
}
function isSameBootAgentDatabaseLease(e, t) {
return e !== null && e === readAgentDatabaseLeaseProvenance(t);
}
function agentDatabaseLeaseProcessDeathRefusal(e, t, n) {
if (n !== "owner-pid-dead") return n;
if (e.opened_at < 0) return "predecessor-full-required";
if (e.owner_start_time === null) return "owner-start-time-missing";
if (e.path !== t) return "lease-path-mismatch";
if (e.provenance === null) return "legacy-provenance-missing";
return isSameBootAgentDatabaseLease(e.provenance, t) ? void 0 : "host-boot-namespace-version-file-mismatch";
}
function agentDatabaseAdmissionProvenanceRefusal(e, t) {
return e === void 0 ? "native-admission-required" : isSameBootAgentDatabaseLease(e, t) ? void 0 : "prepared-provenance-mismatch";
}
//#endregion
//#region src/state/openclaw-state-db-fast-path.ts
function needsOpenClawStateDatabaseSchemaRepair(e, t = "automatic", n = "quick") {
let r;
let i;
try {
i = hasUpdateDoctorMigrationCapture() ? prepareSqliteReadOnlyLocationSync(e) : void 0;
r = openNodeSqliteDatabase(i?.location ?? e, { readOnly: true });
if (t === "automatic" && getStateRuntimeSchemaAdmission(r)?.startupReady) return false;
admitStateSchemaFacts(r, e);
assertSupportedStateSchemaVersion(r, e);
const a = readStateSchemaContentVersion(r) !== 36 || hasLegacyCronRunLogs(r) || t === "doctor" && hasHistoricalImageReserveSnapshots(r);
if (!a) {
assertCurrentStateRuntimeSchema(r, e);
if (t === "doctor") assertSqliteIntegrity(r, e, { check: n });
}
return a;
} catch {
return true;
} finally {
runWithSqliteCleanup({ release: () => i?.cleanup() }, "State schema inspection", () => r?.close());
}
}
function assertCurrentStateRuntimeSchema(e, t, n = createSqliteTableContractReader(e)) {
const r = findMissingLazyStateStartupColumn(n);
if (r) throwSqliteSchemaMismatches(t, ["missing column " + r.tableName + "." + r.columnName]);
assertCanonicalStateSchemaShape(e, t);
assertOpenClawStateDatabaseForMaintenance(e, { pathname: t }, n);
assertSqliteSchemaContains(e, t, OPENCLAW_STATE_SCHEMA_SQL, STATE_RUNTIME_SCHEMA_COMPATIBILITY, n);
}
/** Catalog presence is enough to refuse retired history without reading or rewriting its rows. */
function assertNoLegacyStateRuntimeRepair(e, t) {
if (hasLegacyCronRunLogs(e)) throw new OpenClawStateDatabaseSchemaMigrationRequiredError("legacy-cron-run-logs", t);
}
function isOpenClawStateSchemaFastPathEligible(e, t, n) {
const r = getStateRuntimeSchemaAdmission(e);
if (r) return r.startupReady;
let i;
const a = withSqlitePostCommitPublications(e, () => runSqliteDeferredTransactionSync(e, () => {
const r = assertSupportedStateSchemaVersion(e, t);
if (readStateSchemaContentVersion(e) !== 36) return false;
const a = readSqliteSchemaCookie(e);
if (typeof a !== "number") throw new Error(`Shared-state database ${t} schema version is unavailable.`);
assertCurrentStateRuntimeSchema(e, t, createSqliteTableContractReader(e));
assertNoLegacyStateRuntimeRepair(e, t);
const o = readGatewayOwnerLeaseFromDatabase(e);
if (!(o?.state === "live" && o.pid !== process.pid && Boolean(o.stateDatabaseProvenance) && o.stateDatabaseProvenance === readAgentDatabaseLeaseProvenance(t))) i = assertOpenClawStateRuntimeIntegrity(e, t, {
schemaVersion: a,
userVersion: r
}, n);
return true;
}, { operationLabel: "state.admission.fast-path" }));
i?.();
if (a) publishStateRuntimeSchemaAdmission(e, true);
return a;
}
//#endregion
//#region src/state/openclaw-state-db-existing-schema.ts
/** Metadata is validated with the physical database's first runtime admission. */
function assertExistingOpenClawStateRuntimeMetadata(e, t, n) {
if (getStateRuntimeSchemaAdmission(e)) {
const t = getStateSchemaVersionAdmission(e)?.userVersion;
if (t !== void 0) return t;
}
const r = assertSupportedStateSchemaVersion(e, t, void 0, void 0, n);
if (readStateSchemaContentVersion(e) !== 36) throw new Error(`Existing shared-state database ${t} requires schema migration by its owning installation; run openclaw doctor --fix there before using it.`);
let i;
try {
i = executeSqliteQueryTakeFirstSync(e, getNodeSqliteKysely(e).selectFrom("schema_meta").select(["role", "schema_version"]).where("meta_key", "=", "primary").limit(1));
} catch (t) {
throw classifySqliteTableReadError(e, "schema_meta", [
"meta_key",
"role",
"schema_version"
], t);
}
if (i?.role !== "global" || i.schema_version !== r) throw new Error(`Existing shared-state database ${t} has inconsistent ownership or schema metadata.`);
return r;
}
/** Validate an existing runtime schema without applying repairs. */
function assertExistingOpenClawStateRuntimeSchema(e, t, n, r, i = "runtime") {
const a = getStateRuntimeSchemaAdmission(e) ? getAdmittedSqliteSchemaFacts(e) : void 0;
if (a) {
assertOpenClawStateRuntimeIntegrity(e, t, a, n, r)?.();
return;
}
let o;
runSqliteReadSnapshotSync(e, () => {
const a = assertExistingOpenClawStateRuntimeMetadata(e, t, i);
const s = readSqliteSchemaCookie(e);
if (typeof s !== "number") throw new Error(`Existing shared-state database ${t} schema version is unavailable.`);
o = assertOpenClawStateRuntimeIntegrity(e, t, {
schemaVersion: s,
userVersion: a
}, n, r);
const c = createSqliteTableContractReader(e);
assertCurrentStateRuntimeSchema(e, t, c);
assertNoLegacyStateRuntimeRepair(e, t);
}, { operationLabel: "state.admission.existing-schema" });
o?.();
publishStateRuntimeSchemaAdmission(e, true);
}
//#endregion
export { renewOpenClawStateLeaseInTransaction as C, parseStateLeaseProcessOwner as D, captureNamespacedStateLeaseProcessOwner as E, readNamespacedStateLeaseProcessOwnerStatus as O, releaseOpenClawStateLeaseInTransaction as S, updateOpenClawStateLeasePayloadInTransaction as T, acquireOpenClawStateLeaseInTransaction as _, needsOpenClawStateDatabaseSchemaRepair as a, readOpenClawStateLeaseLoss as b, createAgentDatabaseLeaseStaleReasonReader as c, hasLegacyCronRunLogs as d, GATEWAY_OWNER_LEASE_COLUMNS_SQL as f, readGatewayOwnerLeaseFromDatabase as g, gatewayOwnerKey as h, isOpenClawStateSchemaFastPathEligible as i, readStateLeaseProcessOwnerStatus as k, mayShareAgentDatabaseFile as l, decodeGatewayOwnerLease as m, assertCurrentStateRuntimeSchema as n, agentDatabaseAdmissionProvenanceRefusal as o, assertGatewayOwnerLeaseColumns as p, assertNoLegacyStateRuntimeRepair as r, agentDatabaseLeaseProcessDeathRefusal as s, assertExistingOpenClawStateRuntimeSchema as t, readAgentDatabaseLeaseProvenance as u, readOpenClawStateLease as v, renewOpenClawStateLeaseUnderWriteFence as w, reclaimDeadOpenClawStateLeaseInTransaction as x, readOpenClawStateLeaseExpiry as y };