Skip to content

refactor(workflow): split compiler_yaml_main_job.go into focused modules#44651

Merged
pelikhan merged 4 commits into
mainfrom
copilot/file-diet-split-compiler-yaml
Jul 10, 2026
Merged

refactor(workflow): split compiler_yaml_main_job.go into focused modules#44651
pelikhan merged 4 commits into
mainfrom
copilot/file-diet-split-compiler-yaml

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

pkg/workflow/compiler_yaml_main_job.go had grown to 1265 lines across 23 methods spanning 5 distinct compilation phases, making targeted edits and navigation expensive.

Changes

  • compiler_yaml_main_job.go — reduced to a 42-line phase orchestrator calling the four phase functions below
  • compiler_yaml_checkout.go (new, 302 lines) — Phase 1: OTLP masking, pre-steps, workspace checkout, dev-mode CLI build, repository import checkouts, legacy agent import checkout, merge-.github-folder step
  • compiler_yaml_runtime_setup.go (new, 431 lines) — Phase 2: runtime detection, ARC/DinD tool-cache redirect, activation artifact download, comment-memory setup, custom step emission/sanitization
  • compiler_yaml_post_agent.go (new, 267 lines) — Phase 5: artifact path accumulation, step-summary generation, post-agent upload and cleanup
  • compiler_yaml_ai_execution.go (extended, 497 lines) — absorbs Phases 3 & 4: generateEngineInstallAndPreAgentSteps and generateAgentRunSteps

All files stay in package workflow; no imports rewired, no logic changed — pure mechanical split.

Splits the 1265-line compiler_yaml_main_job.go into smaller, focused files:

- compiler_yaml_main_job.go: reduced to 42-line orchestrator only
- compiler_yaml_checkout.go (new, 302 lines): Phase 1 – OTLP masking, pre-steps,
  workspace checkout, dev-mode CLI build, repository import checkouts, legacy agent
  import checkout, and merge-remote-.github-folder step
- compiler_yaml_runtime_setup.go (new, 431 lines): Phase 2 – runtime detection,
  ARC/DinD adapters, activation artifact download, comment-memory setup, custom step
  emission and sanitization
- compiler_yaml_post_agent.go (new, 267 lines): Phase 5 – artifact path accumulation,
  step-summary generation, post-agent upload and cleanup
- compiler_yaml_ai_execution.go (extended, 497 lines): Phases 3 & 4 –
  generateEngineInstallAndPreAgentSteps and generateAgentRunSteps added

All files remain in package workflow; no imports changed; all tests pass.

Closes #44549

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor compiler_yaml_main_job.go into focused modules refactor(workflow): split compiler_yaml_main_job.go into focused modules Jul 10, 2026
Copilot AI requested a review from pelikhan July 10, 2026 05:23
@pelikhan
pelikhan marked this pull request as ready for review July 10, 2026 05:32
Copilot AI review requested due to automatic review settings July 10, 2026 05:32
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the workflow YAML compiler’s main agent-job generation by splitting the previously large compiler_yaml_main_job.go into phase-focused modules, keeping behavior the same while making the code easier to navigate and modify.

Changes:

  • Replaced the monolithic main-job generator with a small phase orchestrator.
  • Extracted checkout-related compilation logic into compiler_yaml_checkout.go.
  • Extracted runtime/workspace setup and post-agent collection/upload logic into dedicated modules, and moved pre-agent/agent-run logic into compiler_yaml_ai_execution.go.
Show a summary per file
File Description
pkg/workflow/compiler_yaml_main_job.go Reduced to a phase orchestrator that delegates to extracted phase functions.
pkg/workflow/compiler_yaml_checkout.go New module containing checkout/import/merge steps generation.
pkg/workflow/compiler_yaml_runtime_setup.go New module for runtime detection/setup, activation artifact + memory prep, and custom step emission/sanitization.
pkg/workflow/compiler_yaml_ai_execution.go Extended to include pre-agent install/setup and agent execution step generation previously in main job.
pkg/workflow/compiler_yaml_post_agent.go New module for artifact path collection, step-summary generation, and post-agent upload/cleanup orchestration.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread pkg/workflow/compiler_yaml_checkout.go Outdated
Comment on lines +217 to +219
// generateLegacyAgentImportCheckout generates a checkout step for legacy agent imports
// Legacy format: owner/repo/path/to/file.md@ref
// This checks out the entire repository (not just .github folder) since the file could be anywhere

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: Pure Mechanical Refactor ✅

