Skip to content

Command handler registry: core + migrate decider switch #136

Description

@harrryyd

What to build

Replace the monolithic switch (command.type) in decideOrchestrationCommand (apps/server/src/orchestration/decider.ts, 976 lines) with a CommandHandlerRegistry that dispatches by command type.

Registry design:

type CommandHandler = (command: OrchestrationCommand, readModel: OrchestrationReadModel) =>
  Effect<DecideOrchestrationCommandResult, OrchestrationCommandInvariantError | PlatformError>;

registry.register("thread.archive-and-new", handleArchiveAndNew)
registry.register("thread.context.trim", handleContextTrim)
registry.register("thread.context.compact", handleContextCompact)
registry.register("thread.context.summarize", handleContextSummarize)
registry.register("project.create", handleProjectCreate)
// ... etc

The decider becomes:

const handler = registry.get(command.type);
if (!handler) throw new Error(`No handler for command type: ${command.type}`);
return yield* handler(command, readModel);

Migrate these commands to individual handler files:

  • All 4 h-code commands: archive-and-new, context.trim, context.compact, context.summarize
  • At least 3 upstream commands (to prove the pattern works for both): e.g. project.create, thread.create, thread.delete

Each handler moves to its own file with its invariants co-located.

Acceptance criteria

  • CommandHandlerRegistry built (reusing MethodRegistry pattern from Pre-factor: MethodRegistry generic utility #132)
  • decideOrchestrationCommand replaced with registry dispatch
  • All 4 h-code commands have dedicated handler files (e.g. handlers/archiveAndNew.ts)
  • At least 3 upstream commands migrated to handler files
  • Existing decider tests pass without modification (they call decideCommandSequence which delegates to registered handlers)
  • decider.contextTrim.test.ts and decider.archiveAndNew.test.ts still pass
  • vp check and vp run typecheck pass

Blocked by

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions