feat(tasks): OpenWorkflow-backed TaskEngine, task registry, outbox relay and op-ledger fencing (W1-4)

- TaskEngine port + OpenWorkflowEngine ([email protected].1, schema openworkflow):
  enqueue/signal/cancel/get/list/startWorker/stop
- defineTask registry with zod input schema; 9 stub task definitions (§3.1-8)
- TaskContext: step.run/sleep/waitForFact, redacting logger, traceId,
  attemptToken, abortSignal driven by PG cancel flag
- signal persists fact to tasks_fact first; waitForFact checks DB before waiting
- OutboxRelay: FOR UPDATE SKIP LOCKED, idempotencyKey outbox:<id>
- withAttemptToken fencing on tasks_op_ledger (own migration, merged in W2)
- tests: kill -9 crash recovery (child worker), cancel, idempotency,
  concurrent relays, early fact, lease-loss fencing

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
rootandClaude Fable 5.1 committed 2026-09-27 17:51:21 +08:00
1 parent ec023a8405
commit 1262340856
22 files changed
+1818 -8

No files matched your search

+46 -1
View File
@@ -1,2 +1,47 @@
// @umt/tasks 公开入口;W1 起在此导出实现
// @umt/tasks 公开入口:TaskEngine 端口 + OpenWorkflow 实现、任务注册表、outbox 中继、操作账本 fencing
export const PACKAGE_NAME = "@umt/tasks";
export {
cleanupDownloadCache,
createDefaultRegistry,
evaluateAcquisition,
ingestFeed,
reconcileLibrary,
refreshMetadata,
resolveDecision,
resolveObservation,
submitDownload,
TASK_NAMES,
type TaskName,
verifyAndImport,
} from "./definitions";
export { FencingError, TaskCanceledError, UnknownTaskError } from "./errors";
export {
consoleSink,
createLogger,
type LogLevel,
type LogRecord,
type LogSink,
redact,
silentSink,
type TaskLogger,
} from "./logger";
export { migrateTasksTables, TASKS_MIGRATIONS_DIR } from "./migrate";
export {
type AttemptInfo,
assertAttemptToken,
getOperation,
type OpLedgerRow,
type WithAttemptTokenOptions,
withAttemptToken,
} from "./op-ledger";
export { ENGINE_SCHEMA, OpenWorkflowEngine, type OpenWorkflowEngineOptions, signalName } from "./openworkflow-engine";
export {
type OutboxEvent,
OutboxRelay,
type OutboxRelayOptions,
type OutboxRoute,
type OutboxRouteFn,
} from "./outbox-relay";
export { defineTask, type TaskDefinition, TaskRegistry } from "./registry";
export type * from "./types";