This PR is a clean structural split of compiler_yaml_main_job.go into five focused modules. All 22 functions were moved verbatim with no logic changes.

Verification:

  • Every removed function matches an added function in the new files — no omissions or additions
  • Imports correctly redistributed: os, encoding/json, console, constants moved to the files that use them
  • compiler_yaml_main_job.go retains only strings import, which is correct
  • All new files use package workflow — no package boundary issues
  • No behavioral changes detected in any changed line

No issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 30.4 AIC · ⌖ 5.35 AIC · ⊞ 4.8K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /codebase-design — the split is a clean improvement, with one naming observation worth addressing.

📋 Key Themes & Highlights

Issue Found

  • File name / content mismatch: compiler_yaml_ai_execution.go hosts both Phase 3 (engine setup: git config, MCP, engine installation) and Phase 4 (actual agent run). The other extracted files each map to one logical phase by name; this one deviates from that pattern. See the inline comment for options.

Positive Highlights

  • generateMainJobSteps is now a crisp 42-line phase orchestrator — easy to audit at a glance
  • Phase comment blocks in the orchestrator clearly document the responsibility boundary of each call
  • Strict package workflow containment — no import rewiring, zero risk of API surface changes
  • The ordering comments in generateEngineInstallAndPreAgentSteps explain why each step must precede the next (e.g. base-branch restore before pre-agent steps, secret redaction before upload)
  • sanitizeAndWarnCustomSteps and addCustomSteps* are cohesively grouped in compiler_yaml_runtime_setup.go alongside the step emission logic

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 45.1 AIC · ⌖ 4.49 AIC · ⊞ 6.6K
Comment /matt to run again

// generateActivationArtifactAndCommentMemorySteps) so that user steps: can access prior
// comment-memory state.
// It returns the resolved CodingAgentEngine for use in subsequent phases.
func (c *Compiler) generateEngineInstallAndPreAgentSteps(yaml *strings.Builder, data *WorkflowData, needsGitConfig bool) (CodingAgentEngine, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/codebase-design] Phase 3 (generateEngineInstallAndPreAgentSteps) lives in ai_execution.go, but it covers git credentials, MCP setup, and engine installation — none of which is AI execution. A future reader navigating to 'AI execution' code will land here and need to mentally separate the two phases.

💡 Suggested rename or split

Consider either:

  1. Renaming the file to compiler_yaml_engine_setup_and_execution.go to reflect that it covers both setup and run phases.
  2. Or, since the PR description calls them distinct phases, extract Phase 3 into compiler_yaml_engine_setup.go and keep only generateAgentRunSteps in compiler_yaml_ai_execution.go.

Option 1 is the lower-effort fix and is consistent with the file-per-phase pattern established by the other new files.

@copilot please address this.

