checkpoint: complete recoverable V2 pre-separation baseline

Complete the selective V2 checkpoint with its minimal AgentBus, object-storage, replay persistence, and validated-workbench shared dependency closure.
This commit is contained in:
鲨鱼辣椒 committed 2026-08-20 17:09:00 +08:00
1 parent 7330ac853b
commit 694c4317a3
627 files changed
+130467 -885

No files matched your search

@@ -145,6 +145,10 @@ POST /api/open/agent-sessions
`X-DeerFlow-Open-API-Key` 鉴权,并通过 `X-Request-ID`、`idempotency_key` 和 metadata 做调用关联。
当前 TH Hotel 后端 `SuperAgentOpenApiClientImpl` 已发送 CSRF double-submit。CSRF token 由后端每次请求临时生成,不走环境变量,不作为长期 Secret 保存。
2026-08-10 对 `https://superagent.nianxx.cn` 的真实合成 smoke 证明:用户提供的 Curl 示例未携带
CSRF 时当前服务端返回 403;添加同值 `X-CSRF-Token` 与 `csrf_token` Cookie 后 session 创建成功。
因此示例文档的鉴权片段不能单独作为当前运行契约,后端 client 的 double-submit 行为必须保留。
```text
Authorization: Bearer <DEERFLOW_OPEN_API_KEY>
X-Request-ID: <stable-request-id>
@@ -189,6 +193,7 @@ TH Hotel 当前观测并处理的事件类型:
| `metadata` | 读取 Run、Thread、Profile 等调用元数据 |
| `messages` | 流式消息增量或中间消息 |
| `values` | 阶段性或最终聚合状态 |
| `message.final` | 未开启公开 Trace 时的核心最终回答,data 包含 `run_id` 与 `text` |
| `end` | SSE 正常结束标志 |
解析最终答案时,不要简单拼接所有 `messages`。当前实现从后期 `values.messages[]` 中选择:
@@ -210,18 +215,23 @@ content 非空
- `usage_metadata.total_tokens`
- 已出现的 SSE event types
如果没有收到 `end`,或无法找到最终 AI 回答,应视为协议失败,不要伪造成成功结果。
Trace 开启时仍要求公开 `run.completed status=success`;Trace 关闭时,core `message.final` 负责提供最终
文本,收到 `end` 后必须再查询 `GET /runs/{run_id}`,只有权威状态为 `success` 才成功,并从其
`metadata.resolved_profile_id` / `metadata.resolved_profile_version_id` 补齐审计字段。如果没有收到
`end`、无法找到最终回答或无法确认 run 成功,应视为协议失败,不要伪造成成功结果。
### 4.5.1 2026-07-12 SSE 断流恢复要求
2026-07-12 导入的 `docs/import/20260712/OPEN_AGENT_API_JAVA_SSE_CLIENT.md` 已补充 Java 后端调用
SuperAgent Open API 的稳定性要求。后续 TH Hotel 的共享 SuperAgent Open API client 必须满足:
- 初始 `messages/stream?include_trace=true` 请求携带稳定 `X-Request-ID`。
- 初始 `messages/stream` 请求携带稳定 `X-Request-ID`。当前 Parsing Agent 与 Booking Business Agent 必须追加
`?include_trace=true`,显式 false 在调用前 fail closed;legacy Field Recovery 仍固定默认为 false。
- 同一业务 SourceMessage 的 `idempotency_key` 在所有尝试中保持不变。
- 初始 POST 成功后保存响应头 `Content-Location`,解析并保存 SuperAgent `run_id`。
- SSE 必须按帧解析 `event:`、`data:`、`id:` 和 heartbeat comment,并保存 `lastEventId`。
- 成功条件必须同时满足最终 AI 内容、`run.completed status=success`、顶层 `event: end`,且没有顶层 `error` 或 `run.failed`。
- 成功条件必须同时满足最终 AI 内容、顶层 `event: end`、权威 run success,且没有顶层 `error` 或
`run.failed`。权威 success 可来自公开 Trace 的 `run.completed`,无 Trace 时必须来自 run status 查询。
- EOF、Premature EOF、incomplete chunked response 不能当成功。
- 如果已有 `run_id`,断流后不得重新 POST 初始消息,应先查询 `GET /runs/{run_id}`,再通过 `GET /runs/{run_id}/events` 携带 `Last-Event-ID` 恢复。
- 恢复失败应记录为可诊断失败,不返回部分回答。
@@ -272,6 +282,130 @@ usageMetadata
- Provider 内部 Plan / Memory
- 未脱敏的个人信息
### 4.8 M012 Layer 3 字段 Recovery 同步等待
M012 新增一条与旧 V4 `task-results`、MCP submit、M007 AgentBus dispatch 均独立的后端出站链路:
```text
MANUAL_EML → QBD deterministic Parser
→ RecoveryRequestSet(仅 UNRESOLVED + RECOVERABLE 字段及最小锁定上下文)
→ SuperAgent 专用解析 Agent / installed fixed-channel-field-recovery Skill
→ 信息系统在 max-wait 内等待完整 SSE 成功结果
→ 严格 JSON-only RecoveryPatchSet
→ 本地 Validator / dependency resolver / projector
→ PostgreSQL invocation audit + atomic Assembly + EffectiveFactView artifact
```
运行配置使用 `booking.field-recovery.*`,默认关闭。启用时至少需要同时满足:
- `booking.postgres.enabled=true`;
- `booking.field-recovery.enabled=true`;
- `booking.field-recovery.open-api.base-url=https://superagent.nianxx.cn`(可按环境覆盖);
- `booking.field-recovery.open-api.api-key` 由解析 Agent 专属部署 Secret 注入;
- `booking.field-recovery.open-api.include-trace=false`;当前解析 Agent 外部应用策略禁用公开 Trace;
- 该 `df_open_...` token 对应的外部应用策略已绑定安装 Recovery Skill 的已发布 Profile,并开启 API exposure;
- `max-wait` 有界且不超过 10 分钟,请求和最终回答均受字符数上限保护。
公开 API 请求不传 `profile_id`。Profile 由 token 对应的外部应用策略选择;`external_subject_id` 只是
信息系统侧主体标识,Recovery 由 `source_message_id` 哈希稳定派生。通用 client factory 只复用
session/SSE transport;解析 Agent 与未来 Booking Business Agent 必须分别建立外部应用、Secret、
wrapper/config 和调用审计,不能共享 key。
真实合成 smoke 已确认该 token 可完成 session、无 Trace SSE、core `message.final`、`end` 与 run status
success,并解析到已发布 Profile/version;完整 `RecoveryRequestSet → RecoveryPatchSet` 业务输出和
PostgreSQL V3 事务链仍待测试/预生产联调,不能据此宣称字段 Recovery 已上线。
当前 checkpoint 只允许 `MANUAL_EML` 等待。`AGENTBUS` 仍在 WebSocket frame 线程同步进入 Booking
编排器,因此明确跳过该调用;只有先把 AgentBus 的 Booking 下游迁入受控 worker 后,才可在 worker
内等待解析 Agent。Provider 输出只是 patch 建议,不直接覆盖 Parser artifact、不进入 PMS/Opera,也不在本
checkpoint 提前喂给 Layer 4/5。
### 4.9 M012 Fixed-Channel Parsing Agent v1 durable 出站边界
新的QBD/LIANTAI共用Parsing Agent不复制4.8的`MANUAL_EML`同步例外。代码已完成专属
`booking.parsing-agent.*` properties、SuperAgent wrapper、adapter及CP4 pre-Context durable主链,但Port只
能由worker调用;AgentBus WebSocket callback、手工HTTP线程和前端请求线程都不得直接等待。
```text
SourceMessage + immutable public ParserResult
→ durable execution claim/lease/fence
→ complete Current/History + deterministic evidence registry
→ fixed-channel-parsing-agent-v1 AgentRequest
→ Parsing Agent专属external app/token + shared session/SSE transport
→ resolved Profile ID gate + published version audit
→ strict local decoder/semantic validator
→ deterministic local merger
→ normalized Agent result + authoritative Layer3 artifact
```
运行边界:
- Parsing Agent、Field Recovery和Booking Business三者只共享无身份transport factory;各自拥有key、wrapper、
config、hash subject与审计,禁止fallback。
- adapter要求`include-trace=true`并由配置校验防止关闭,限制UTF-8 request/message/response bytes与整体
deadline;History超限时 fail closed,绝不截断或摘要替代。
- Trace 模式必须收到公开`run.completed(status=success)`和顶层`end`。既有execution audit仍保留安全聚合;
PostgreSQL V13共用journal另在语义解析/去重前按实际接收顺序保存每条公开事件,并保存transport最终交给decoder
的完整答案。重复投递照录,失败/超时/断流时保留已收到部分。
- journal只记录Provider返回,不记录API Key、Authorization、Cookie、CSRF、数据库密码、请求头或出站完整请求;
不推导平台未返回的隐藏思考。
- expected Profile ID必须由部署配置提供并与run metadata精确一致;实际published version只记录,不参与任务放行。
Main Prompt和Skill不由API request绑定;其平台安装/发布证据仍是单独release gate。
- adapter仍只把raw JSON作为业务候选送到进程内validator;完整返回原文由共用journal作为运行证据保存,不写入
Parser artifact,也不改变Parser-only review或Layer 3业务边界。
- 当前`booking.parsing-agent.enabled/provider-enabled/worker-enabled=false`且production强制false;CP4 fake链
完成不代表真实Provider、scheduler或生产执行已经启用。
### 4.10 M012 Booking Business Agent V2 durable 出站边界
Layer 3/4 到 Layer 5 的正式运行路径复用既有 `booking.agent.open-api.*`、
`SuperAgentBookingBusinessOpenApiClient` 和共享 SSE transport,不创建第二套 Booking client、凭据或状态机。
Booking、Parsing、Field Recovery、AgentBus 与 Debug EML 只共享无身份 transport;Booking Agent 必须使用自己的
外部应用 Secret,禁止 key fallback。
```text
final Layer3ResultV2
→ Layer 4 + canonical BookingDecisionInputV2
→ 短事务保存 Layer 3/4/input、enqueue execution、标记 AWAITING_BOOKING_AGENT
→ commit
→ V11 worker claim(SKIP LOCKED + lease + fencing)
→ 无数据库事务:专用 Booking port 调用 SuperAgent
→ Profile/版本/大小/deadline + JSON-only CandidateDecision 严格校验
→ 短事务提交 Candidate 与成功 attempt audit
→ 后续 claim 从持久 Candidate 恢复 Layer 6
```
运行边界:
- 只有 `booking.postgres.enabled`、`booking.agent.enabled`、`booking.agent.provider-enabled` 和
`booking.agent.worker-enabled` 同时为 true,durable worker 才注册;默认值与 production profile 均保持关闭。
- Provider 调用前有“当前线程无 Spring transaction”的可执行保护。Provider 超时、断流、临时网络错误或非法
Candidate 不得回滚已经提交的 Parsing、Layer 3/4 和 input。
- 同一 processing run 只有一个 execution,幂等键为 `booking-v2:<canonical input sha256>`。到期 lease 可由
重启后的 worker 接管;已保存 Candidate 只恢复 Layer 6,不再调用 Provider。
- 超时、断流、HTTP 408/425/429/5xx 和临时 transport 错误按有限次数、上限退避重试;JSON、契约、逻辑或平台
Profile 版本、input hash、evidence/reference 和大小错误不可重试,直接形成安全 `FAIL_CLOSED` Risk 后进入 Layer 6。
- 每个真正发出的 Provider attempt 必须先有受控 invocation audit;记录 input/response hash、execution/attempt、
Provider session/run/profile/version、duration、event types 与 failure class。V13 journal再以该invocation/attempt为
关联保存Provider实际返回的公开事件与最终答案原文;出站完整request、Secret、Authorization、Cookie、CSRF和
数据库密码不进入journal。
- Booking 调用必须携带`include_trace=true`,显式 false 在调用前拒绝;成功必须同时具备公开
`run.completed(status=success)`和顶层`end`。既有`public_trace_events`继续作安全聚合,完整公开返回以journal
为权威;Provider返回不做摘要、截断、脱敏或去重。
- Candidate 只是 Layer 5 候选,必须由本地 decoder 与 Layer 6 Validator 校验;Agent 不得直接创建 TaskCard、调用
PMS/Opera 或改变 Layer 6 的业务职责。
历史 CP5 证据记录测试 Profile ID `85ab8334-4e1c-4716-8ec0-9c3c099cec9b`、发布版本 ID
`9fed48c0-1f53-4d5a-8ba0-52865c738d83`(v7)及一次真实 Candidate 调用。该证据不能替代目标部署环境的当前
发布核验;本次实现环境没有专用 key、PostgreSQL 连接和 live flags,未重新查询或修改平台。放行前必须用最小
合成数据重新验证 resolved Profile ID/version,并完成 QBD、普通 LianTai 各 New/Update/Cancel/Allotment 的八场景
真实联调。该矩阵只证明核心接线,不代表 Rooming List 全业务完成。
2026-08-14 RC6 后续已用单项合成 Trace/Extra Bed 关闭“当前 resolved 身份+RC6 严格 payload”薄门禁:Profile
仍为 `85ab8334-4e1c-4716-8ec0-9c3c099cec9b`,发布 version ID 为
`b91686f4-b8b8-4ac0-aeb4-b7a2f54a0a41`,严格 Candidate/Layer 6 验证 1/1 通过。八场景、PostgreSQL 和
AgentBus 双 Agent 全链仍是独立部署门禁。
## 5. AgentBus 对接
### 5.1 运行时配置
@@ -455,6 +589,10 @@ Replay 负责:
Replay 接口默认关闭,仅在本地、UAT 或受控生产运维场景开启。
开发测试 AgentBus EML replay 的身份策略另有一项隔离规则:`PRESERVE_IDENTITY` 保留 EML 的 message/conversation
身份用于幂等验证;`FRESH_DELIVERY` 每次同时生成独立 message 与 conversation 身份。后者用于真实双 Agent 回放,
避免同一 EML 的早期调试副本被后续运行误当作真实 History;该规则不改变真实 AgentBus 入站邮件的 conversation 身份。
### 5.7 AgentBus 入库后自动分发 SuperAgent
M007 已实现的自动分发链路不是 Debug EML,也不是 SourceMessage Replay。它只负责把 AgentBus 新入库邮件异步交给 SuperAgent Open API:
@@ -649,7 +787,12 @@ SuperAgent 建议覆盖:
- SSE 正常结束并解析最终回答。
- SSE 缺少 `end` 时失败。
- SSE 缺少最终回答时失败。
- SSE 缺少 `run.completed status=success` 时失败。
- Trace 模式缺少 `run.completed status=success`,或无 Trace 模式无法通过 run status 确认 success 时失败。
- Parsing/Booking 专用客户端的初始消息 URL 精确包含 `include_trace=true`,并拒绝显式 false 配置。
- 所有公开事件在业务解析前按原 `data` 内容与交付顺序进入journal;多行/空白不改写,重连重复投递照录;最终
交给decoder的答案另有`FINAL_ANSWER`记录。
- 出站API Key、Authorization、Cookie、CSRF、数据库密码和请求头不得进入journal;平台未返回的隐藏思考不补写。
- 无 Trace core `message.final` 能提取最终回答,并由 run metadata 补齐 Profile/version。
- SSE 断流后携带 `Last-Event-ID` 通过 `/runs/{run_id}/events` 恢复,且不重发初始 POST。
- HTTP 401 / 403 / 404 / 409 / 5xx 错误转换。
- 连接超时,以及 SSE 断流后的 run/events 恢复。
@@ -691,6 +834,17 @@ SuperAgent 返回的是 Provider 输出。即使未来返回结构化 JSON,也
真实邮件、附件 URL、客户姓名和联系方式都可能是敏感数据。测试夹具应使用合成数据。
## 9.1 2026-08-17 完整公开返回与生命周期日志(ADR-017)
- fixed-channel Parsing Agent 与 Booking Business Agent 的初始 message 请求必须带 `include_trace=true`;显式
false 在调用前拒绝。legacy Field Recovery 继续 no-Trace。
- 信息系统在测试与生产使用同一V13追加式journal:SuperAgent实际返回的session响应、每条公开事件、恢复run响应、
HTTP错误正文和最终答案,按原顺序、原内容保存,并记录双时间、event/session/run/execution/invocation/attempt。
- 既有安全Provider audit继续用于聚合诊断;完整返回以journal为权威。journal不参与Parser、Layer5、Layer6或任务卡。
- 开发回放的lifecycle V2按同一replay/processing run读取journal,复制与导出复用同一JSON。读取失败返回503,不
降级为残缺日志。
- 出站凭据/请求与未返回的隐藏思考排除。旧调用保持空journal;不得重发同一消息来“补日志”,否则会启动新run。
## 10. 接入前检查清单
接入 SuperAgent 前确认: