# lite-work-flow-v2 **Repository Path**: gamains/lite-work-flow-v2 ## Basic Information - **Project Name**: lite-work-flow-v2 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-31 - **Last Updated**: 2026-08-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Lite Workflow V2 Lite Workflow V2 是一个无历史包袱重写的 Java 21 持久化执行解释器。它把静态操作图编译成不可变 Plan,再通过 Run 状态、持久化事实和可恢复的 Runtime 推进执行。 V2 不继承 V1 的 `Workflow`、`Node`、`Executor`、`Scheduler`、TaskExecution、数据库表或 API。设计基线见 [V2_DESIGN_REVIEW.md](docs/V2_DESIGN_REVIEW.md),运行架构见 [V2_RUNTIME_ARCHITECTURE.md](docs/V2_RUNTIME_ARCHITECTURE.md),Plan Artifact contract 见 [V2-10A_PLAN_ARTIFACT.md](docs/V2-10A_PLAN_ARTIFACT.md),SQLite Store 设计见 [V2-10B_SQLITE_PLAN_ARTIFACT.md](docs/V2-10B_SQLITE_PLAN_ARTIFACT.md),RunLauncher 和运行态来源身份见 [V2-10C_RUN_LAUNCHER.md](docs/V2-10C_RUN_LAUNCHER.md),PayloadStore contract 见 [V2-12_PAYLOAD_STORE.md](docs/V2-12_PAYLOAD_STORE.md),PayloadRef 与 Run 原子绑定设计见 [V2-12B_RUN_PAYLOAD_ATOMICITY.md](docs/V2-12B_RUN_PAYLOAD_ATOMICITY.md),可交互架构图见 [v2-runtime-architecture.html](docs/v2-runtime-architecture.html)。 ## 核心模型 外部输入与 callback payload ingress 设计见 [V2-12C_PAYLOAD_INGRESS.md](docs/V2-12C_PAYLOAD_INGRESS.md)。 ```text immutable Plan -> Run mailbox + pure reducer -> snapshot + journal + inbox/outbox/timer -> at-least-once Capability command -> callback/query/reconcile/recovery ``` 核心承诺是:状态变化由 Kernel 决定,提交由 Store 的 revision/CAS 和幂等 identity 仲裁,外部副作用由 Capability 隔离,进程崩溃后由 durable work reconcile 恢复。外部系统的 exactly-once 仍需要 provider 通过幂等键或查询协议参与,不能由本地代码凭空保证。 ## 模块 | 模块 | 职责 | |---|---| | `lite-workflow-v2-model` | identity、Plan input model、Capability contract、StructuredValue | | `lite-workflow-v2-kernel` | Plan Compiler、Run/Action/Attempt 状态和纯 reducer | | `lite-workflow-v2-spi` | RuntimeStore、Mailbox、Outbox、Timer、Capability 等端口 | | `lite-workflow-v2-adapter-memory` | InMemory Store、PayloadStore、Mailbox、Outbox、Timer 和 fake Capability | | `lite-workflow-v2-registry` | 控制面 Plan 编译、Artifact 发布和完整引用读取 | | `lite-workflow-v2-adapter-sqlite` | SQLite schema、Plan Artifact/Payload/Run codec、Plan Artifact/Payload Store、Run/Runtime Store 和 callback replay adapter | | `lite-workflow-v2-runtime` | RuntimeEngine、RunLauncher、Host admission、Coordinator、recovery、quarantine、metrics | | `lite-workflow-v2-host-scheduled` | 可选 JDK ScheduledExecutorService 驱动、worker、reconcile 和有限关闭 | | `lite-workflow-v2-host-reference` | 显式 SQLite bootstrap、Reference Host 和 one-shot smoke application | 依赖方向保持单向: ```text host-scheduled -> runtime -> spi/model/kernel registry -> spi/kernel/model adapter -> spi/model/kernel ``` 核心 Runtime 不绑定 Spring、HTTP、消息系统、JDBC 连接池或某种部署线程模型。Scheduled Host 只是可选的宿主便利层,不是 V1 Scheduler 的回归。 ## 已完成闭环 - V2-01A~V2-01J:Plan/DAG、状态归约、retry、UNKNOWN、timeout、pause/resume、cancel、optional skip。 - V2-02A~V2-02D:Decision/commit identity、严格 InMemory Store、Capability command、outbox/timer/mailbox、原子 Runtime commit、crash/restart、backpressure、shutdown drain。 - V2-03A~V2-03E:SQLite bootstrap、RunStore、outbox/timer/mailbox、RuntimeStore 原子 replay、append-only journal。 - V2-04A~V2-04B:SQLite Runtime 集成和 `RuntimeEngine` 正式 API。 - V2-05A~V2-05I:Capability identity/registry/descriptor/lifecycle、durable timeout、callback ingress、Plan binding、非幂等 retry policy。 - V2-06A~V2-06C:Host readiness、低基数 metrics、graceful shutdown runbook。 - V2-07A~V2-07D:Kernel error isolation、跨 Run 公平 queue、quarantine recovery/audit、callback HMAC/replay security、durable work reconciliation。 - V2-08A:Host/Coordinator operational snapshot 和低基数观测边界。 - V2-08B:可选 Scheduled Host Driver;详见 [V2-08B_SCHEDULED_HOST.md](docs/V2-08B_SCHEDULED_HOST.md)。 - V2-09A:SQLite Reference Host、显式 schema bootstrap、重启保留和 one-shot 示例;详见 [V2-09A_REFERENCE_HOST.md](docs/V2-09A_REFERENCE_HOST.md)。 - V2-10A:Plan Artifact 内容寻址、不可变发布、版本坐标和 hash mismatch 校验;详见 [V2-10A_PLAN_ARTIFACT.md](docs/V2-10A_PLAN_ARTIFACT.md)。 - V2-10B:SQLite Plan Artifact Store、显式 schema contract、共享 codec、重启读取和损坏 fail-closed;详见 [V2-10B_SQLITE_PLAN_ARTIFACT.md](docs/V2-10B_SQLITE_PLAN_ARTIFACT.md)。 - V2-10C:RunLauncher 按完整 ArtifactRef 创建 Run,RunState 保存 PlanRef 与 CompiledPlan 快照;当前 writer 使用 run-state/4,并向后兼容 run-state/2、run-state/3;详见 [V2-10C_RUN_LAUNCHER.md](docs/V2-10C_RUN_LAUNCHER.md) 和 [V2-12B_RUN_PAYLOAD_ATOMICITY.md](docs/V2-12B_RUN_PAYLOAD_ATOMICITY.md)。 - V2-10D:PlanArtifactCatalog metadata-only 查询、稳定 keyset 分页和 Registry PlanCatalog facade;详见 [V2-10D_PLAN_CATALOG.md](docs/V2-10D_PLAN_CATALOG.md)。 - V2-11:RuntimeEngine facade 与 package-private RuntimeCore 收敛,移除历史 InMemoryRuntime 实现名;详见 [V2-11_RUNTIME_CORE_MIGRATION.md](docs/V2-11_RUNTIME_CORE_MIGRATION.md)。 - V2-12:不可变 SHA-256 PayloadStore、Memory/SQLite BLOB adapter 和独立 payload/1 schema contract;详见 [V2-12_PAYLOAD_STORE.md](docs/V2-12_PAYLOAD_STORE.md)。 - V2-12B:已完成 `ActionOutput` one-of、Memory/SQLite payload 与 Run snapshot 原子绑定、旧 codec 兼容读取和 host-managed schema readiness;详见 [V2-12B_RUN_PAYLOAD_ATOMICITY.md](docs/V2-12B_RUN_PAYLOAD_ATOMICITY.md)。 ## 快速验证 ```bash mvn clean test ``` Scheduled Host 的最小装配顺序是: ```java RuntimeEngine engine = new RuntimeEngine(store, mailbox, capability, commandFactory, lease); RuntimeCoordinator coordinator = new RuntimeCoordinator(engine, 1_000); RuntimeHost host = new RuntimeHost(engine, readinessChecks); try (ScheduledRuntimeDriver driver = new ScheduledRuntimeDriver( host, coordinator, ScheduledRuntimeDriverConfig.defaults() )) { RuntimeReadiness readiness = driver.start(); if (!readiness.ready()) { throw new IllegalStateException("Runtime is not ready"); } host.enqueue(runId, messageId, input, clock.instant()); driver.signal(runId); } ``` 应用负责装配 adapter、schema、Capability provider、HTTP/message ingress、health/metrics exporter 和备份恢复流程。driver 崩溃或关闭不会删除未完成的 durable work;新进程启动时仍必须执行 reconcile。 ## 当前生产化边界 当前仓库已经覆盖执行语义、持久化正确性、Plan Artifact 发布与运行态来源身份、不可变 PayloadStore、PayloadRef 与 Run 状态原子绑定、恢复、安全边界、单进程公平调度、可选默认驱动,以及内存态和 SQLite contract。尚未内置的生产应用层包括:SQLite schema migration/backup 自动化、HTTP callback adapter、Schema/Capability registry、payload archive/GC、日志/trace/exporter、故障注入与性能 soak,以及真正的多实例分片和全局限流。这些能力应继续以独立闭环演进。