Просмотр исходного кода

文档:同步阶段一真实实现边界和旧代码基线

将旧业务基线校正为脚本构建第二版的真实分支与提交,移除失效绝对路径。

记录运行配置解析器、通用派发合同、生产组装、Direction partial 检查点,并明确阶段一协作停止与阶段三恢复能力的边界。
SamLee 18 часов назад
Родитель
Сommit
eff9d8f82d
2 измененных файлов с 38 добавлено и 25 удалено
  1. 1 3
      智能创作构建系统产品方案.md
  2. 37 22
      智能创作构建系统技术方案.md

+ 1 - 3
智能创作构建系统产品方案.md

@@ -1206,9 +1206,7 @@ Task、Attempt、Validation、Decision 和 Trace 可用于解释这份脚本如
 
 ## 附录 C:事实证据入口
 
-老版代码根目录:
-
-`/home/sam/image_article_comprehension/aiddit/pattern/patter_from_global_and_build`
+老版代码基线:仓库 `脚本构建第二版`、分支 `script_build_refactor_0709`、提交 `3b2db592079a`,业务目录为 `aiddit/pattern/patter_from_global_and_build`。
 
 建议核对顺序:
 

+ 37 - 22
智能创作构建系统技术方案.md

@@ -37,13 +37,13 @@
 
 ### 1.1 上一代代码
 
-上一代真实代码位于:
+上一代真实代码位于仓库 `脚本构建第二版` 的目录
 
 ```text
-/home/sam/image_article_comprehension/aiddit/pattern/patter_from_global_and_build
+aiddit/pattern/patter_from_global_and_build
 ```
 
-审查基线为分支 `script_build_refactor_0709`、提交 `cc0e2a5`。真实业务入口、Prompt、工具、ORM、模板和静态脚本均来自该目录;本文不根据工具 Schema 数量猜测运行能力。
+审查基线为分支 `script_build_refactor_0709`、提交 `3b2db592079a`。真实业务入口、Prompt、工具、ORM、模板和静态脚本均来自该目录;本文不根据工具 Schema 数量猜测运行能力。
 
 上一代的核心运行逻辑是:
 
@@ -189,7 +189,7 @@ TopicBuildRecord
 冻结内容包括:
 
 - always-on 策略全文;
-- on-demand 策略摘要、ID、版本和内容 hash
+- on-demand 策略全文、mode、ID、版本和内容 hash;是否主动采用仍由 Planner 决定,冻结全文只用于保证后续读取不漂移
 - 主 Agent、Worker、Validator 的 preset 名称与 Prompt 版本;
 - 实际解析到的 Prompt 来源、`biz_type`、版本和 SHA-256;
 - 模型名、关键采样配置以及数据源配置版本。
@@ -330,7 +330,7 @@ script_build_host/
 - Attempt、固定 child Decision 输入;
 - ArtifactSnapshot、Validation、Planner Decision;
 - capability 权限边界;
-- `wire_orchestration()` 的通用可选注入点:`validation_policy`、`deterministic_validator`、`evidence_provider`;旧位置参数调用保持兼容;
+- `wire_orchestration()` 的通用可选注入点:`validation_policy`、`deterministic_validator`、`evidence_provider`、`role_run_config_resolver`;旧位置参数调用保持兼容;
 - Operation、Event、Trace 和 V2 读取接口;
 - `FileSystemTaskStore` 的 revision/CAS、文件锁和原子替换,以及 `FileSystemArtifactStore` 的文件锁/first-write-wins;TraceStore 不具同等级跨进程写保证。
 
@@ -346,19 +346,25 @@ script_build_host/
 
 ### 4.2 部署约束
 
