Skip to content

[Cleanup] Split useGatewayBootstrap god hook (6 responsibilities) #345

@samzong

Description

@samzong

Problem

useGatewayBootstrap is a god hook that handles 6 distinct concerns in a single function:

  1. Gateway dispatcher singleton initialization
  2. Event listener registration (status, catalogs, version)
  3. Task store subscription for ensemble hydration
  4. Performer candidate callback registration
  5. Approval handler wiring
  6. Debug event listener setup

This makes the hook hard to test, reason about, and modify without risking side effects in unrelated concerns.

Location

File: packages/desktop/src/renderer/hooks/useGatewayBootstrap.ts

Fix Approach

Split into focused hooks:

// useGatewayDispatcherSetup.ts — responsibility 1
export function useGatewayDispatcherSetup() { ... }

// useGatewayEventListeners.ts — responsibility 2
export function useGatewayEventListeners(dispatcher: GatewayDispatcher) { ... }

// useEnsembleSync.ts — responsibilities 3-4
export function useEnsembleSync(dispatcher: GatewayDispatcher) { ... }

// The original hook becomes a thin orchestrator:
export function useGatewayBootstrap() {
  const dispatcher = useGatewayDispatcherSetup();
  useGatewayEventListeners(dispatcher);
  useEnsembleSync(dispatcher);
}

Verification

  1. Run pnpm check — must pass
  2. Connect to gateway, create task, verify session events flow correctly

Context

  • WG: UI & Design System + Task & Session Core
  • Priority: Medium
  • Estimated effort: ~1 hour

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreTask & Session Core WGarea/uiUI & Design System WGkind/cleanupCategorizes issue or PR as related to code cleanup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions