Skip to content

Migrate to event-driven orchestration architecture#1

Merged
fmizzell merged 2 commits into
mainfrom
event-driven-refactor
Nov 8, 2025
Merged

Migrate to event-driven orchestration architecture#1
fmizzell merged 2 commits into
mainfrom
event-driven-refactor

Conversation

@fmizzell

@fmizzell fmizzell commented Nov 8, 2025

Copy link
Copy Markdown
Owner

Summary

Migrated Hearth from imperative orchestration loop to fully event-driven architecture using Atmos events, reducers, before hooks, and listeners.

Key Changes

New Files:

  • orchestration.go (346 lines) - Event-driven orchestration logic
    • Reducers: Build state only (no side effects)
    • Before hooks: Do work (Claude calls, context gathering, enrichment)
    • Listeners: Chain events (event-driven flow)
  • execution.go (175 lines) - Reusable business logic
    • ExecuteTask, BuildTaskContext, StoreTaskResult
    • ClaudeCaller interface with DefaultClaudeCaller implementation
  • orchestration_test.go - Test event-driven orchestration

Simplified:

  • cmd/hearth/run.go: 425 → 92 lines (78% reduction)
    • Single entry point: h.Process(&ExecuteTasksRequested{})
    • Logging moved to orchestration hooks

Enhanced:

  • events.go: Added orchestration events
    • ExecuteTasksRequested, NextTaskSelected, TaskExecuted
    • SummaryRequested, SummaryGenerated
  • reducers.go: Removed mutation logic (now event-driven)

Removed:

  • cmd/hearth/run_test.go (278 lines) - Logic now tested in core tests

Architecture Benefits

✅ Clear separation of concerns (reducers/hooks/listeners)
✅ Fully auditable event log
✅ Highly testable (10 tests passing)
✅ No state mutations in reducers
✅ Event-driven parent auto-completion

Test Plan

  • All 10 tests passing
  • Logging works correctly during execution
  • Verify context injection (parent chain, sibling results) - TODO
  • Manual testing with real Claude execution

Known Issues

  • Context injection may not be working correctly (needs verification)
  • Parent chain and sibling results might not be passed to Claude

🤖 Generated with Claude Code

Migrated from imperative orchestration loop to fully event-driven
architecture using Atmos events, reducers, before hooks, and listeners.

Key changes:
- Created orchestration.go (346 lines) with event-driven flow:
  * Reducers: Build state only (no side effects)
  * Before hooks: Do work (Claude calls, context gathering, enrichment)
  * Listeners: Chain events (event-driven flow)

- Created execution.go (175 lines) with reusable business logic:
  * ExecuteTask, BuildTaskContext, StoreTaskResult
  * ClaudeCaller interface with DefaultClaudeCaller implementation

- Simplified cmd/hearth/run.go from 425 → 92 lines (78% reduction)
  * Removed imperative task loop
  * Single entry point: h.Process(&ExecuteTasksRequested{})

- Added orchestration events to events.go:
  * ExecuteTasksRequested, NextTaskSelected, TaskExecuted
  * SummaryRequested, SummaryGenerated

- Fixed parent auto-completion:
  * Replaced reducer mutation with event-driven approach
  * onTaskCompletedParent emits TaskCompleted for parents

- Added logging directly in orchestration hooks
  * beforeNextTaskSelected: logs task selection
  * beforeTaskExecuted: logs Claude calls
  * onTaskCompletedParent: logs task completion

- Deleted obsolete cmd/hearth/run_test.go (278 lines)
  * Logic now tested in hearth_test.go and orchestration_test.go

All 10 tests passing. Event-driven architecture complete.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

Major refactoring to improve code organization and test coverage:

## File Organization
- Split orchestration.go into architectural layers:
  - hooks.go: Before hooks (where work happens)
  - listeners.go: Event chaining
  - reducers.go: State updates (added orchestration reducers)
- Moved HearthState and Task types to state.go
- Deleted orchestration.go (setup moved to hearth.go)
- Deleted persistence.go (merged into hearth.go)
- Created test_utils.go for shared test helpers

## API Cleanup
- Merged NewHearth and NewHearthWithPersistence into single constructor
  - Empty workspaceDir = in-memory (for tests)
  - Non-empty workspaceDir = persistence + services
- Removed complete command (not needed with autonomous orchestration)
- Removed DependsOn field from TaskCreated event and Task struct
- Removed --depends-on flag from add command

## Service Registration
- Moved service registration into NewHearth constructor
- Services now registered during engine construction (not after)
- Removed RegisterServices method

## Decoupling
- Decoupled execution.go from Hearth dependency
- ExecuteTask and BuildTaskContext now pure functions
- Functions take taskID and tasks map instead of Hearth instance

## Testing
- Rewrote TestHearthJourney to test autonomous orchestration
  - Exercises full event-driven flow (79% code coverage)
  - Tests depth-first scheduling, parent auto-completion, summary generation
  - Revealed and fixed orchestration bug in onSummaryGenerated
- Created MockClaudeCaller for testing without real API calls
- Fixed all persistence tests (were hanging due to Claude API calls)
  - TestEventPersistence
  - TestEventPersistence_ComplexHierarchy
  - TestEventPersistence_EmptyWorkspace
  - TestEventPersistence_EventMerging
- All tests passing, golangci-lint clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@fmizzell fmizzell marked this pull request as ready for review November 8, 2025 09:02
@fmizzell fmizzell merged commit b488afc into main Nov 8, 2025
4 checks passed
@fmizzell fmizzell deleted the event-driven-refactor branch November 8, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants