# 把回放当策略测试

`evaluate(event, state)` 是纯函数，`state` 是 `events.jsonl` 的折叠（[事件与状态](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/events-and-state.zh.html) §4），所以回放历史就能在真实负载上测试规则，不需要 mock 和运行中的 agent。这是研究设计，下面的命令尚未实现。

```
openprogram proactive replay --policy TestGapWatcher --sessions <ids|all>
```

- **工程**: 新规则上线前都要回放，离线暴露精确率问题（Clippy 式的失败）。工具要先于决策引擎。
- **论文**: would-have-fired 报告提供[精确率标注](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/_research_archive/evaluation.zh.html)样本。

## 模式

新规则的 L2 推断没在历史上运行过，所以没有它的 `state.inferred` 事件。

| 模式 | 允许的状态 | 确定性 | 用途 |
| --- | --- | --- | --- |
| strict | L0、L1、已持久化的 `state.inferred` | 逐位一致 | L0/L1 回归、论文数字。DangerousCommandGuard；TestGapWatcher 的 L1 部分 |
| augmented | strict 加新计算的 L2 | 靠缓存复现 | L2 规则首次运行。UnvalidatedCompletionNudge；TestGapWatcher 的完成信号 |

## augmented 的可复现性

- 固定 `model`、版本和 `temperature=0`。
- 把新 L2 结果持久化为缓存，随报告发布 `model fingerprint`。复现指复现标注集，不调用可能已变化的模型。
- 同一规则同一会话第二次回放读缓存，是确定的。
- Prepare 规则止于 would-have-prepared：reviewer 子 agent 无法确定性重跑。TestGapWatcher 的报告标注“Notify precision: online-only”，用 A/B 测量。

## 回放必须做对的三件事

| 细节 | 不做的后果 | 规则 |
| --- | --- | --- |
| 模拟冷却 | 新规则没有动作历史，每次匹配都上报 | 把 would-fire 决策作为虚拟冷却事件反馈 |
| 时钟注入 | 用今天计算旧会话的冷却是错的 | “现在”是事件的 `ts`。规则不能调用 `time.time()`，框架把时钟注入 `evaluate` |
| 按分支折叠 | 被回退的分支被当成连续历史 | 用 `node_id` 重建当前节点到根的 DAG 路径再折叠（[事件与状态](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/events-and-state.zh.html) §5）。打断预算跨分支全局 |

## 召回

would-have-fired 报告只列触发点，所以回放能得出精确率，得不出召回。召回需要单独标注的 should-have-fired 集。报告不声称召回。

## 报告

```
replay-report {
  policy: "TestGapWatcher"
  mode: "augmented"                      # strict | augmented
  model_fingerprint: "claude-…"          # 仅 augmented
  sessions_scanned: 214
  events_scanned: 51_320
  fired: 38
  per_session: [
    { session_id, node_path: [...],      # 折叠用的 DAG 路径
      fires: [
        { event_ref, state_snapshot_ref, # 脱敏后的触发上下文
          action: "Prepare→Notify",
          cooldown_suppressed: false,
          notes: "Notify precision: online-only" }
      ] }
  ]
  invariant_checks: { loop_free: pass, breaker_exempt: pass, ... }
}
```

`event_ref`、`state_snapshot_ref` 让标注者判断每次触发；脱敏见[威胁模型](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/_research_archive/threat-model.zh.html)。报告还断言四条[不变式](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/invariants.zh.html)（§5）。

## 实现状态

`openprogram proactive replay` 只是提案，尚未实现；CLI 没有 `proactive` 子命令。