…o into phase modules

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (1,243 new lines in pkg/workflow/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/44651-split-compiler-yaml-main-job-into-phase-modules.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff
  2. Complete the missing sections — add context the AI could not infer, refine the decision rationale, and list real alternatives you considered
  3. Commit the finalized ADR to docs/adr/ on your branch
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-44651: Split compiler_yaml_main_job.go into Phase-Focused Modules

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 0042-use-postgresql.md for PR #42).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · 51.7 AIC · ⌖ 12.7 AIC · ⊞ 8.5K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: Pure mechanical split — logic preserved, but the file boundaries leak

The refactor successfully breaks a 1265-line monolith into four focused files. The compiler builds cleanly and all tests pass. Phase ordering and variable scoping in the orchestrator are correct.

One security-adjacent concern and two cohesion issues survive adjudication:

📋 Findings summary

High — security-adjacent (non-blocking, pre-existing, but worsened by split)

  • compiler_yaml_ai_execution.go:481 — secret redaction snapshot covers only Phase 1–4 YAML; Phase 5 steps are outside the scan window. This was already true in the monolith, but the split distributes phases across files with no in-file warning, making it easy for a future contributor to add a ${{ secrets.* }} reference in compiler_yaml_post_agent.go without realising it will never be scanned.

Medium — maintainability

  • compiler_yaml_ai_execution.go:139isOTLPEnabled should live in observability_otlp.go with isOTLPHeadersPresent/isOTLPAttributesPresent.

Low — maintainability

  • compiler_yaml_ai_execution.go:172generateAgentOutputPlaceholderStep has its sole call site in Phase 5 but is defined in the Phase 4 file.

None of these are regressions introduced by new logic — they are either pre-existing hazards made less visible by the split, or under-grouping of helpers. Recommend addressing the redaction scope concern (at minimum with a clear doc comment) before this lands, so future Phase 5 contributors are not silently in a blind spot.

🔎 Code quality review by PR Code Quality Reviewer · 172.6 AIC · ⌖ 4.81 AIC · ⊞ 5.4K
Comment /review to run again

Comments that could not be inline-anchored

pkg/workflow/compiler_yaml_ai_execution.go:481

Secret redaction snapshot excludes all Phase 5 YAML — any secrets first referenced in post-agent steps are never scanned by the redactor.

<details>
<summary>💡 Details</summary>

generateSecretRedactionStep at line 481 receives yaml.String() as a snapshot of the entire YAML output at the end of Phase 4. generatePostAgentCollectionAndUpload (Phase 5) then appends more YAML after this call — any ${{ secrets.* }} expressions that appear only in Phase 5 steps (generatePostSteps

pkg/workflow/compiler_yaml_ai_execution.go:139

isOTLPEnabled is stranded in the AI execution file while its sibling helpers live in observability_otlp.go, creating a hidden cross-file dependency for post-agent code.

<details>
<summary>💡 Details</summary>

isOTLPEnabled is defined here at line 139, but its two closest relatives — isOTLPHeadersPresent (line 281 of observability_otlp.go) and isOTLPAttributesPresent (line 317 of observability_otlp.go) — already live in the OTLP observability file. The function is called from…

pkg/workflow/compiler_yaml_ai_execution.go:172

generateAgentOutputPlaceholderStep is defined here (Phase 4 file) but its only call site is in compiler_yaml_post_agent.go (Phase 5), making navigation unnecessarily confusing.

<details>
<summary>💡 Details</summary>

This function has a single caller: compiler_yaml_post_agent.go line 195 (inside generatePostAgentCollectionAndUpload). Defining it in the AI execution file means a maintainer reading Phase 5 code must look in the wrong file to understand or modify this step. Move it t…

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

pr-sous-chef
@copilot please run the pr-finisher skill, address the latest review feedback on the module split (including the phase/file-boundary issues and the redaction-scope warning), complete the ADR linked by the design gate, update the PR body to reference it, and rerun checks once the branch is up to date.

Run: https://github.com/github/gh-aw/actions/runs/29072075004

Generated by 👨‍🍳 PR Sous Chef · 10.3 AIC · ⌖ 7.41 AIC · ⊞ 7.1K ·
Comment /souschef to run again

…entImportCheckout

The previous comment incorrectly described:
- The accepted format as 'owner/repo/path/to/file.md@ref' — specs with
  extra path segments are rejected by parseRepositoryImportSpec.
- The checkout scope as 'entire repository' — only .github/ is checked
  out via sparse-checkout.

Update the comment to match actual parser behavior and step output.

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

pr-sous-chef
@copilot please run the pr-finisher skill, address the latest review feedback on the module split (including the phase/file-boundary issues and the redaction-scope warning), complete ...

Addressed the review feedback on the doc comment at compiler_yaml_checkout.go:217-219. The comment now correctly reflects:

  • The accepted format (owner/repo@ref or owner/repo) — specs with extra path segments are rejected by parseRepositoryImportSpec
  • That only .github/ is checked out via sparse-checkout, not the entire repository

Fixed in commit fix(compiler_yaml_checkout): correct doc comment for generateLegacyAgentImportCheckout. Local validation (make fmt, make lint, make test-unit) all pass.

Copilot AI requested a review from gh-aw-bot July 10, 2026 06:03
@pelikhan
pelikhan merged commit a29130b into main Jul 10, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/file-diet-split-compiler-yaml branch July 10, 2026 06:49
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.8

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.

[file-diet] File Diet: Split pkg/workflow/compiler_yaml_main_job.go (1265 lines) into focused modules

4 participants