Repository navigation
refactor(move): split daemon server http-server.ts by ownership seam - #3393
Conversation
http-server.ts crossed the 1,000-line architecture-debt line. Split it along the ownership seams the file already had, with no behavior change: - http-rpc-envelope.ts: the JSON-RPC envelope types, error builders, and plain/NDJSON response writers for /rpc - http-authorization.ts: the auth hook, token check, tenant-trust gate, auxiliary-route authorization, and remote-surface restrictions - http-rpc-methods.ts: the RPC method vocabulary and the projections that turn each method's params into a DaemonRequest - http-server.ts: the listener and route dispatch that wires them together Wire-surface declarations moved with their text: digests are unchanged (moved key paths are handled by the wire-compat move model).
…TTP modules The daemon RPC wire manifest, ledger keys, and mutation probes now name http-rpc-envelope.ts / http-rpc-methods.ts / http-authorization.ts where the declarations moved. All 28 declaration digests are unchanged, so the released-surface comparison reads them as moves, not wire changes. The fallow health baseline entry for http-server.ts splits to match: the two parse* findings move with their code, the dispatcher keeps its own.
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
1 issue found across 10 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/daemon/server/http-rpc-envelope.ts">
<violation number="1" location="src/daemon/server/http-rpc-envelope.ts:67">
P3: The extraction left this comment pointing to checks “below,” but those checks are now in `http-server.ts`; update the reference so readers can find them.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
|
||
| // Map a thrown boundary error to its JSON-RPC error code. Invalid params (malformed | ||
| // wire input rejected before the request reaches the handler) is JSON-RPC -32602, to | ||
| // match the explicit `Invalid params` sibling checks below; everything else is the |
There was a problem hiding this comment.
P3: The extraction left this comment pointing to checks “below,” but those checks are now in http-server.ts; update the reference so readers can find them.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/daemon/server/http-rpc-envelope.ts, line 67:
<comment>The extraction left this comment pointing to checks “below,” but those checks are now in `http-server.ts`; update the reference so readers can find them.</comment>
<file context>
@@ -0,0 +1,91 @@
+
+// Map a thrown boundary error to its JSON-RPC error code. Invalid params (malformed
+// wire input rejected before the request reaches the handler) is JSON-RPC -32602, to
+// match the explicit `Invalid params` sibling checks below; everything else is the
+// generic application error -32000.
+function jsonRpcCodeForNormalizedError(code: string): number {
</file context>
| // match the explicit `Invalid params` sibling checks below; everything else is the | |
| // match the explicit `Invalid params` checks in `http-server.ts`; everything else is the |
|
This PR is ready. The split of http-server.ts matches the original text, and 19/19 checks pass at 751fb67, including the wire-compat gate on the moved declarations and the daemon HTTP suites that run against createDaemonHttpServer. There are no conflicts. Not blocking: ADR 0023 rows 70 and 159 still say http-server.ts "resolves the token", and the comment at src/daemon/session-tenant-scope.ts:12 says the auth hook attests the tenant in http-server.ts, but resolveToken and runHttpAuthHook now live in http-authorization.ts, so you can point those at the new file or leave them. I did not re-run the local gates from the PR body and relied on CI. I compared sorted line sets for the move, so order inside the non-wire functions is not proven, but the hunks I compared show no body changes. One cubic-dev-ai P3 thread still applies: #3393 (comment). The comment at http-rpc-envelope.ts:67 says "sibling checks below", but the -32602 "Invalid params" sends are now in http-server.ts. The fix is a comment-only change. Nothing else is needed before merge. |
|
#3393 split http-server.ts into http-authorization/http-rpc-envelope/ http-rpc-methods (daemon-server) and #3400 moved dispatch-context (daemon-core: pure flag vocabulary read by core's context.ts) and interaction-response-data-transform (daemon-execution, beside its touch-response consumer) into the daemon; the exhaustive manifest follows, verified upward-edge-free at the new head.
#3391) * chore(gates): add the daemon layer manifest and R81 daemon-layer rule Partition every production file under src/daemon/ into five local layers (core < resources < execution < sessions < server) with an exhaustive machine-readable manifest, and verify it: reject upward static value and type-only edges, report dynamic cross-layer edges without rejecting them, and fail on omitted, duplicated, or untracked manifest entries. No files move; the global spine rank stays 4 for all five layers. * chore(gates): R81 rejects a declared layer that owns no files An empty layer array kept a phantom position in the daemon layer order after its last file moved; reject it, and isolate the orphaned-file test from the empty-layer check. * chore(gates): layer the five daemon files main gained since the seed #3393 split http-server.ts into http-authorization/http-rpc-envelope/ http-rpc-methods (daemon-server) and #3400 moved dispatch-context (daemon-core: pure flag vocabulary read by core's context.ts) and interaction-response-data-transform (daemon-execution, beside its touch-response consumer) into the daemon; the exhaustive manifest follows, verified upward-edge-free at the new head.
Summary
src/daemon/server/http-server.tscrossed the 1,016-line architecture-debt line (AGENTS.md: files past 1,000 lines are debt). This splits it along the ownership seams the file already had, with no behavior change:http-rpc-envelope.ts(92 lines) — the JSON-RPC envelope types, error builders, and plain/NDJSON response writers for/rpc.http-authorization.ts(291 lines) — the auth hook (load + run), token check, tenant-trust gate, auxiliary-route authorization, and remote-surface restrictions.http-rpc-methods.ts(311 lines) — the RPC method vocabulary and the per-method projections intoDaemonRequest.http-server.ts(395 lines) — the listener:/health, auxiliary route dispatch,/rpcbody framing, and the wiring of the gate around each request.10 touched files; the rest of the diff is the path-keyed enforcement moving with the code (wire-compat manifest/ledger/mutation probes, fallow health baseline, one ADR path reference). No new eager dependencies: the split files' import closures are unions of the original file's imports.
Validation
Tested at
751fb6757(the pushed head):pnpm install --frozen-lockfile && pnpm build,pnpm format(clean),pnpm check:quick,pnpm check:layering,pnpm check:fallow,pnpm check:production-exports— pass.http-server-{artifacts,limrun-uploaded-apps,rpc-validation,tenant-trust},host-lease-http,human-control-http,request-diagnostics-http,request-save-script-transports,http-instance-precondition(62 tests) and thedaemon-http-*/remote-*provider-scenario suites + daemon-client abort / daemon-proxy / cli-remote-diagnostics (55 tests) — all pass. No test files were moved (nohttp-server.test.tsexisted; the suites importcreateDaemonHttpServer, whose path is unchanged).pnpm check:affected --run— all runnable checks pass.pnpm check:daemon-wire-compat— 191 declarations, 0 changed/removed/added, 27 moved: all 28 wire declarations moved with byte-identical text, so digests are unchanged and the released-surface comparison reads them as file moves (no bump, no ack).pnpm depgraph):1,817 files / 9,721 edges;dominator summary for src/daemon.ts: 650 of 1817 files loaded eagerly, biggest branch daemon-runtime.ts (647 files, 102035 loc)1,820 files / 9,738 edges;dominator summary for src/daemon.ts: 653 of 1820 files loaded eagerly, biggest branch daemon-runtime.ts (650 files, 102110 loc)eager-closure-budgets.test.tsaccepts this under the ADR-0027 split tolerance: contained closure, novel modules, flat weight). No new eager edge: R4/R5/R6/zone SCCs unchanged.