+阶段一已提供 `compose_production_host()` 和固定单 worker 的 `script-build-host` 启动入口。部署方必须通过 `SCRIPT_BUILD_RUNTIME_FACTORY=module:callable` 显式注入真实 `AgentRunner`、`PrincipalProvider` 和 `BuildAuthorizer`;缺少认证依赖、durable TraceStore、生产 Decode Endpoint 或读写账号未分离时启动失败。Host 自己组装 SQLAlchemy read/write sessions、四张业务表 Repository、旧输入只读 Adapter、FileSystem Task/Artifact Store、OutboundPolicy、上传 Topic 与图片 raw Artifact Store,不复制 Executor/Coordinator。
+
+生产 Decode 只走配置且经 allowlist 的 HTTPS Adapter;文件词法 Decode 仅用于 `environment=test` 的固定 fixture。外部 endpoint、DNS 和每次 redirect 在启动/请求时重新校验,响应以流式字节上限读取;上传 JSON 与图片另有数量、单体和总字节门禁。阶段一内置的 8 个 preset Prompt 来自实际打包 `.md` 文件,内容、source、version 与 SHA-256 一并进入 InputSnapshot,而不是只记录文件名。
+
 框架 Store 目录必须位于持久盘:
 
 ```text
-{agent_data_root}/{root_trace_id}/orchestration/ledger.json
-{agent_data_root}/{root_trace_id}/orchestration/artifacts/*.json
+{agent_data_root}/task-ledger/{root_trace_id}/orchestration/ledger.json
+{agent_data_root}/framework-artifacts/{root_trace_id}/orchestration/artifacts/*.json
 {agent_data_root}/{trace_id}/meta.json
 {agent_data_root}/{trace_id}/messages/
 ```
 
-同一 `root_trace_id` 只能被一个活动 Host 进程驱动。文件锁保护 Ledger 提交,但 `OperationRuntime` 和正在执行的模型调用仍是进程内对象,因此不能把共享盘上的多个进程当作分布式调度器。进程重启后执行显式 recovery:对旧 RUNNING Attempt 不猜测、不接管模型上下文,按框架规则失败/重新规划
+同一 `root_trace_id` 只能被一个活动 Host 进程驱动。文件锁保护 Ledger 提交,但 `OperationRuntime` 和正在执行的模型调用仍是进程内对象,因此不能把共享盘上的多个进程当作分布式调度器。阶段一进程重启后只允许读取 Ledger、Trace、Snapshot 和 Artifact,不猜测并重跑模型;显式 resume/recovery、旧 RUNNING Attempt 对齐和跨进程 OwnerLease 留到阶段三
 
 ## 5. `script_build_host/` 模块设计
 
+下列是三阶段最终模块边界;阶段一只落地其中输入、Mission、Direction/Evidence、观测和 production composition 所需文件,`publisher.py`、`recovery_service.py`、`legacy_detail_projection_service.py` 以及正文领域文件仍未实现。
+
 ```text
 script_build_host/
   api/
@@ -553,21 +559,27 @@ async def run(self, script_build_id: int) -> None:
         completion = await self.coordinator.root_completion(
             binding.root_trace_id
         )
-        if completion["status"] == "completed":
-            await self.finalize_accepted_root(
-                script_build_id, binding.root_trace_id
-            )
-        else:
-            await self.status_projector.project_non_success(completion)
+        if (
+            completion["status"] != "blocked"
+            or completion.get("blocked_reason")
+            != "PHASE_ONE_CAPABILITY_BOUNDARY"
+        ):
+            raise ProtocolViolation("mission did not stop at phase-one boundary")
+        await self.direction_reconciler.reconcile(
+            script_build_id, binding.root_trace_id
+        )
+        await self.legacy_state.set_status(script_build_id, "partial")
     except Exception as exc:
         await self.status_projector.project_runtime_failure(exc)
         raise
 ```
 
