Pre-alpha 文档
依据持久化证据驱动 Graph。
冻结精确可执行绑定、验证非初始 Replay,并在不削弱 Crash Recovery 的前提下集成 StateKnot 带 Fence 的可恢复 Graph Driver。
冻结一份精确可执行部署
Scheduler 开始 Claim 前必须完成注册表构建。每份 JSON Schema 都必须离线可用、符合 JSON Schema 2020-12、使用 RFC 8785 Canonical Bytes,并由 SHA-256 Digest 固定。 每个完整 Graph Digest 必须闭合到唯一 Reducer 与全部已声明 Node Executor。缺失、 重复、不匹配、无法解析或孤立的绑定都会拒绝启动。
let mut schemas = JsonSchemaRegistryBuilder::with_default_limits();
register_standard_graph_driver_event_schema(&mut schemas)?;
register_standard_graph_lifecycle_event_schema(&mut schemas)?;
register_standard_agent_cancellation_event_schema(&mut schemas)?;
register_application_schemas(&mut schemas)?;
let mut executables = ExecutableGraphRegistryBuilder::new(schemas.build()?);
executables.register_graph(compiled_graph)?;
executables.register_reducer(reducer)?;
for executor in node_executors {
executables.register_node(executor)?;
}
let driver = DurableGraphDriver::new(
store,
executables.build()?,
DurableGraphDriverOptions::default(),
)?;
标准审计 Schema 必须通过注册函数安装,其不可变 Identity 为https://stknot.com/schemas/runtime/graph-driver-event/1.0.0。不要在应用代码中手工写死 Digest。
Agent Loop 部署还必须通过
register_standard_graph_lifecycle_event_schema 安装https://stknot.com/schemas/runtime/graph-lifecycle-event/1.0.0。
Lifecycle 部署还必须通过 register_standard_agent_cancellation_event_schema 安装https://stknot.com/schemas/runtime/agent-cancellation-event/1.0.0。
先 Replay,再执行
已 Claim 的 Run 会先重新加载并编译 Checkpoint-pinned Graph。Runtime 随后使用 精确安装的 Schema 与 Reducer,在有界 Pending-result 内存中重放每个已提交非初始 Checkpoint,同时验证 Journal Anchor、Parent Checkpoint 与不可变 Ready Set。任何 Durable Evidence 缺失或矛盾都会在 Node 代码运行前,由当前 Live Fence 把 Run Quarantine。
Committed Start 才是执行授权
Driver 会先提交 Physical Node-attempt Start,再启动 Node 代码。只有新返回
NodeAttemptCommitOutcome::Committed 才会调用 Executor。Idempotent Start 可能表示 ACK 丢失或另一个执行器已经写入,因此一律按 In-flight 处理。
Node 运行期间不会持有数据库事务。Driver 会在启动前刷新临近过期的 Lease,并在 数据库时间换算的单调到期 Watchdog 下续租、传播单调 Cancellation Signal、执行硬 Deadline,并按最新 Journal Head 提交 Completion。外部 Model/Tool 副作用必须 进入各自 Invocation Ledger;Node 内裸写外部系统无法继承 Reconciliation 保证。
Process Shutdown Signal 与已持久化的 Run 取消请求是不同边界。Node Active 期间,Driver 会轮询 Run Projection;观察到 Cancellation Request 后停止新 Dispatch、向 Node 发出 Signal、执行有界 Cooperative Grace Period,再返回精确 Lifecycle Handoff。
let claim = store
.claim_lease(&tenant_id, run_id, attempt_id)
.await?;
let result = driver
.drive(claim.lease().fence().clone(), shutdown_signal)
.await?;
let (outcome, report) = result.into_parts(); 允许工作重叠,但不让时序成为语义
Executor 默认保持 Exclusive。只有当执行过程不追加 Run Journal
或 Invocation-ledger Fact,且 Result 不依赖 Sibling Timing 时,才能声明 JournalIsolated。这是可信 Deployment Contract;外部 Model/Tool
工作必须进入有序、支持持久执行的 Coordinator。
Driver 先按 Canonical NodeId 顺序串行提交全部 Fresh Start,再让
Eligible Batch 共用一套 Lease/Cancellation Watchdog。乱序完成会先缓冲,再按相同顺序提交
Terminal Fact。实际 Width 同时受 Process Policy、Compiled Graph Policy、Ready
Work 与剩余 Event Quantum 限制;Exclusive Node 会形成 Batch Boundary。
impl GraphNodeExecutor for ReadOnlyComputeNode {
fn scheduling(&self) -> GraphNodeScheduling {
GraphNodeScheduling::JournalIsolated
}
// graph()、node_id() 与 execute() 省略
}
let options = DurableGraphDriverOptions::default()
.with_parallel_node_limit(8)?; 显式处理每种 Outcome
-
LifecycleBarrierReady - 立即补齐 Wait 或成功 Terminal 元数据,并使用 Handoff 原样携带的 Plan、Journal Head、Revision 与 Live Lease 完成一次原子 Provider Commit。禁止序列化或重建该 Handoff。
-
Blocked - 同一 Fence 下的 In-flight 工作不能再次 Dispatch。Failed 或 Exhausted 必须把 Plan 的精确证据交给 Run-level Failure Policy,禁止自行推导 Retry 权限。
-
Deferred - 数据库时间驱动的 Wakeup 与 Lease Release 已经持久化,不能再创建第二个进程内 Timer。
-
Yielded - 有界 Durable-event Quantum 在两次 Mutation 之间结束,Lease 已释放;通过 Scheduler Discovery 与新 Claim 再次进入。
-
CancellationRequested - 已经观察到已持久化的 Run 取消请求。必须使用精确 Lease-bound Handoff 完成 Lifecycle Confirmation;DurableAgentLoop 会自动执行且不会虚构 Usage。
-
Cancelled - 进程拥有的 Shutdown Signal 停止本地工作并释放精确 Fence;下一次 Claim 根据持久化记录恢复执行。
普通应用 Worker 应使用DurableAgentLoop 把这些 Handoff 绑定到原子 Lifecycle Commit 与 Exact-fence Error Cleanup。
限制时间、内存与 Mutation Retry
-
GraphReplayLimits默认允许每个历史 Barrier 保留 64 MiB Compact Result,硬上限为 512 MiB。 -
一次
drive默认最多处理 1,024 个 Driver-owned Durable Event,并且只在 Durable Operation 之间 Yield。 - Ready-node 并发默认值为 1,必须显式开启,进程内硬上限为 64。
- Renewal Interval 必须至少能在 Provider Lease Duration 中容纳三次;默认 Node Deadline 为 15 分钟。
- Cancellation Polling 与 Cooperative Grace 默认分别为 250 ms 与 5 s,硬上限分别为 60 s 与 5 分钟。
- Storage Mutation Retry 有明确次数上限,复用相同 Durable Event/Attempt Identity, 并采用封顶指数退避。
生产监控应从 GraphDriveReport 采集 Replay 数量与保留字节、Attempt
Start/Completion、Batch 数与最大实际 Width、Continue Barrier、Lease Renewal
和 Mutation Retry。
Crash Recovery 只有一条授权路径
-
Same Fence
未完成 Attempt 保持 In-flight,同一 Fence 不能重复启动。
-
Higher Fence
Lease 到期或可信 Supersession 后,后继 Fence 只能接管未完成 Physical Attempt 一次。
-
Continue Barrier
Driver 消费完整 Result Set,原子提交 Successor Checkpoint,并在下一次非初始 Replay 中独立验证。
-
Wait 或 Terminal
Driver 保留精确 Lease,返回短生命周期 Commit Handoff,不会虚构不属于自己的 Lifecycle Metadata。
-
Cancellation
Driver 把精确持久化 Intent 交给 Lifecycle。精确 Ledger Usage 与数据库时间会成为一条 Terminal Confirmation;Evidence 不可用时保留可恢复 Request。
验证证据
CI 在 PostgreSQL 16 与 17 上分别运行强制 Runtime 测试集。八个保留 Driver 恢复/排序覆盖:Continue 后的非初始 Replay 与 Terminal Handoff、Same-fence 重复抑制、通过续租执行超过原始 Lease、Node 启动前刷新临近过期 Lease、执行前隔离非法初始状态、Higher-fence Takeover、三个 Sibling 反向完成但按 Canonical 顺序提交,以及 Higher Fence 接管 Orphaned Parallel Member;其余场景覆盖 Success/Wait/Failure/Cancellation Lifecycle 原子提交、精确 Lost-ACK Recovery、Agent Loop Cleanup、Tenant 与加权 Scheduling、可恢复 Model/Tool 执行、Streaming、 Provider-native 多轮 Recovery、精确 Cancellation、原子 Agent Admission 与持久化 Run/Result Read。每个数据库版本还会运行 Provider 测试集。部署这个 Pre-alpha Surface 前请阅读完整的集成与运维契约。