UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

52 lines (51 loc) 2.59 kB
import { n as getRuntimeConfig } from "./io.runtime-B9iJRs3w.js"; import { f as resolveAgentIdFromSessionKey, k as parseCronRunScopeSuffix } from "./session-key-BnWWjqNc.js"; import { o as resolveSessionStorePathCore } from "./paths-CXdaYWF_.js"; import "./config-Cs0XXL3x.js"; import { c as getAgentEventLifecycleGeneration } from "./agent-events-CoxiItUi.js"; import "./session-accessor-YsytfDtG.js"; import { l as loadSessionEntry } from "./session-accessor.sqlite-entry-CWk3jL7s.js"; import { r as deleteSessionEntryLifecycle } from "./session-accessor.sqlite-lifecycle-DBhNICvK.js"; import { o as hasPendingGeneratedMediaTaskForSessionKey } from "./task-status-access-C6caarxH.js"; import { m as loadPendingSessionDeliveries } from "./session-delivery-queue-storage-ClcsFC9e.js"; //#region src/tasks/cron-run-continuation-cleanup.ts /** Removes an idle exact-run continuation through the session lifecycle owner. */ function canRemoveCronRunContinuation(marker) { if (!marker || marker.basePersisted !== true) return false; if (marker.phase === "ready") return !marker.ownerRunId; if (marker.phase !== "continuing" || !marker.ownerRunId) return false; const ownerLifecycleGeneration = marker.ownerLifecycleGeneration?.trim(); return Boolean(ownerLifecycleGeneration && ownerLifecycleGeneration !== getAgentEventLifecycleGeneration()); } async function removeCronRunContinuationSessionIfIdle(sessionKey, settledDeliveryId) { if (!parseCronRunScopeSuffix(sessionKey).runId || hasPendingGeneratedMediaTaskForSessionKey(sessionKey)) return; if ((await loadPendingSessionDeliveries()).some((entry) => entry.sessionKey === sessionKey && entry.id !== settledDeliveryId && entry.settlementOutcome === void 0 && entry.acknowledgedAt === void 0)) return; const agentId = resolveAgentIdFromSessionKey(sessionKey); const cfg = getRuntimeConfig(); const storePath = resolveSessionStorePathCore(cfg.session?.store, { agentId }); const entry = loadSessionEntry({ agentId, sessionKey, storePath, readConsistency: "latest", hydrateSkillPromptRefs: false }); const marker = entry?.cronRunContinuation; if (!entry || !canRemoveCronRunContinuation(marker)) return; await deleteSessionEntryLifecycle({ agentId, archiveTranscript: false, expectedEntry: entry, expectedLifecycleRevision: entry.lifecycleRevision, expectedSessionId: entry.sessionId, expectedUpdatedAt: entry.updatedAt, requireWriteSuccess: true, storePath, target: { canonicalKey: sessionKey, storeKeys: [sessionKey] } }); } //#endregion export { removeCronRunContinuationSessionIfIdle as t };