mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 16:37:46 +08:00
评审第 4 条:responses/turn.rs 实际复制了一整套 HTTP execution lifecycle——
usage 写入、candidate 状态流转、health/adaptive 效果投射、pool key lease 释放、
body capture、账单失败判定,与 HTTP 的顺序和超时语义只能靠人工对齐。
新增 execution_runtime/attempt_lifecycle.rs,把一次 provider attempt 的记账收成
transport 中立的三段:
ExecutionAttemptLifecycle::begin pending usage 行 + Pending candidate
ExecutionAttemptLifecycle::mark_started usage stream_started + Streaming candidate(幂等)
ExecutionAttemptLifecycle::settle 终态四段,顺序不可重排:
1 usage terminal(detachable,不可丢)
2 candidate terminal
3 provider 效果 + 超时兜底释放 lease
4 execution report(作废账单不提交)
顺序、5s 分段超时常量、detachable 语义、「每个效果分支都释放 lease」「作废账单
一律不提交 report」这些不变量全部保持原样。
一并上移的辅助设施:
- AttemptStageGuard 取代 await_websocket_lifecycle_stage /
await_detachable_lifecycle_stage,把「等多久」参数化:WS 用 Bounded(5s),
HTTP 接线时用 Unbounded 即保持它现在的语义。
- AttemptBodyCapture 取代 append_capture / encode_stream_capture,把
「缓冲 + 截断标志」两个字段收成一个类型(WS 侧四个字段变两个)。捕获内容
仍然是 SSE 形状:usage runtime 按 data: 行解析被捕获的 body 来判定
StreamCapturedTerminalState,换成结构化 JSON 会让终态判定恒为 Missing。
- C2/C3 的结算表本来就不含任何 WS 类型,随之上移。效果表分支与注释逐字未改,
仅按新位置改名为 AttemptProviderEffect / classify_attempt_provider_effect。
responses/settlement.rs 只保留 WS 专属的一件事:把 relay loop 的结算信号
ResponsesWebSocketTurnOutcome 翻译成两个正交事实。
ResponsesProviderAttempt 现在只持有 WS 专有状态:lifecycle 句柄、deadline、
终态观测器、两侧 capture、准入、provider/delivery 事实。plan / trace_id /
report_kind / report_context / candidate 起始时间戳都归 lifecycle。
HTTP 侧不接线:execution_runtime/stream/execution.rs 的
DirectPassthroughFinalizerCore(38 字段)与 failover / oauth 重试 / prefetch 深度
纠缠,无法在「行为等价 + 单 commit 可验证」的前提下改动。逐调用点映射表写在
模块文档注释里作为后续 PR 的接线依据。验收:git diff 对
execution_runtime/stream/ 与 crates/aether-usage 均为零 diff。
新增 6 个测试:效果段超时后仍走兜底 lease 释放、Unbounded 会一直等、detachable
写入在调用方停止等待后仍跑完、settle 四段顺序(计数器替身)、body capture 的
SSE 形状与编码状态(并显式记录默认上限是 usize::MAX,截断分支不可达)、
candidate error_type 映射。