refactor(daemon): table-ify handleSessionCommands - #1467
Merged
Conversation
Replace the 18-branch if-chain in handleSessionCommands with a handler table keyed by session-routed command name, satisfies-checked against DescriptorSessionRouteCommandName (derived from command-descriptor registry entries with route: 'session'). A missing handler entry is now a compile error instead of a runtime routing gap caught only by expectHandlerResponse. Command-kind groupings (inventory/state/ observability/replay) map several command names to the same shared handler reference, preserving the former getSessionCommandKind clustering without the runtime lookup. Deletes the fallow-ignore-next-line complexity waiver the if-chain required. getSessionCommandKind itself is no longer called from production code (only exercised by its own unit test), so it's added to the fallow production-exports allowlist alongside the existing test-only-consumer entries. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01U7JRr87E2QguHF36XrVbph
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
Member
Author
|
Reviewed clean at The descriptor-derived exhaustive session-handler table preserves the existing handler groupings and raw-wire |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1458.
Summary
handleSessionCommands(src/daemon/handlers/session.ts) withSESSION_COMMAND_HANDLER_IMPLS, a handler table keyed by session-routed command name, following the existingsnapshot.ts/dispatch.tspattern.DescriptorSessionRouteCommandNametosrc/core/command-descriptor/registry.ts— the literal union of every command whosedaemon.routeis'session', derived from the descriptor registry (mirrors the existingDescriptorDispatchCommandName).satisfies Record<DescriptorSessionRouteCommandName, SessionCommandHandler>, so a session-routed descriptor with no matching table entry is a compile error.session_list/devices/capabilities/appsall point athandleSessionInventoryCommandGroup;boot/shutdown/appstateathandleSessionStateCommandGroup;perf/logs/events/network/audioathandleSessionObservabilityCommandGroup;replay/testathandleSessionReplayCommandGroup) — no working handler was split.fallow-ignore-next-line complexitywaiver that gated the old if-chain.expectHandlerResponseinrequest-handler-chain.tsis untouched — it stays as defense-in-depth for raw-wire requests.Compile-time exhaustiveness demonstration
Per the acceptance criteria, I verified the guard actually fires by temporarily adding a fake session-routed descriptor with no handler entry:
pnpm typecheckfailed as expected:The fake descriptor was then reverted before this commit — it isn't part of the diff.
Incidental fix
getSessionCommandKind(src/daemon/daemon-command-registry.ts) had no production consumer left after this refactor (the new table encodes command-kind clustering directly via shared handler references instead of a runtime kind lookup), which tripped thefallow dead-code --productiongate. The function and itsSessionCommandKindclassification are still exercised bydaemon-command-registry.test.ts, so I added it to.fallowrc.json'signoreExportsallowlist, following the same pattern already used there for other test-only-consumed exports (e.g.listRegisteredDispatchCommandNames's sibling indispatch.ts).Test plan
pnpm check:tooling(lint, typecheck, layering, depgraph, production-exports, mcp-metadata, build, bundle-owner-files) — greenpnpm test:unit— 523/523 test files, 4660 tests passingpnpm test:smoke— 13/15 passing; the 2 failures (smoke-daemon-clean,smoke-daemon-http) reproduce identically on the unmodifiedmainbaseline in this sandbox (real daemon-process spawn is restricted here), unrelated to this changehandleSessionCommandsare unchanged since its exported signature is identical)Generated by Claude Code