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

Aperta Adatta ai principianti
#1,441 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api, backend

Direzione di ricerca

Leggi src/daemon/server.ts intorno a DaemonServer.#handleRequest e il comportamento di dispatch citato in src/daemon/dispatch.ts. Sposta i 37 casi elencati con una sola chiamata in PASSTHROUGH_OPERATIONS e aggiungi il dispatch protetto prima del caso predefinito. Mantieni gli otto casi che svolgono lavoro aggiuntivo e le relative eccezioni documentate; esegui i test dei socket, poi pnpm check e conferma che lo switch abbia 11 casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
705
Fork
40
Merge medio
12h 9m
PR unite (30g)
376

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di callstackincubator/simlock

Tutte le issue di callstackincubator/simlock

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.