- CRITICAL #1:链 write/review 节点经 gateway_builder 按节点自建 session 现建网关,
usage_ledger sink 绑活 session,随节点 commit 持久化;run_chain_job 不再转发请求网关
(其 session 在 BackgroundTask 跑时已关闭,记账行被静默丢弃)。新增 get_chain_gateway_builder
缝(仿 digest builder),get_chain_gateway 退化为纯 503 凭据预检。守不变量 #1。
- HIGH #2:chain_runner 失败日志不再记 str(exc)(可能含 key/连接串/LLM 输出),改记
_classify_job_error 脱敏文案 + exc_type(设计 §5)。
- HIGH #3:resume 端点原子抢占 awaiting→running(JobRepo.claim_awaiting_to_running 条件
UPDATE),抢不到 → 409,防并发 resume 双 Command(resume) 损坏图。
- HIGH #4:resume 校验 job.project_id == project_id(JobView 新增 project_id),不匹配 → 404。
- HIGH #5:resume 返回新 ChainResumeAccepted{job_id,chain_key},去掉无意义哨兵 start/count=0。
- HIGH #6:删 nodes.py 死导入 extract_conflicts(import + __all__)。
- 测试 #7:e2e 断言链跑后 usage_ledger 有行(#1 回归守卫)+ chapter_reviews 每章一行;
新增 claim 原子抢占单测 + resume 跨项目 404 / 并发 409 端点测。
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""多章工作流链端点的请求/响应 schema(chain-workflow 设计 §6)。
|
||
|
||
snake_case(命名契约,见 memory/gotchas)。前端经 OpenAPI→TS 客户端消费——改字段
|
||
须 `pnpm gen:api` 重生成。
|
||
|
||
- `ChainRunRequest`:发起一条链(起始章 + 章数)。`count` 1..50(系统边界校验,fail fast)。
|
||
- `ChainRunAccepted`:202 受理回执(job_id + 回显请求参数,供前端轮询 `GET /jobs/{id}`)。
|
||
- `ChainResumeRequest`:裁决续跑(复用 `ConflictDecision`,对 awaiting 章的冲突逐条裁决)。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import uuid
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
from ww_api.schemas.projects import ConflictDecision
|
||
|
||
# 链一次最多写 K 章(系统边界,避免一条 run 无界占用;§6 校验)。
|
||
MAX_CHAIN_COUNT = 50
|
||
MIN_CHAIN_COUNT = 1
|
||
|
||
|
||
class ChainRunRequest(BaseModel):
|
||
"""发起多章链:从 `start_chapter_no` 起循环写 `count` 章(区间含两端)。
|
||
|
||
`count` 1..50(>50 → 422 VALIDATION,由 Field 约束在边界拦下,不进 BackgroundTask);
|
||
`start_chapter_no >= 1`。
|
||
"""
|
||
|
||
start_chapter_no: int = Field(ge=1, description="起始章号(含),>=1")
|
||
count: int = Field(
|
||
ge=MIN_CHAIN_COUNT,
|
||
le=MAX_CHAIN_COUNT,
|
||
description="本 run 连续写的章数(1..50,含起始章)",
|
||
)
|
||
|
||
|
||
class ChainRunAccepted(BaseModel):
|
||
"""链受理回执(202):job_id + 回显请求参数(前端走 `GET /jobs/{id}` 轮询进度/awaiting)。"""
|
||
|
||
job_id: uuid.UUID
|
||
chain_key: str
|
||
start_chapter_no: int
|
||
count: int
|
||
|
||
|
||
class ChainResumeRequest(BaseModel):
|
||
"""裁决续跑:对 awaiting 章最近审稿的每个冲突逐条裁决(复用 `ConflictDecision`)。"""
|
||
|
||
decisions: list[ConflictDecision] = Field(
|
||
default_factory=list,
|
||
description="对 awaiting 章冲突的裁决清单(采纳/忽略/手改)",
|
||
)
|
||
|
||
|
||
class ChainResumeAccepted(BaseModel):
|
||
"""resume 受理回执(202):job_id + chain_key(前端走 `GET /jobs/{id}` 轮询续跑进度)。
|
||
|
||
续跑无独立区间(图从检查点续),故不回显 start/count(会是无意义哨兵值)——只回 job 标识。
|
||
"""
|
||
|
||
job_id: uuid.UUID
|
||
chain_key: str
|