mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 01:52:53 +00:00
Move task run, delivery, and flow registry persistence onto the shared OpenClaw state SQLite database.
Summary:
- Store task runs, delivery state, and flow runs in state/openclaw.sqlite via the generated Kysely schema.
- Migrate shipped task sidecars into the shared state DB and archive old sidecars, including invalid-config/read-only CLI paths.
- Keep startup migration lightweight for read-only status/tasks paths while still detecting known legacy state markers and custom session stores.
Verification:
- .agents/skills/autoreview/scripts/autoreview --mode local: clean after final fix
- pnpm test src/tasks/task-registry.store.test.ts src/tasks/task-flow-registry.store.test.ts src/commands/doctor-state-migrations.test.ts -- --reporter=verbose
- pnpm test src/commands/doctor-state-migrations.test.ts src/cli/program/config-guard.test.ts src/cli/route.test.ts src/cli/command-path-policy.test.ts -- --reporter=verbose
- pnpm test src/cli/program/config-guard.test.ts src/cli/route.test.ts src/cli/command-startup-policy.test.ts src/cli/command-path-policy.test.ts src/cli/command-execution-startup.test.ts -- --reporter=verbose
- pnpm test src/cli/program/config-guard.test.ts src/cli/argv.test.ts src/cli/route.test.ts src/commands/doctor-config-preflight.state-migration.test.ts -- --reporter=verbose
- pnpm test src/tasks/task-flow-registry.store.test.ts -- --reporter=verbose
- pnpm test test/scripts/lint-suppressions.test.ts -- --reporter=verbose
- pnpm db:kysely:check
- pnpm lint:kysely
- git diff --check HEAD
- pnpm test:startup:memory
- PR CI green on 2f7d76f0d5
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import {
|
|
closeTaskFlowRegistryDatabase,
|
|
deleteTaskFlowRegistryRecordFromSqlite,
|
|
loadTaskFlowRegistryStateFromSqlite,
|
|
saveTaskFlowRegistryStateToSqlite,
|
|
upsertTaskFlowRegistryRecordToSqlite,
|
|
} from "./task-flow-registry.store.sqlite.js";
|
|
import type { TaskFlowRegistryStoreSnapshot } from "./task-flow-registry.store.types.js";
|
|
import type { TaskFlowRecord } from "./task-flow-registry.types.js";
|
|
|
|
export type { TaskFlowRegistryStoreSnapshot } from "./task-flow-registry.store.types.js";
|
|
|
|
export type TaskFlowRegistryStore = {
|
|
loadSnapshot: () => TaskFlowRegistryStoreSnapshot;
|
|
saveSnapshot: (snapshot: TaskFlowRegistryStoreSnapshot) => void;
|
|
upsertFlow?: (flow: TaskFlowRecord) => void;
|
|
deleteFlow?: (flowId: string) => void;
|
|
close?: () => void;
|
|
};
|
|
|
|
export type TaskFlowRegistryObserverEvent =
|
|
| {
|
|
kind: "restored";
|
|
flows: TaskFlowRecord[];
|
|
}
|
|
| {
|
|
kind: "upserted";
|
|
flow: TaskFlowRecord;
|
|
previous?: TaskFlowRecord;
|
|
}
|
|
| {
|
|
kind: "deleted";
|
|
flowId: string;
|
|
previous: TaskFlowRecord;
|
|
};
|
|
|
|
export type TaskFlowRegistryObservers = {
|
|
// Observers are incremental/best-effort only. Snapshot persistence belongs to TaskFlowRegistryStore.
|
|
onEvent?: (event: TaskFlowRegistryObserverEvent) => void;
|
|
};
|
|
|
|
const defaultFlowRegistryStore: TaskFlowRegistryStore = {
|
|
loadSnapshot: loadTaskFlowRegistryStateFromSqlite,
|
|
saveSnapshot: saveTaskFlowRegistryStateToSqlite,
|
|
upsertFlow: upsertTaskFlowRegistryRecordToSqlite,
|
|
deleteFlow: deleteTaskFlowRegistryRecordFromSqlite,
|
|
close: closeTaskFlowRegistryDatabase,
|
|
};
|
|
|
|
let configuredFlowRegistryStore: TaskFlowRegistryStore = defaultFlowRegistryStore;
|
|
let configuredFlowRegistryObservers: TaskFlowRegistryObservers | null = null;
|
|
|
|
export function getTaskFlowRegistryStore(): TaskFlowRegistryStore {
|
|
return configuredFlowRegistryStore;
|
|
}
|
|
|
|
export function getTaskFlowRegistryObservers(): TaskFlowRegistryObservers | null {
|
|
return configuredFlowRegistryObservers;
|
|
}
|
|
|
|
export function configureTaskFlowRegistryRuntime(params: {
|
|
store?: TaskFlowRegistryStore;
|
|
observers?: TaskFlowRegistryObservers | null;
|
|
}) {
|
|
if (params.store) {
|
|
configuredFlowRegistryStore = params.store;
|
|
}
|
|
if ("observers" in params) {
|
|
configuredFlowRegistryObservers = params.observers ?? null;
|
|
}
|
|
}
|
|
|
|
export function resetTaskFlowRegistryRuntimeForTests() {
|
|
configuredFlowRegistryStore.close?.();
|
|
configuredFlowRegistryStore = defaultFlowRegistryStore;
|
|
configuredFlowRegistryObservers = null;
|
|
}
|