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

Đang mở Phù hợp với người mới
#1,441 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

Đọc src/daemon/server.ts quanh DaemonServer.#handleRequest và hành vi dispatch được trích dẫn trong src/daemon/dispatch.ts. Chuyển 37 nhánh được liệt kê chỉ gọi một lần vào PASSTHROUGH_OPERATIONS và thêm dispatch có điều kiện bảo vệ trước nhánh mặc định. Giữ lại tám nhánh thực hiện công việc bổ sung cùng các ngoại lệ đã được ghi rõ; chạy các bài kiểm thử socket, sau đó chạy pnpm check và xác nhận switch có 11 nhánh case.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
705
Fork
40
Merge trung bình
12 giờ 9 phút
Pull request đã merge (30 ngày)
376

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của callstackincubator/simlock

Tất cả issue của callstackincubator/simlock

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.