Skip to content

[Code Quality] Split compiler_orchestrator.go into Focused Modules (1077 → 300-400 lines) #11766

@github-actions

Description

@github-actions

Description

The file pkg/workflow/compiler_orchestrator.go contains 1,077 lines, exceeding the 800-line guideline by 35%. This makes the file difficult to navigate and maintain. The file handles multiple distinct compilation phases that can be logically separated.

Current Issues

  1. File Size: 1,077 lines vs 800-line maximum guideline
  2. Mixed Responsibilities: Frontmatter parsing, engine setup, tools processing, workflow construction
  3. Long Functions: Multiple functions exceed 100 lines:
    • processToolsAndMarkdown: ~200+ lines
    • setupEngineAndImports: ~200+ lines
    • ParseWorkflowFile: ~70+ lines
  4. Navigation Difficulty: Hard to find specific compilation logic

Suggested File Split

Split into 4 focused files (~250-300 lines each):

1. compiler_orchestrator_frontmatter.go

Responsibility: Frontmatter parsing and validation

  • parseFrontmatterAndPrintFailures()
  • validateFrontmatterConfig()
  • Frontmatter result types
  • Estimated lines: ~250

2. compiler_orchestrator_engine.go

Responsibility: Engine setup and configuration

  • setupEngineAndImports()
  • processEngineDetection()
  • Engine result types
  • Estimated lines: ~250

3. compiler_orchestrator_tools.go

Responsibility: Tools and markdown processing

  • processToolsAndMarkdown()
  • extractMarkdownContent()
  • processToolConfiguration()
  • Tools result types
  • Estimated lines: ~300

4. compiler_orchestrator_workflow.go

Responsibility: Workflow data construction and orchestration

  • ParseWorkflowFile() (main orchestration)
  • buildWorkflowData()
  • Core orchestration logic
  • Estimated lines: ~250-300

Benefits

  1. Improved Navigation: Find specific compilation logic faster
  2. Better Maintainability: Smaller files are easier to understand
  3. Clearer Separation: Each file has single, clear responsibility
  4. Easier Testing: Test files can mirror the split structure
  5. Reduced Cognitive Load: Developers work with 250-300 line files vs 1077

Files Affected

Original file (to be split):

  • pkg/workflow/compiler_orchestrator.go (1,077 lines)

New files (to be created):

  • pkg/workflow/compiler_orchestrator_frontmatter.go (~250 lines)
  • pkg/workflow/compiler_orchestrator_engine.go (~250 lines)
  • pkg/workflow/compiler_orchestrator_tools.go (~300 lines)
  • pkg/workflow/compiler_orchestrator_workflow.go (~250-300 lines)

Test file (may need updates):

  • pkg/workflow/compiler_orchestrator_test.go (678 lines, test-to-source ratio: 0.63)

Implementation Approach

Phase 1: Extract Helper Modules (Low Risk)

  1. Create new files with extracted functions
  2. Keep original file as orchestrator
  3. Run tests after each extraction
  4. Verify make build && make test passes

Phase 2: Refactor Large Functions (Medium Risk)

  1. Extract sub-functions from 200+ line functions
  2. Move to appropriate module files
  3. Maintain backward compatibility

Phase 3: Clean Up Orchestrator (Low Risk)

  1. Slim down main orchestrator file
  2. Remove duplicated code
  3. Final test verification

Success Criteria

  • Original file reduced from 1,077 to ~250-300 lines
  • 4 new files created with clear, focused responsibilities
  • No functions exceed 100 lines in new files
  • All existing tests pass without modification
  • Test-to-source ratio maintained (current: 0.63)
  • make build && make test passes
  • make lint reports no issues
  • make recompile successfully regenerates workflows
  • No regression in compilation behavior

Reference Example

Use pkg/workflow/compiler_jobs.go (503 lines, score: 93/100) as a reference for ideal file structure and organization.

Estimated Effort

1 day (8 hours)

  • 3 hours: Extract and create new files
  • 2 hours: Refactor large functions into helpers
  • 2 hours: Testing and verification
  • 1 hour: Documentation and cleanup

Source

Extracted from Daily Compiler Code Quality Report #11729 - Analysis of compiler_orchestrator.go (2026-01-25)

Priority

Medium - File size exceeds guidelines significantly, but code quality is otherwise good (score: 80/100). Refactoring improves maintainability without urgent functional issues.

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 8, 2026, 2:04 PM UTC

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions