Skip to content

Conversation

@jwillp
Copy link
Contributor

@jwillp jwillp commented Oct 19, 2025

This pull request introduces a workflow orchestration subsystem with event-driven orchestration, workflow/run management, and lease-based concurrency control. It adds new orchestrator, worker, and lease management components, adapts repositories for event sourcing, and updates deployment configuration to use PostgreSQL for persistence. The most important changes are grouped below.

Workflow Orchestration and Concurrency Management:

  • Added new orchestrator (internal/orchestrator/orchestrator.go) and worker (internal/orchestrator/worker.go) components to handle workflow events, manage concurrent workflow runs, and ensure only one runner processes a workflow run at a time using leases. [1] [2]
  • Introduced lease management (internal/orchestrator/lease.go) with interfaces and manager logic for acquiring, renewing, and releasing workflow run leases, supporting both in-memory and PostgreSQL-backed repositories. [1] [2] [3]

Event-Sourced Workflow and Run Repositories:

  • Implemented event-sourced repositories for workflows and runs (internal/workflowmgmt/adapters/workflow_repo.go, internal/workflowmgmt/adapters/run_repo.go), enabling persistence and retrieval of workflow/run state from event streams. [1] [2]

Workflow Actions and Execution:

  • Added an extensible action interface and function type for workflow steps (internal/workflowmgmt/action.go), allowing custom step logic to be injected and executed within workflows.

Deployment and Infrastructure Updates:

  • Updated deployment configuration to use PostgreSQL as the backing store (compose.yaml), removed the debug compose file, and added required Go module dependencies and local module replacement for development. [1] [2] [3]

Application Initialization:

  • Refactored cmd/smallflow/main.go to initialize all components, wire up repositories, event stores, orchestrator, and demonstrate workflow enable/trigger operations with event inspection.

@jwillp jwillp self-assigned this Oct 19, 2025
@jwillp jwillp requested a review from Copilot October 19, 2025 08:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Introduces event-driven workflow orchestration with lease-based concurrency control, event-sourced repositories for workflows and runs, and a demo app wiring everything against PostgreSQL.

  • Adds orchestrator and worker components with lease management (in-memory and PostgreSQL)
  • Implements event-sourced repositories for workflows and runs, and command handlers for enable/disable/trigger/run/resume
  • Updates compose to PostgreSQL and boots an end-to-end demo in cmd/smallflow

Reviewed Changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
specs/smallflow.def.hcl Defines system metadata and Go backend version for the project
specs/business/workflowmgmt.def.hcl Declares business commands/events/structs/service providers for workflow management
internal/workflowmgmt/*.go Core workflow domain, command handlers, runner and adapters for event-sourced storage
internal/orchestrator/*.go Orchestrator, worker and lease management (interfaces and implementations)
internal/orchestrator/adapters/*.go Lease repositories (PostgreSQL and in-memory)
cmd/smallflow/main.go Wires repositories, orchestrator, and runs a demo scenario
compose.yaml Adds a PostgreSQL service and volumes
go.mod Adds dependencies and local replace for go-misas

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

})).
WithCommandHandler(ResumeWorkflowRunCommandTypeName, mx.NewTypedCommandHandler(ResumeWorkflowRunCommandHandler{
WorkflowRepository: workflowRepo,
RunRepository: runRepository,
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResumeWorkflowRunCommandHandler.Runner is never initialized; Handle calls h.Runner.ResumeFromStep will use a zero-value runner with nil repositories, causing a nil dereference. Initialize Runner here, e.g., Runner: WorkflowRunner{RunRepository: runRepository, WorkflowRepository: workflowRepo, Clock: clock}.

Suggested change
RunRepository: runRepository,
RunRepository: runRepository,
Runner: WorkflowRunner{
RunRepository: runRepository,
WorkflowRepository: workflowRepo,
Clock: clock,
},

Copilot uses AI. Check for mistakes.

clock := mx.NewRealTimeClock(time.UTC)

dbConn, err := mpostgres.OpenConn("postgres://smallflow:smallflow@localhost:5432/postgres?sslmode=disable")
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The connection string targets the 'postgres' database, but compose config sets POSTGRES_DB=smallflow. Align the DSN to use the 'smallflow' database to avoid auth/permission mismatches (e.g., postgres://smallflow:smallflow@localhost:5432/smallflow?sslmode=disable).

Suggested change
dbConn, err := mpostgres.OpenConn("postgres://smallflow:smallflow@localhost:5432/postgres?sslmode=disable")
dbConn, err := mpostgres.OpenConn("postgres://smallflow:smallflow@localhost:5432/smallflow?sslmode=disable")

Copilot uses AI. Check for mistakes.
description = "Detailed error message."
type = "string"
}
fiel "Details" {
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: 'fiel' should be 'field'.

Suggested change
fiel "Details" {
field "Details" {

Copilot uses AI. Check for mistakes.
Comment on lines +291 to +292
type = "workflowmgmt.WorkflowState"
type = "[]byte"
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field 'workflow' has two 'type' entries; this is invalid/ambiguous in the schema. Keep only the intended type (e.g., workflowmgmt.WorkflowState) and remove the duplicate.

Suggested change
type = "workflowmgmt.WorkflowState"
type = "[]byte"
type = "workflowmgmt.WorkflowState"

Copilot uses AI. Check for mistakes.
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