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

未关闭 适合新手
#1,441 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
api, backend

调研方向

阅读src/daemon/server.ts中DaemonServer.#handleRequest附近的代码,以及src/daemon/dispatch.ts中引用的dispatch行为。将列出的37个单次调用分支移入PASSTHROUGH_OPERATIONS,并在默认分支之前添加带守卫的dispatch。保留执行额外工作的8个分支及其文档中说明的例外;运行socket测试,然后运行pnpm check,并确认switch有11个case分支。

由索引模型根据 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 分钟
30 天内合并 PR
376

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

callstackincubator/simlock 的其他 Issue

查看 callstackincubator/simlock 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。