Skip to content

[Code Quality] Refactor buildAllJobs() into focused helper functions #14488

Closed

Description

@github-actions

Description

The buildAllJobs() function in compiler_jobs.go is 140+ lines and handles multiple responsibilities: activation jobs, main job, safe outputs jobs, and memory management jobs. This complexity makes the function harder to test, maintain, and understand.

Current state:

  • Function length: 140+ lines (lines 133-277)
  • Handles 5+ distinct job types
  • Mixed concerns in a single function
  • Good test coverage (117%) but could be improved with smaller functions

Desired state:

  • Extract job-type-specific logic into focused helper functions (~30-40 lines each)
  • Single responsibility per function
  • Easier to test individual job creation logic
  • Improved readability and maintainability

Suggested Changes

Refactor buildAllJobs() into smaller, focused functions:

// Current: buildAllJobs() - 140 lines
// Proposed structure:
func buildAllJobs() error {
    if err := c.buildPreActivationAndActivationJobs(); err != nil {
        return err
    }
    if err := c.buildMainJob(); err != nil {
        return err
    }
    if err := c.buildSafeOutputsJobs(); err != nil {
        return err
    }
    if err := c.buildMemoryManagementJobs(); err != nil {
        return err
    }
    return nil
}

// Extract helpers:
func (c *Compiler) buildPreActivationAndActivationJobs() error { ... }
func (c *Compiler) buildMainJob() error { ... }
func (c *Compiler) buildSafeOutputsJobs() error { ... }
func (c *Compiler) buildMemoryManagementJobs() error { ... }

Files Affected

  • pkg/workflow/compiler_jobs.go (lines 133-277)
  • pkg/workflow/compiler_jobs_test.go (may need test updates)

Success Criteria

  • buildAllJobs() becomes a simple orchestrator (~20-30 lines)
  • Each extracted function is 30-50 lines max
  • Single responsibility per function
  • All existing tests pass
  • Test coverage maintained at 100%+ (currently 117%)
  • No behavioral changes (refactoring only)

Source

Extracted from Daily Compiler Code Quality Report discussion #13034

Finding excerpt:

"buildAllJobs() function is 140+ lines... Handles multiple responsibilities: activation, main, safe outputs, repo-memory, cache-memory jobs... Recommendation: Extract job-specific logic into smaller helper functions"

Quality score: 87/100 for compiler_jobs.go (Excellent, but this improvement would boost maintainability)

Priority

Medium - Improves code maintainability but not critical for stability. Good candidate for code quality improvement.

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 9, 2026, 9:06 AM UTC

Activity

  1. github-actions commented on Feb 8, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster has assigned this to Copilot!

    I've identified this issue as a good candidate for automated resolution and assigned it to the Copilot agent.

    The Copilot agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    AI generated by Issue Monster

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions