From 6aba7dbbe01363992c4c1bf3dc5e4942e17da789 Mon Sep 17 00:00:00 2001 From: Hare Date: Fri, 26 Jun 2026 13:56:13 +0900 Subject: [PATCH] ticket: record websocket observation implementation --- .yoi/tickets/00001KVZKSTJT/item.md | 2 +- .yoi/tickets/00001KVZKSTJT/thread.md | 104 +++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/.yoi/tickets/00001KVZKSTJT/item.md b/.yoi/tickets/00001KVZKSTJT/item.md index 76bce3e7..1cdec3f9 100644 --- a/.yoi/tickets/00001KVZKSTJT/item.md +++ b/.yoi/tickets/00001KVZKSTJT/item.md @@ -2,7 +2,7 @@ title: 'Runtime/Backend WebSocket observation proxyを実装する' state: 'inprogress' created_at: '2026-06-25T14:44:02Z' -updated_at: '2026-06-26T04:23:22Z' +updated_at: '2026-06-26T04:56:04Z' assignee: null queued_by: 'workspace-panel' queued_at: '2026-06-25T20:34:20Z' diff --git a/.yoi/tickets/00001KVZKSTJT/thread.md b/.yoi/tickets/00001KVZKSTJT/thread.md index f6bebc2c..5a3bba6d 100644 --- a/.yoi/tickets/00001KVZKSTJT/thread.md +++ b/.yoi/tickets/00001KVZKSTJT/thread.md @@ -274,3 +274,107 @@ Next action: - Wait for Coder implementation report, then route to reviewer. --- + + + +## Implementation report + +Implementation report: + +実装完了。Ticket ファイル / project records は変更していない。merge / close / cleanup 前で停止。 + +Commit: +- `9807accaf08f4322763dd7cd3536baf3dab8d10e feat: add worker observation websocket proxy` + +変更概要: + +### worker-runtime + +変更ファイル: +- `crates/worker-runtime/Cargo.toml` +- `crates/worker-runtime/src/observation.rs` +- `crates/worker-runtime/src/runtime.rs` +- `crates/worker-runtime/src/http_server.rs` + +実装内容: +- optional feature `ws-server` を追加。 + - `http-server` に加えて `axum/ws`, `protocol`, `futures`, `tokio/sync` を使用。 + - feature 無効時の core compile も確認済み。 +- Runtime 側に Worker-scoped observation backlog / bus を追加。 + - Runtime-local opaque cursor: `wo_` + - bounded in-memory backlog v0 + - `observe_worker_event(worker_ref, protocol::Event)` で `protocol::Event` payload をそのまま observation bus に投入。 +- Runtime HTTP server に worker-scoped WS endpoint を追加。 + - `GET /v1/workers/{worker_id}/events/ws?cursor=...` +- Runtime WS frame: + - `RuntimeWorkerEventWsFrame::Event { envelope }` + - `RuntimeWorkerEventWsFrame::Diagnostic { diagnostic }` +- Runtime WS envelope: + - `cursor` + - `event_id` + - `worker_id` + - `payload: protocol::Event` +- 接続時に `protocol::Event::Snapshot` を初期 projection として送信。 +- live update は observation bus の `protocol::Event` payload を転送。 +- client からの text/binary 等の入力は `runtime.observation_only` diagnostic で終了。 +- malformed cursor / unknown-or-expired cursor / worker not found / bus closed / lagged backlog などを typed diagnostic/error 化。 + +### workspace-server + +変更ファイル: +- `crates/workspace-server/Cargo.toml` +- `crates/workspace-server/src/lib.rs` +- `crates/workspace-server/src/observation.rs` +- `crates/workspace-server/src/server.rs` + +実装内容: +- Backend-owned observation proxy module を追加。 +- Runtime WS client を追加。 + - Runtime WS envelope を decode。 + - 内部表現として `runtime_id + worker_id + runtime_cursor + protocol::Event` を保持。 +- Backend client-facing WS endpoint を追加。 + - `GET /api/runtimes/{runtime_id}/workers/{worker_id}/events/ws?cursor=...` +- Backend-local cursor/envelope を追加。 + - Backend cursor: `bo_` + - Runtime endpoint / credential / socket / session path は client-facing payload に出さない。 +- Backend client-facing frame: + - `ClientWorkerEventWsFrame::Event { envelope }` + - `ClientWorkerEventWsFrame::Diagnostic { diagnostic }` +- Backend client-facing envelope: + - `cursor` + - `event_id` + - `runtime_id` + - `worker_id` + - `payload: protocol::Event` +- Backend source config は server 内部設定 `runtime_event_sources` として保持。 +- unknown worker/runtime source, malformed/unknown cursor, upstream disconnect, malformed upstream frame, observation-only client input を typed diagnostic/error 化。 + +### workspace/root/package + +変更ファイル: +- `Cargo.toml` +- `Cargo.lock` +- `package.nix` + +内容: +- `tokio-tungstenite = "0.29"` を workspace dependency に追加。 +- `package.nix` の `cargoHash` を更新。 + +Validation: +- `cargo fmt --all`: success +- `cargo check -p worker-runtime`: success +- `cargo test -p worker-runtime --features ws-server`: success(14 lib tests + 3 bin tests + doctests) +- `cargo test -p yoi-workspace-server`: success(22 lib tests + bin/doctests) +- `cargo check -p yoi`: success +- `git diff --check`: success +- `git diff --check --cached`: success +- `nix build .#yoi --no-link`: success + +Review focus / residual risks: +- v0 backlog は in-memory bounded。process restart / memory eviction 後の cursor は unknown/expired 扱い。 +- Runtime Snapshot projection は minimal projection。`protocol::Event::Snapshot` を使うが、entries / in-flight は現 Runtime adapter の範囲で空 projection。 +- Backend source discovery は `runtime_event_sources` 内部 config seam。remote lifecycle/discovery や full registry redesign は Non-goals として未実装。 +- Auth/redaction/policy は full 実装せず、後続拡張しやすい typed source/diagnostic/proxy boundary に留めた。 +- Browser / future TUI には Backend endpoint のみを公開し、Runtime endpoint / credential / socket / session path は envelope に含めていない。 + +---