Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(daemon): table-ify handleSessionCommands - #1467

Merged
thymikee merged 1 commit into
mainfrom
claude/optimistic-ritchie-flgfty
Jul 28, 2026
Merged

refactor(daemon): table-ify handleSessionCommands#1467
thymikee merged 1 commit into
mainfrom
claude/optimistic-ritchie-flgfty

Conversation

@thymikee

Copy link
Copy Markdown
Member

Fixes #1458.

Summary

  • Replaces the 18-branch if-chain in handleSessionCommands (src/daemon/handlers/session.ts) with SESSION_COMMAND_HANDLER_IMPLS, a handler table keyed by session-routed command name, following the existing snapshot.ts / dispatch.ts pattern.
  • Adds DescriptorSessionRouteCommandName to src/core/command-descriptor/registry.ts — the literal union of every command whose daemon.route is 'session', derived from the descriptor registry (mirrors the existing DescriptorDispatchCommandName).
  • The table is satisfies Record<DescriptorSessionRouteCommandName, SessionCommandHandler>, so a session-routed descriptor with no matching table entry is a compile error.
  • Command-kind groupings are preserved by mapping several command names to the same handler reference (e.g. session_list/devices/capabilities/apps all point at handleSessionInventoryCommandGroup; boot/shutdown/appstate at handleSessionStateCommandGroup; perf/logs/events/network/audio at handleSessionObservabilityCommandGroup; replay/test at handleSessionReplayCommandGroup) — no working handler was split.
  • Deletes the fallow-ignore-next-line complexity waiver that gated the old if-chain.
  • expectHandlerResponse in request-handler-chain.ts is untouched — it stays as defense-in-depth for raw-wire requests.
  • Zero behavior change: every branch's request/response shape, error messages, and ordering are identical; only the dispatch mechanism changed.

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:

{
  name: 'fake_session_probe',
  catalog: { group: 'internal', key: 'fakeSessionProbe' },
  recordsSessionAction: false,
  daemon: { route: 'session', refFrameEffect: 'preserve' },
  timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
  batchable: false,
},

pnpm typecheck failed as expected:

src/daemon/handlers/session.ts(465,3): error TS2741: Property 'fake_session_probe' is missing in type '{ session_list: SessionCommandHandler; ... }' but required in type 'Record<"apps" | "appstate" | ... | "fake_session_probe" | ... , SessionCommandHandler>'.

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 the fallow dead-code --production gate. The function and its SessionCommandKind classification are still exercised by daemon-command-registry.test.ts, so I added it to .fallowrc.json's ignoreExports allowlist, following the same pattern already used there for other test-only-consumed exports (e.g. listRegisteredDispatchCommandNames's sibling in dispatch.ts).

Test plan

  • pnpm check:tooling (lint, typecheck, layering, depgraph, production-exports, mcp-metadata, build, bundle-owner-files) — green
  • pnpm test:unit — 523/523 test files, 4660 tests passing
  • pnpm test:smoke — 13/15 passing; the 2 failures (smoke-daemon-clean, smoke-daemon-http) reproduce identically on the unmodified main baseline in this sandbox (real daemon-process spawn is restricted here), unrelated to this change
  • Existing handler tests pass unmodified (no test file edits were needed at all — imports of handleSessionCommands are unchanged since its exported signature is identical)

Generated by Claude Code

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
@github-actions

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.87 MB 1.87 MB +798 B
JS gzip 598.9 kB 598.9 kB +13 B
npm tarball 714.6 kB 714.6 kB +11 B
npm unpacked 2.50 MB 2.50 MB +798 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.0 ms 26.8 ms -0.2 ms
CLI --help 57.4 ms 56.5 ms -0.9 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/session.js +1.4 kB +228 B
dist/src/reporting.js -381 B -156 B
dist/src/cli-help.js -160 B -51 B
dist/src/internal/daemon.js -49 B -7 B

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Jul 28, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Reviewed clean at 092cb581eec7f6e1250ee5a9d9cbb6a35a14f7b1.

The descriptor-derived exhaustive session-handler table preserves the existing handler groupings and raw-wire null fallback while making a missing session route a compile-time failure. Existing defense-in-depth routing remains intact; checks are green. Ready for human review.

@thymikee
thymikee merged commit 6f476b5 into main Jul 28, 2026
25 checks passed
@thymikee
thymikee deleted the claude/optimistic-ritchie-flgfty branch July 28, 2026 15:39
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-28 15:41 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(daemon): table-ify handleSessionCommands — the one router that skipped the repo's own dispatch pattern

2 participants