Shared helper: PASSTHROUGH_OPERATIONS for the daemon socket's one-call request arms

オープン 初心者向け
#1,441 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
api, backend

調査の方向性

src/daemon/server.tsのDaemonServer.#handleRequest周辺と、引用されているsrc/daemon/dispatch.tsのdispatch動作を読みます。一度だけ呼び出す37個の列挙されたcaseをPASSTHROUGH_OPERATIONSに移し、defaultの前にガード付きdispatchを追加します。追加の処理を行う8個のcaseと、それらに記載された例外は残します。socketテストを実行し、続いてpnpm checkを実行して、switchのcaseが11個であることを確認します。

索引モデルが issue の本文から書いたものです。

説明

task:draft

Scope

One shared list for the daemon socket server's pass-through request names.
Every identical one-call case arm of DaemonServer.#handleRequest moves to
it. No behaviour change.

In short

DaemonServer.#handleRequest (src/daemon/server.ts) has 45 case arms; 37
of them do exactly one thing: return this.#dispatcher.dispatch("<the case's own name>", frame.payload <maybe> ?? {}, this.#session(connection));. They are
37 hand-written copies of "this socket request is a thin client of exactly one
contract operation, with no per-connection bookkeeping". The shared shape is a
module-level PASSTHROUGH_OPERATIONS: ReadonlySet<OperationName> in
server.ts plus one guarded line before the default throw. The 37 arms
occupy 185 lines today; the set and guard are about 45, so about 140 lines go.

Technical spec

Facts
# Fact Source
F1 37 arms are that one call and nothing else (case label and call name equal in all 37; a script over the switch reported 0 name mismatches): lease.renew, lease.cancel, lease.get, lease.list, status.get, list.get, catalog.get, cleanup.run, doctor.run, nuke.run, warm.forget, baseline.list, baseline.remove, baseline.save, events.replay, usage.get, inbox.get, events.subscribe, events.unsubscribe, driver.passthrough, device.rotate, relay.cancel, config.get, identity.get, token.create, token.list, token.revoke, worker.list, worker.drain, worker.undrain, worker.remove, worker.update, alerts.test, component.list, component.remove, device.add, device.remove. They occupy 185 lines. 23 span 6 lines with frame.payload ?? {}, 14 are one-line or 2-line with a bare frame.payload. src/daemon/server.ts:956-1160, every arm read at e4599cf2; the script over the switch printed the 37 names, their line spans and the totals
F2 The ?? {} adds nothing over a bare payload: runDispatch coalesces itself — const input = parseDispatchInput(definition.input, rawInput ?? {}); — which is how the 14 bare arms already call it. src/daemon/dispatch.ts:331 at e4599cf2
F3 All 37 names are registered operations in both dispatchers (src/daemon/dispatcher.ts, src/gateway/dispatcher.ts) and in OPERATIONS; runDispatch answers DispatchError("UNKNOWN_REQUEST", ...) for a name with no handler, and the switch's own default answers ProtocolError("UNKNOWN_REQUEST", ...) for any name the set does not hold. grep of the 37 names in the three files (e4599cf2); src/daemon/dispatch.ts:325-328; src/daemon/server.ts:1162-1163
F4 The arms that stay each do real work before or around the dispatch: lease.request, lease.release and lease.release-all (per-connection release bookkeeping), device.exec and component.install and worker.install-component (per-call push wiring), relay.request (link channel), daemon.update (the second frozen call: skips the version gate, and query skips readiness — kept explicit). src/daemon/server.ts:910-1160, 829-830; daemon/AGENTS.md Rules → Start and stop (e4599cf2)
F5 Two arms carry a why: comment inside the arm (driver.passthrough, and the worker.* group's ADR 0005 §23 note above worker.list); moving an arm to the set moves its comment onto the set. src/daemon/server.ts:1066-1068,1109-1111 at e4599cf2
F6 Socket tests already drive named set members end to end through createClient(...).request(...) (status.get, lease.renew, events.subscribe, role matrices), so the refactor runs under existing coverage. src/daemon/server.test.ts, server-roles.test.ts, dispatcher-status.test.ts (grep of the names, e4599cf2)
F7 #session(connection) and #dispatcher are already the same receiver in every one of the 37 arms; nothing varies except the name. F1 spans, read at e4599cf2
Modules touched

Only src/daemon, one file: a module-private constant and one guard. No other
module imports server.ts past the daemon index, and the index does not
change. Found by grep -n 'this.#dispatcher.dispatch(' (45 hits in
server.ts; the 37 of F1 are inside #handleRequest).

flowchart LR
  socket[socket frame] --> host[#handleRequest switch]
  host -->|name in PASSTHROUGH_OPERATIONS| run[dispatch.ts runDispatch]
  host -->|8 arms with real work| run
  host -->|name in neither| unk[ProtocolError UNKNOWN_REQUEST]
Contract and event changes

None. OperationName already exists in the contract and the set only reads it;
no wire shape moves, so no protocol bump.

Rules in play
  • architecture rule 10 — "A rule is enforced in exactly one place": today a
    new pass-through operation is written twice (case label plus a duplicated
    call), and the 14 bare-payload arms have already drifted from the 23
    ?? {} ones over a difference F2 shows is empty.
  • architecture rule 1 — no platform knowledge enters the switch.
  • daemon/AGENTS.md Dispatch — every frame still goes through the same
    dispatch pipeline; parse, role check and the converge park are untouched,
    and the frozen-call exceptions stay explicit (F4).

Done when

  • PASSTHROUGH_OPERATIONS holds the 37 names of F1 in src/daemon/server.ts,
    with the comments of F5 moved onto the set, and one guard before the
    default throws none: a member dispatches
    this.#dispatcher.dispatch(frame.type as OperationName, frame.payload, this.#session(connection)).
  • The 37 arms are gone; the 8 arms of F4 and the default stay.
  • grep -cE 'case "' src/daemon/server.ts prints 11 (48 today, minus 37).
  • A socket test sends one set member (say status.get) and one unknown name,
    pinning the dispatch and the UNKNOWN_REQUEST answer at the transport.
  • pnpm check passes.

Out of scope

The worker and gateway Dispatcher handler tables (same operation names,
different handlers by mode — they are meant to diverge). The HTTP frontend's
routes.

Depends on

Written by an agent.

主要言語
TypeScript
スター
705
フォーク
40
平均マージ
12時間 9分
マージ済み PR(30日)
376

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

callstackincubator/simlock のほかの issue

callstackincubator/simlock の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。