-`AgentRunner.run()` 是 async iterator,不能直接 `await`;服务模式使用 `run_result()` 消费完整事件流,若需要流式投影则显式 `async for`。`RunConfig` 必须使用 `explicit_validation`、`script_planner` preset 和 Root Task draft dict。当前 `wire_orchestration()` 以可选关键字参数暴露 `validation_policy`、`deterministic_validator`、`evidence_provider`,并保留原有 3~5 个位置参数调用语义;阶段一由 composition root 实例化脚本领域实现后显式注入,不再由业务 Host 直接构造 `TaskCoordinator` 或复制 `LocalAgentExecutor`、`runner.task_coordinator` 的框架装配逻辑。未传入时仍使用原有默认 Agent Validator,Evidence Provider 仍为空
+`AgentRunner.run()` 是 async iterator,不能直接 `await`;服务模式使用 `run_result()` 消费完整事件流,若需要流式投影则显式 `async for`。`RunConfig` 必须使用 `explicit_validation`、`script_planner` preset 和 Root Task draft dict。当前 `wire_orchestration()` 以可选关键字参数暴露 `validation_policy`、`deterministic_validator`、`evidence_provider` 和 `role_run_config_resolver`,并保留原有 3~5 个位置参数调用语义。Resolver 获得的是深复制、递归只读 context,只能从冻结模型配置解析 Worker/Validator 的 model、temperature 和 max_iterations这三个受信字段可优先于 preset 默认值,但不能覆盖 Trace 身份、protected context、工具或 completion policy。Planner 框架合同只要求使用 preset 暴露的 task-dispatch tool,不再硬编码工具名 `dispatch_tasks`。阶段一由 composition root 实例化脚本领域实现后显式注入,不再由业务 Host 直接构造 `TaskCoordinator` 或复制 `LocalAgentExecutor`、`runner.task_coordinator` 的框架装配逻辑。未传入时仍使用原有默认行为
 
 ### 6.5 stop/resume/recovery
 
+阶段一只实现同进程 cooperative stop:旧业务状态 `stopping` 就是持久 stop intent,Host 以同一进程内 `BuildTransitionGate` 串行化 Direction publication 与 stop intent,停止 active Operation 并通知当前 Planner runtime;全部终止后才投影 `stopped`,超时继续保持 `stopping`。跨进程 OwnerLease、resume/recovery 与进程崩溃后的 publication 竞态恢复仍属于阶段三。
+
 `stop()`:
 
 1. 读取一次 Mission Snapshot;
@@ -577,7 +589,7 @@ async def run(self, script_build_id: int) -> None:
 5. 超时则保持 `stopping`,记录脱敏、可恢复原因,不能假称已停止;
 6. 保留 Ledger、Trace、候选和发布记录,且 stop 路径不得执行发布。
 
-`resume()`:
+以下 `resume()` 是阶段三设计,阶段一未挂载也不会自动执行
 
 1. 获取 build/root 的单活所有权锁;锁冲突返回稳定 `409 MISSION_ALREADY_OWNED`;
 2. 若旧业务状态已是 `success`,验证 publication/digest 后幂等返回,绝不重开 Planner;
@@ -591,7 +603,7 @@ async def run(self, script_build_id: int) -> None:
 
 - Ledger 有 Operation:`recover_operations()` 只对齐持久状态。未安全启动的 pending 可保留;已启动但进程丢失的 stage 归一为 stopped/expired/failed,不能自动调用模型;
 - 前台遗留 Attempt 无 Operation 且 `started_at is None`:尚未启动 Worker,才允许安全 `advance_cycle()`;
-- 前台遗留 Attempt 无 Operation 且 `started_at is not None`:禁止重跑同一 Attempt,避免重复外部副作用。当前框架没有公开的 foreground orphan 原子恢复命令,因此生产 Script preset 必须排除同步 `dispatch_tasks`,只开放 Host 包装的 `dispatch_script_tasks`;该工具内部使用 `start_operation()` 创建 durable BackgroundOperation 并等待/轮询。若未来保留前台路径,须先新增通用 Coordinator recovery command,原子将 Attempt 标为 stopped/failed、Task 转 needs_replan;
+- 前台遗留 Attempt 无 Operation 且 `started_at is not None`:禁止重跑同一 Attempt,避免重复外部副作用。当前 `TaskCoordinator.dispatch_tasks()` 已经通过 `start_operation()` 创建 durable BackgroundOperation 并等待结果;Host 仍只开放 `dispatch_script_tasks`,其价值是校验 Script worker preset 白名单、Task 类型和 protected identity,而不是复制 Operation 实现。若未来保留无 Operation 的遗留前台路径,须先新增通用 Coordinator recovery command,原子将 Attempt 标为 stopped/failed、Task 转 needs_replan;
 - `accepted_child_decision_ids=None`:遗留协议未知,仍由现有 `advance_cycle()` 走 `PROTOCOL_VIOLATION`,不得猜测子输入;
 - `resume_operation()` 只允许框架判断为未安全启动的 stage;已启动后停止的模型 stage 返回 `resume_not_safe`,交给 Planner retry/replan;
 - Root completed:不调用上述模型恢复,只走同一 Artifact 的 Publisher 重试。
