强化项目总控协作合同与崩溃恢复

新增 Supervisor 协作策略控制面和 mixed 首批原子预检。\n升级 Provider action batch v2 并补齐 isolated spawn 幂等恢复与旧协议失败关闭。\n限制委派后总控项目变更、进程 stdin 和破坏性 MCP,同时保留进程治理能力。\n加固委派、隔离 Agent、持久进程和 Provider 日志的持久化与并发边界。\n扩充确定性回归、真实 Provider 验收器、自测和项目文档。
This commit is contained in:
AIGameCreator App
2026-07-17 23:36:43 +08:00
parent c607451edd
commit 0ca15a2645
18 changed files with 5931 additions and 365 deletions
@@ -1163,6 +1163,22 @@ V1.31 新增独立 `supervisor-swarm-static-isolated-autonomous-chat` 真实 Pro
Runner pidfd 强杀后的 boot、父 context、pending action、两类 durable identity 和完整 Provider identity set 均稳定恢复;isolated mutation action、isolated 文件修改、continuation、重复 delivery/group/instance/result/join/claim/message/action/receipt/Provider lifecycle、残留 sidecar和公共正文/凭据/绝对路径/报告泄漏均为 0。`turn.report=settled`,父计划 4/4 completed,正式 Supervisor assistant 恰好 1,内部专业 assistant 3、isolated assistant 3,最终 disposable 项目与隔离 AppData 均自动清理。此前不完整编排、child 合同不满足、外部 Provider 终态失败和调试验收器误判均各自作为独立失败轮停止,未与本轮 PASS 拼接。
## V1.32 Runtime 强制 Supervisor 协作合同
V1.31 证明真实 Provider 可以自主形成 static + isolated 混合协作,但首波是否完整仍主要依赖 Supervisor prompt。V1.32 把该要求收进 Runtime:项目可在 `.agent/collaboration-policy.json` 声明协作策略,缺失时使用 `requiredInitialWave=auto`、`minStaticDelegates=0`、`requiredStaticAgentIds=[]`、`minIsolatedChildren=0`、`orchestratorOnlyAfterDelegation=true`。该 sidecar 是独立于 `.agent/policy.json` 的项目私有控制面,不扩展 133 处权限策略结构体字面量;通用 `file.list/read/write/patch/delete` 与 patchset 底层路径统一隐藏或拒绝该文件,并在项目锁、verification gate 和 revision 变化前失败,只有宿主配置入口可以原子写入。
- `requiredInitialWave` 只接受 `auto / static / isolated / mixed`;static 与 isolated 模式分别至少要求一项对应协作,mixed 同时要求两类。`minStaticDelegates`、`requiredStaticAgentIds` 和 `minIsolatedChildren` 可进一步收紧,三项必须在单个最多 3 action 的 native Provider 批次内可满足。required Agent ID 只匹配非 repair 的 initial `agent.delegate`,拒绝 `project-supervisor` 与 `child-*` 冒充静态专业 Agent;isolated 最低数量必须由同一个 `agent.spawn_isolated(joinMode=all)` group 的 children 满足,不能把多个不足最低数量的小 group 相加,单个 Provider 批次也最多包含一个 spawn。
- 首波要求尚未满足时,普通读取、`project.verify`、`agent.run_status` 和计划更新仍可进行;一旦 Supervisor 请求项目 mutation 或开始任何一类协作,Runtime 必须整批预检。缺少 required mode、数量或 Agent 时整个计划形成 `runtime.collaboration_policy:blocked` observation,不创建 pending action、provider batch、static delivery、isolated group/child,不推进 project revision,也不执行批次中其它动作。
- 通过预检的 Supervisor 协作批次升级为 Provider action batch v2,并持久化完整策略快照、实际 initial static Agent、isolated child 数量和合同 SHA-256;batchId 同时绑定合同。即使只有一个 delegate/spawn,也强制进入 durable batch。每个成员必须先把 pending action 和 batch 成员共同持久化为 `executing`,随后才能创建 delivery/group 等副作用,成功 observation 落盘后才推进 cursor。恢复、确认和每次 batch 读取都必须先重新校验项目策略、合同和 batch 身份,再考虑 pending action 恢复或 replay;`agent.spawn_isolated` 的 v2 恢复若已存在绑定同一 action 和合同的持久 group/instance,必须复用它们并只补全缺失投影,不得重复创建 group/instance 或重复记录 spawn 审计。策略漂移、合同/动作不一致或旧 v1 协作批次统一进入 `needs-reconciliation`,不能按旧策略启动 child,也不能让已产生的 durable delivery 反过来使当前 batch 自我拒绝。
- `orchestratorOnlyAfterDelegation=true` 时,只要同一父 run 已有非 suppressed static delivery 或 isolated group,或者当前原子批次正在创建协作,Supervisor 都不得执行 `file.write / file.patch / file.delete / project.patchset / project.restore / project.git_commit / command.exec / command.start / command.stdin / canvas.asset_generate`。门禁在批次预检、真实工具 dispatch 前以及 `project.git_commit` / `canvas.asset_generate` 取得项目锁后再次复核;阻断不得创建 confirmation、pending action、revision 或项目副作用。MCP 只有同时声明 `readOnlyHint=true` 与 `destructiveHint=false` 才视为只读,破坏性或注解不完整的 MCP 在首批原子预检和委派后执行阶段都失败关闭。
- 总控只编排门禁继续允许读取、checkpoint/diff、`project.verify`、受限静态验证、进程观察与收束(`command.poll / command.terminate`)、任务编排、黑板/消息、`agent.run_status`、新的合法 isolated 检查,以及继承原合同的唯一 repair `agent.delegate`。专业 Agent 与 isolated child 的既有工具权限不因本条改变。
- finalization 在两类 delivery/join blocker 之外追加协作策略完成门禁。配置要求的 initial static/isolated 事实缺失、required static Agent 不完整或策略 sidecar 损坏时,原 Supervisor run 必须回到 planning,不能提交最终回复。完成事实只来自当前父 run 的 durable delivery/group,不接受 prompt 声明、计划文字或 Agent DB 诊断投影代替。
- 确定性验收至少覆盖:不完整 mixed 首波零 child/零 revision;完整 mixed 首波形成唯一 v2 合同;`executing` 先于首个 durable delivery 且 cursor 正确推进;恢复先验合同并在策略漂移时零 replay;委派后 mutation 在 confirmation 前被拒绝;Git commit 与画板生成在项目锁内再次阻断;破坏性 MCP、策略文件写/patch 和 revision 推进均为 0;repair delegate、isolated spawn、`project.verify` 和读取仍允许;batch round-trip/Runner 恢复保持 batchId、policy/contract fingerprint 和 actionId,重复 child/delivery/group 为 0。真实 Provider 另建 V1.32 suite,不能把 V1.31 的一次成功样本外推为 Runtime 合同已验收。
2026-07-17 在最终代码 diff 上使用 `gpt-5.5 / openai_chat / high` 完成 V1.32 独立真实 PASS。`supervisor-swarm-collaboration-policy-mixed-recovery` 只在隔离 AppData 配置副本中把瞬态重试设为 `maxRetries=2 / retryBackoffMs=500`,正式 AppData、源配置和 Runner endpoint 均未修改;86 个 Provider lifecycle 全部完成,本轮未触发重试。首批 v2 batch 固化 3 个 action,包含 2 个指定 static delegate 与 1 个三 child isolated spawn;waiting-confirmation 零副作用边界、pidfd 强杀恢复、batch/contract/action identity、两类 Provider 重叠、1 次 repair、3 个 delivery、1 个 isolated group/3 个 instance/3 个 result/1 个 claimed join、宿主验证和唯一 Supervisor assistant 全部通过。
成功报告共记录 178 个 task snapshot、326 个 event、556 个 Agent DB record、30 个 action execution 和 38 个 receipt;重复 delivery/group/instance/result/join/claim/message/action/receipt/Provider lifecycle 与 pending/batch/finalization/confirmation sidecar 均为 0,私密正文、Provider payload、API Key、项目路径、正式配置路径和最终报告泄漏均为 0。`turn.report=settled` 且 reconciliation Agent 为 0。49 次 native tool plan 中发生 30 次格式修复,未破坏动作幂等与最终结果,但说明真实链路仍有明显延迟和 Provider 调用成本,后续应单独收敛工具合同表达和 repair 频率。
## 验收命令
- `cargo test --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml structured_plan_ -- --nocapture`
@@ -1173,6 +1189,8 @@ Runner pidfd 强杀后的 boot、父 context、pending action、两类 durable i
- `cargo test --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml provider_action_batch_ -- --nocapture`
- `cargo test --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml parallel_read_batch_ -- --nocapture`
- `cargo test --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml project_supervisor_mixed_ -- --nocapture --test-threads=1`
- `cargo test --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml supervisor_collaboration_ -- --nocapture --test-threads=1`
- `npm run agc:collaboration-policy-e2e -- --config-dir <AppData>`
- `npm run agc:mixed-swarm-e2e -- --config-dir <AppData>`
- `cargo test --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml swarm_cli::tests -- --nocapture`
- `cargo test --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml typed_goal_pause_and_cancel_require_durable_intent_and_keep_exact_run -- --nocapture`
@@ -592,3 +592,5 @@ game-project/
- 2026-07-17 Runtime V1.31 的同父 run 混合协作门禁已完成独立真实 PASS;详细业务任务边界、首批 confirmation gate、static/isolated durable 合同、三条确定性回归、真实报告数字和失败轮隔离记录统一以同一 Runtime 文档的“V1.31 Project Supervisor 静态与隔离子 Agent 混合协作门禁”为事实源。App 侧复验入口为 `npm run agc:mixed-swarm-e2e -- --config-dir <AppData>`,不在实施计划重复维护一次性拓扑和计数。
- `agent.message` 使用来源 Agent/run、目标 Agent/Session 和清洗后正文 SHA-256 形成稳定语义身份。同一语义消息只允许写 1 条目标 tool conversation、1 条 `conversation.message` 和 1 条 `agent.runtime.agent.message`;后续 Runtime action 仍完整落账,但返回 `messageAppended=false` 且不算新的 loop 进展。专业 Agent 不得用重复消息替代最终回执;持续重复时最多经过当前 6 轮停滞窗口即以 `loop-budget-exhausted` 失败,保留 `in_progress` 计划且不写 completed。完整后台回归同时断言 6 个 actionId、同一 action fingerprint、6 组 action/observation/receipt、消息持久化唯一、receipt 零正文、第 7 次 Provider 请求为 0。
- 开发模式可通过本地项目文件面板执行 `file.list/read/write/delete`,普通用户界面不暴露文件面板。
- 2026-07-17 起,同一 Runtime 文档的“V1.32 Runtime 强制 Supervisor 协作合同”作为 mixed swarm 可靠性事实源。项目可用 `.agent/collaboration-policy.json` 约束首波 static/isolated 模式、数量和 required static Agent;Runtime 在任何 child 副作用前整批校验并把合同指纹固化进 Provider batch v2。当前父 run 一旦形成 delivery/group,正式 `project-supervisor` 默认只负责编排、状态认领和验证,不再直接执行项目 mutation;专业 Agent/isolated child 权限与唯一 Supervisor 最终回复边界保持不变。
- 2026-07-17 V1.32 最终代码已完成独立真实 Provider PASS:首批 mixed batch、三 isolated child、Runner 强杀恢复、专业返工、宿主验证、唯一最终回复与零重复/残留/泄漏同时成立。真实报告计数、隔离重试配置和仍待收敛的 tool-plan repair 成本统一以 Runtime 文档 V1.32 章节与共享决策记录为准。