STEP 1534 — PlanRunner v0.2 (arc 3/3 完)
Counter drift note: STEP 番号 1534 だが narrative 上は STEP 1533 (MCP tool wrapping) の続き。 rebase の副作用で counter reset された状態、 別 STEP で修復候補。
目的
藤本さん directive「Bluesky の残 10 Msg type (open_run/close_run/subscribe/monitor 等) を semantics 明確化しつつ追加」 応答。
STEP 1579 (b) の v0.1 は 5 Msg type (call/check/dry_run_hint/wait/checkpoint)。 Bluesky RunEngine の 15+ Msg type のうち Rei stack に持ち帰れる意味のあるもの 6 種を追加 して v0.2 完成。
追加 6 Msg type
| Bluesky | Rei v0.2 | 意味 |
|---|---|---|
open_run | open_run | plan 実行 session の開始、 runId 生成 + __run__.opened event 自動 emit |
close_run | close_run | session 終了、 exitCode 記録 + __run__.closed event 自動 emit |
subscribe | subscribe | event bus 購読 (topic + handler + optional filter) |
monitor | monitor | subscribe + 即時 N tick emit (ticksToEmit) |
stage | stage | resource setup lifecycle (setup callback + stagedResources 追加) |
unstage | unstage | resource teardown lifecycle (teardown callback + stagedResources 削除) |
意図的に追加しない Bluesky Msg
| Bluesky | 理由 |
|---|---|
set / read / trigger | Rei では call で十分 (verdict 出力が primary) |
kickoff / complete | 長時間 background task の async 高度化は別 STEP |
pause / resume | interactive control は separate agent 統合が必要 |
null | no-op、 checkpoint で代替可 |
create / save / drop | document store 相当、 Rei には data 層が不在 (別 STEP で benchtop-mcp ledger と統合検討) |
PlanRunnerV02 class
const runner = new PlanRunnerV02({
toolHandler, safetyGate, waitFn, // v0.1 と同じ
runIdGen: () => 'my-run-id', // v0.2 新規 (auto generation)
dryRun: false,
});
// event bus emit (外部から)
runner.emit('sensor.reading', { value: 42 });
// introspection
runner.staged(); // ['probe_a', 'probe_b']
runner.subscribedTopics(); // ['sensor.reading', '__run__.opened']
Example: full lifecycle plan
function* fullPlan(): PlanV02 {
yield openRunMsg(); // → runId 生成 + __run__.opened emit
yield stageMsg('disk_probe', async () => connect()); // → setup callback + stagedResources 追加
yield subscribeMsg('__run__.closed', (e) => log(e)); // → close 時に自動通知
yield callMsg('disk_health_verdict', {...}); // 通常の tool call
yield unstageMsg('disk_probe', async () => close()); // → teardown callback + 削除
yield closeRunMsg(undefined, 'success', { calls: 1 }); // → __run__.closed emit
}
const trace = await runner.run(fullPlan());
// trace 6 entry + __run__.closed subscriber が exitCode='success' を受信
Backward compat
- v0.1 の 5 Msg type + PlanRunner は不変 — STEP 1579 test 48/48 継続 PASS
- v0.2 は新 Msg type union + PlanRunnerV02 として提供、 opt-in
- STEP 1584 SafetyGate + STEP 1533 wrapper registry 両方 v0.2 と互換 (safetyGate handler + toolHandler 共通)
Test — 47/47 PASS + regression 130/130 clean
- Msg constructors (6 新 v0.2 type)
- PlanRunnerV02 basic run (v0.1 Msg backward compat)
- open_run / close_run lifecycle
- open_run generates runId when omitted
- subscribe + emit delivery
- subscribe with filter
- monitor with ticksToEmit
- stage / unstage lifecycle (setup + teardown 呼出)
- staged() introspection
- __run__ lifecycle events auto-emitted
- summarizeTraceV02
- dryRun skips setup/teardown, still traces
- Full sequence (open → stage → subscribe → call → close)
Regression: STEP 1579 v0.1 (48/48) + STEP 1584 SafetyGate (44/44) + STEP 1533 wrapper (38/38) 全通過。
STEP 1569 arc 完結
| STEP | Layer | Commit |
|---|---|---|
| 1569 | arc 起点 (Ophyd 読解 + top 3 宣言) | 082609899 |
| 1571 (a) | No-Data Primitives | 700c4c98c |
| 1576 (c) | Connector Protocols | 5e4b2ec4c |
| 1579 (b) | Plan Runner Msg v0.1 | 5beed1c41 |
| 1584 | SafetyGate (実 hardware 統合 1/3) | e89dd95ab |
| 1533 | MCP tool wrapping (実 hardware 統合 2/3) | 1328ee77e |
| 1534 | PlanRunner v0.2 (実 hardware 統合 3/3) | (this) |
Ophyd 10 年設計 + Bluesky RunEngine の系統的輸入完了:
- NotConnectedError = NEITHER 型化 (Layer 1/2 primitives)
- Protocol type + compile-time drift 検知
- Plan generator + Msg dispatch (5 + 6 = 11 Msg type)
- SafetyGate rule catalog
- Wrapper factory + registry (opt-in migration)
- Event bus + lifecycle (open/close/subscribe/monitor/stage/unstage)
Honest scope
- v0.2 = 11 Msg type total、 全 Bluesky Msg (15+) の subset。 pause/resume/kickoff/complete は Rei semantics 明確化次第 v0.3+
- Event bus は in-memory (single-process)。 分散 event bus (Redis / NATS 等) は別 STEP
- Stage/unstage は setup/teardown callback を実行するだけの minimum wire。 stateful tool の resource pool 管理は別 STEP
- Counter drift = STEP 番号 1534 が narrative 上の 1587 に相当、 別 STEP で counter 修復候補