@@ -1189,19 +1201,22 @@ Root Validator 通过后,Planner ACCEPT。Publisher 将同一 frozen Artifact
 实现:
 
 - `script_build_host/` composition 和配置;
-- 通过框架 `wire_orchestration()` 注入 ScriptBuild ValidationPolicy、DeterministicValidator 和 EvidenceProvider;
+- 通过框架 `wire_orchestration()` 注入 ScriptBuild ValidationPolicy、DeterministicValidator、EvidenceProvider 和 RoleRunConfigResolver;
 - 四张业务表的 migration 基础版本;
 - InputSnapshotService 和真实旧数据 Adapter;
+- Evidence/Direction 的 append-only ArtifactRepository 子集;
 - MissionFactory、MissionService.start/run/stop;
 - `script_planner`、Direction Worker、四个 Retrieval Worker;
 - Retrieval/Direction Validator;
 - Pattern、Decode、External、Knowledge、图片工具 Adapter;
-- 显式挂载 V2 Mission/Trace API;
-- 凭据轮换、读写账号分离、日志脱敏。
+- 显式挂载经 build→root 授权的 V2 Mission/Trace 只读观测 API;
+- 凭据环境注入、读写账号分离、日志脱敏;真实凭据轮换是上线前运维门禁。
+
+当前阶段一落地采用单进程 active-run registry:Direction publication 成功后更新 active direction 指针和旧 `script_direction`,随后 Root 只允许以 `PHASE_ONE_CAPABILITY_BOUNDARY` BLOCK,旧 build 投影为 `partial`。该路径不会创建 Paragraph/Element/Link、Round、Branch、PlanStep 或旧 external log,不会写 `branch_id=0`,也不会出现 `success`。
 
 暂不实现:Paragraph/Element 正式写入、正式发布、页面。
 
-验收:真实旧输入启动;输入 hash 稳定;Decode v1 fail→revise→v2 pass→ACCEPT;Direction Attempt 只消费固定 Decision;Root objective 可 revise;无 Round/multipath 固定计划;Worker 无法创建 Agent 或调用未授权写工具。
+验收:真实旧输入格式的脱敏 fixture 启动;输入 hash 稳定;Decode v1 fail→revise→v2 pass→ACCEPT;Direction Attempt 只消费固定 Decision;Root objective 可 revise;Direction ACCEPT 后 Root 以 `PHASE_ONE_CAPABILITY_BOUNDARY` 进入 BLOCKED、旧 build 为 `partial`;无 Round/multipath 固定计划;Worker 无法创建 Agent 或调用未授权写工具;阶段一不产生 `success` 或 `branch_id=0`
 
 ### 阶段二:候选结构化创作
 
@@ -1226,7 +1241,7 @@ Root Validator 通过后,Planner ACCEPT。Publisher 将同一 frozen Artifact
 - ScriptPublisher 与 publication 幂等状态;
 - `branch_id=0` 事务投影、旧详情读回和 digest 门禁;
 - success 状态投影;
-- stop/resume/recover;
+- resume/recover、跨进程 OwnerLease 和完整 stop/publication 竞态保护
 - 单机单活锁与启动自检;
 - 全链路 Event/Trace 关联;
 - 旧 API 黑盒兼容 E2E。