Files
openclaw/src/tasks/task-flow-registry.types.ts
T
Peter Steinberger 4d9052929b feat(cron): serve cron run history from the task ledger
Cron executions now write full-fidelity task_runs rows (detail_json column,
store-key scoped) and cron.runs/CLI/task-maintenance read from the ledger;
legacy cron_run_logs dual-write stays as a revert safety net. Existing
history auto-imports at first state-DB open (verified against a production
DB copy: 2750/2750 rows, byte-identical parity, idempotent). Startup crash
recovery restores finished runs from finalized ledger rows instead of
reporting synthetic interruptions.

Part 1 of 2 for #106041.
2026-07-13 11:32:57 -07:00

74 lines
1.9 KiB
TypeScript

// Defines managed task-flow registry records and parser helpers.
import type { DeliveryContext } from "../utils/delivery-context.types.js";
import type { JsonValue, TaskNotifyPolicy } from "./task-registry.types.js";
export type { JsonValue } from "./task-registry.types.js";
export type TaskFlowSyncMode = "task_mirrored" | "managed";
/** Lifecycle status for multi-step task flows. */
export type TaskFlowStatus =
| "queued"
| "running"
| "waiting"
| "blocked"
| "succeeded"
| "failed"
| "cancelled"
| "lost";
const TASK_FLOW_SYNC_MODES = new Set<TaskFlowSyncMode>(["task_mirrored", "managed"]);
const TASK_FLOW_STATUSES = new Set<TaskFlowStatus>([
"queued",
"running",
"waiting",
"blocked",
"succeeded",
"failed",
"cancelled",
"lost",
]);
function parsePersistedFlowValue<T extends string>(
value: unknown,
values: ReadonlySet<T>,
label: string,
): T {
if (typeof value === "string" && values.has(value as T)) {
return value as T;
}
throw new Error(`Invalid persisted task flow ${label}: ${JSON.stringify(value)}`);
}
export function parseOptionalTaskFlowSyncMode(value: unknown): TaskFlowSyncMode | undefined {
if (value == null || value === "") {
return undefined;
}
return parsePersistedFlowValue(value, TASK_FLOW_SYNC_MODES, "sync mode");
}
export function parseTaskFlowStatus(value: unknown): TaskFlowStatus {
return parsePersistedFlowValue(value, TASK_FLOW_STATUSES, "status");
}
export type TaskFlowRecord = {
flowId: string;
syncMode: TaskFlowSyncMode;
ownerKey: string;
requesterOrigin?: DeliveryContext;
controllerId?: string;
revision: number;
status: TaskFlowStatus;
notifyPolicy: TaskNotifyPolicy;
goal: string;
currentStep?: string;
blockedTaskId?: string;
blockedSummary?: string;
stateJson?: JsonValue;
waitJson?: JsonValue;
cancelRequestedAt?: number;
createdAt: number;
updatedAt: number;
endedAt?: number;
};