Imported from cschleiden/go-workflows (
AGENTS.md). Install upstream withnpx skills add cschleiden/go-workflows. Copyright stays with the author.
go-workflows Development Guide for AI Agents
Durable workflows library for Go that borrows heavily from Temporal and DTFx. Supports multiple backends (MySQL, Redis, SQLite, in-memory) and provides comprehensive workflow orchestration capabilities.
This guide provides essential information for AI coding agents working on this project. Always reference this information first before exploring the codebase or running commands.
Development Environment Setup
Bootstrap and Build
Execute these commands in sequence to set up a working development environment:
# 1. Download Go dependencies - Takes ~3.5 minutes. Allow sufficient timeout.
go mod download
# 2. Build all packages - Takes ~40 seconds.
go build -v ./...
# 3. Start development dependencies - Takes ~13 seconds.
docker compose up -d
Testing
# Run short tests - Takes ~45 seconds.
go test -short -timeout 120s -race -count 1 -v ./...
# Run full test suite - Takes ~2.5 minutes.
go test -timeout 180s -race -count 1 -v ./...
# Install test reporting tool (if needed)
go install github.com/jstemmer/go-junit-report/v2@latest
# Run tests with JUnit output (as used in CI) - Takes ~2.5 minutes.
go test -timeout 120s -race -count 1 -v ./... 2>&1 | go-junit-report -set-exit-code -iocopy -out "report.xml"
Linting
The project uses golangci-lint v2 with a custom analyzer plugin for workflow code validation. There are multiple ways to run the linter:
Recommended: Using Makefile (Preferred)
# Run the full linter suite with custom analyzer - Takes ~12-15 seconds.
make lint
This will:
- Check if golangci-lint is installed
- Build the custom analyzer plugin
- Run all configured linters from
.golangci.yml
Manual Setup
If you need to install golangci-lint or run it manually:
# Install golangci-lint v2 (required for this project)
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0
# Run the full linter configuration - Takes ~12-15 seconds.
golangci-lint run --timeout=5m
Note: The project uses golangci-lint v2.4.0 configuration. Version v1.x will not work with the .golangci.yml configuration file.
Workaround: Basic Linting (When Custom Analyzer Has Issues)
If the custom analyzer has version compatibility issues:
# Run basic linting without custom analyzer - Takes ~12 seconds.
golangci-lint run --disable-all --enable=gofmt,govet,ineffassign,misspell --timeout=5m
Available Linters
The .golangci.yml configuration enables multiple linters including:
- Code Quality: staticcheck, unused, ineffassign, wastedassign
- Bug Detection: govet, makezero, prealloc, predeclared
- Style & Formatting: gofmt, whitespace, tagalign
- Testing: testifylint, tparallel
- Custom: goworkflows (workflow-specific validation, currently commented out)
Sample Applications
# Simple workflow example with Redis backend (default)
cd samples/simple && go run .
# Simple workflow with SQLite backend
cd samples/simple && go run . -backend sqlite
# Benchmark utility
cd bench && go run .
# Web example with diagnostic UI
cd samples/web && go run .
# Access UI at http://localhost:3000/diag
Validation and Testing
Core Workflow Functionality
Always test core workflow functionality after making changes:
-
Simple End-to-End Test:
cd samples/simple && go run . -backend sqliteExpected output: "Workflow finished. Result: 59"
-
Multi-Backend Test:
# Test Redis backend (requires docker compose up) cd samples/simple && go run . # Test SQLite backend (embedded) cd samples/simple && go run . -backend sqlite -
Benchmark Validation:
cd bench && go run .Expected: Workflow hierarchy execution with metrics output
Pre-Commit Validation
Run these validation steps before committing changes:
- Full Build:
go build -v ./...- Must complete without errors - Short Tests:
go test -short -timeout 120s -race -count 1 -v ./...- Should pass (1 known non-critical test failure in tester package) - Linting:
make lintorgolangci-lint run --timeout=5m- Should pass with no new violations - Code Formatting:
make fmt- Ensure code is properly formatted - Sample Execution: At least one sample must run successfully
Manual Testing Scenarios
Execute these scenarios to verify workflow functionality:
-
Basic Activity Workflow:
- Run
samples/simple - Verify workflow executes activities and returns result
- Check no errors in output
- Run
-
Subworkflow Execution:
- Run
benchutility - Verify hierarchical workflow creation and execution
- Check metrics output shows expected activity and workflow counts
- Run
-
Backend Switching:
- Test same workflow with different backends (Redis, SQLite)
- Verify consistent behavior across backends
Repository Structure
Key Directories
/samples/- Example applications demonstrating workflow patterns:simple/- Basic workflow with activitiesweb/- Web UI example with diagnosticssubworkflow/- Nested workflow patternstimer/- Timer and scheduling examplessignal/- Signal handling patterns
/backend/- Storage backend implementations:mysql/- MySQL backendredis/- Redis backendpostgres/- PostgreSQL backendsqlite/- SQLite backendmonoprocess/- In-memory backend
/workflow/- Core workflow execution engine/activity/- Activity execution framework/tester/- Testing utilities for workflow development/client/- Client library for workflow interactions/worker/- Worker process implementation/analyzer/- Custom Go analyzer for workflow code validation
Build and Configuration Files
go.mod- Go module definition with all dependenciesdocker-compose.yml- Development dependencies (MySQL, Redis).golangci.yml- Linting configuration (includes custom analyzer)tools.go- Development tool dependencies.github/workflows/go.yml- CI pipeline definition
Development Dependencies
The project requires Docker services for full functionality:
# Start MySQL and Redis services
docker compose up -d
# Check service status
docker compose ps
# View logs
docker compose logs
# Stop services
docker compose down
Common Development Tasks
Adding New Workflow Examples
- Create directory under
samples/ - Implement workflow and activity functions
- Add backend selection similar to existing samples
- Test with multiple backends
- Add to documentation
Backend Development
- Implement
backend.Backendinterface - Add database schema/migrations as needed
- Create integration tests using
backend/testpackage - Add CI job in
.github/workflows/go.yml
Custom Analyzer Rules
- Modify
analyzer/analyzer.go - Rebuild plugin:
go build -tags analyzerplugin -buildmode=plugin analyzer/plugin/plugin.go - Test with golangci-lint (note: version compatibility issues exist)
Performance and Timing
Operation Duration Expectations
| Operation | Typical Duration | Notes |
|---|---|---|
go mod download |
~3.5 minutes | Critical operation, allow full completion |
go build -v ./... |
~40 seconds | Full project build |
go test -short |
~45 seconds | Quick test suite |
go test (full) |
~2.5 minutes | Complete test suite |
docker compose up -d |
~13 seconds | Start services |
| Plugin build | ~8 seconds | Custom analyzer |
| Linting | ~12 seconds | Basic linting rules |
Important: Allow sufficient time for build and test operations to complete. Interrupting these operations can lead to incomplete or corrupted builds.
Known Issues and Limitations
Current Issues
- Custom analyzer plugin has version conflicts with current golangci-lint
- One test failure in
tester/tester_timers_test.go(non-critical) - Various linter warnings present but not blocking
Workarounds
- Use basic linting configuration instead of full analyzer
- Skip non-critical test failures in validation
- Focus on core functionality tests for validation
CI/CD Pipeline
The GitHub Actions workflow (.github/workflows/go.yml) performs:
- Build validation across Go versions
- Short tests on main branch
- Backend-specific tests (Redis, MySQL, SQLite) in parallel
- Test reporting with summaries
Ensure local changes pass the same validation steps that CI runs.
Best Practices for AI Agents
Code Modification Guidelines
- Always run validation tests after making changes
- Test with multiple backends when modifying core functionality
- Maintain backward compatibility in API changes
- Follow existing code patterns and conventions
- Update relevant documentation and examples
Error Handling
- Check for compilation errors after code changes
- Validate test outcomes, especially for workflow functionality
- Verify sample applications still work after modifications
- Monitor for new linter warnings
Development Workflow
- Start with understanding the existing codebase structure
- Make incremental changes and test frequently
- Use the provided samples to validate functionality
- Run appropriate validation steps before finalizing changes
Documentation
The project includes comprehensive documentation built with Slate, a static documentation generator. The documentation is located in the /docs/ directory and provides detailed guides, API references, and examples.
Documentation Structure
/docs/source/index.html.md- Main documentation file with quickstart guide/docs/source/includes/- Modular documentation sections:_guide.md- Comprehensive development guide_samples.md- Example applications and use cases_backends.md- Backend configuration and usage_faq.md- Frequently asked questions
/docs/images/- Documentation assets and images/docs/build/- Generated static documentation (created during build)
Working with Documentation
Development Server
Start a local documentation server for live editing:
cd docs
./serve.sh
This will:
- Start a Docker container running Slate
- Mount source files for live reloading
- Serve documentation at http://localhost:4567/
Building Documentation
Generate static documentation files:
cd docs
./build.sh
This creates a static site in the build/ directory suitable for deployment.
Documentation Content
The documentation covers:
- Quickstart Guide - Basic workflow and activity examples
- Comprehensive Guide - Detailed API documentation and patterns
- Sample Applications - Real-world usage examples from
/samples/ - Backend Configuration - Setup guides for MySQL, Redis, SQLite backends
- FAQ Section - Common questions and troubleshooting
Documentation Dependencies
The documentation system requires:
- Docker - For running the Slate documentation generator
- Slate Docker Image (
slatedocs/slate) - Automatically pulled when needed
Updating Documentation
When making code changes that affect the public API or add new features:
- Update Relevant Sections: Modify the appropriate
.mdfiles in/docs/source/ - Test Locally: Run
./serve.shto preview changes - Validate Examples: Ensure code examples in documentation are accurate
- Build Static Version: Run
./build.shto generate deployable documentation - Update Sample References: Keep documentation synchronized with
/samples/directory
Documentation Best Practices
- Keep code examples in documentation synchronized with working samples
- Test all code snippets to ensure they compile and run correctly
- Update documentation whenever API changes are made
- Include practical examples alongside theoretical explanations
- Maintain consistency between inline code comments and external documentation