Skip to content

refactor(compile): reduce complexity of build_agent_job in agentic_pipeline.rs - #2272

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-build-agent-job-c935145ca4b83f42
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-build-agent-job-c935145ca4b83f42

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

What was complex

build_agent_job in src/compile/agentic_pipeline.rs was flagged by clippy::too_many_lines at 160/100 lines. It was a single monolithic function assembling every step of the Agent job inline: checkouts, engine/compiler install, integrity check, MCPG/ado-proxy startup, create-pull-request diff-base prep, GitHub App/provider token minting, the agent run itself, token revocation, safe-output collection/summary, MCPG/ado-proxy teardown, post-steps, log copy, and artifact publish — all in one body, making it hard to follow and to test each phase in isolation.

What changed

Extracted eight well-named helper functions, each owning one logically distinct phase, with their original doc comments preserved and attached to the new function:

  • push_agent_checkout_steps — checkout: self + additional named repo checkouts.
  • push_agent_install_and_prepare_steps — read token, engine install, compiler download, integrity check, MCPG config, tooling, prompt, Docker install, AWF download, image pre-pull, extension/user steps:.
  • push_agent_mcp_startup_steps — AWF path step, Azure WIF refresh sidecars, ado-proxy startup, MCPG startup, topology-peer liveness check, debug-only MCP backend check. Returns whether ado-proxy is enabled so later steps can gate on it.
  • push_agent_create_pr_base_prep_steps — create-pull-request diff-base fetch/deepen steps (local + cross-org repos).
  • push_agent_run_steps — GitHub App / external provider token minting immediately before, plus the actual AWF-sandboxed agent run.
  • push_agent_collect_and_stop_steps — GitHub App token revocation, safe-output collection + summary rendering, MCPG/WIF/ado-proxy teardown in reverse start order.
  • push_agent_finalize_steps — user post_steps:, log copy, and the agent_outputs_$(Build.BuildId) artifact publish.

build_agent_job itself now reads as a short, linear sequence of calls to these helpers plus job/variable/condition assembly.

No behavior change: the same steps are emitted in the same order under the same conditions — this is a pure extraction, not a logic change.

Before/after complexity

  • Before: clippy::too_many_lines reported build_agent_job at 160/100 lines.
  • After: build_agent_job no longer appears in the clippy::too_many_lines violation list for this file (confirmed via cargo clippy --all-targets --all-features --message-format=json -- -W clippy::too_many_lines).

Verification

  • cargo build --bin ado-aw — succeeds.
  • cargo test — full suite, 3406+ tests pass, 0 failed, including all 79 tests in compile::agentic_pipeline.
  • cargo clippy --all-targets --all-features — clean, no warnings.
  • Only src/compile/agentic_pipeline.rs is touched. (Skipped running a project-wide cargo fmt/rustfmt pass after discovering the installed rustfmt 1.9.0 reformats large swaths of unrelated, already-committed code across 79 files; the one new function's line-wrap was fixed manually to stay within the repo's existing style.)

Note on duplicate-avoidance

Before selecting a target, I checked for existing open PRs addressing other high-ranking too_many_lines candidates and found two already in flight: #2267 (build_safeoutputs_job) and #2243 (check_pipeline). Both were skipped to avoid duplicate work; build_agent_job was the next-largest untouched, non-duplicated candidate.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com
  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · auto · 190.9 AIC · ⌖ 6.41 AIC · ⊞ 11.1K · ◷

…peline.rs

build_agent_job was flagged by clippy::too_many_lines at 160/100 lines.
It was a single monolithic function assembling every step of the Agent
job inline: checkouts, engine/compiler install, MCPG/ado-proxy startup,
create-pull-request base prep, token minting, the agent run itself,
teardown, and artifact publish.

Extracted eight well-named helper functions, each owning one logically
distinct phase, with original doc comments preserved and attached to
the new function:

- push_agent_checkout_steps — checkout: self + additional repo checkouts.
- push_agent_install_and_prepare_steps — read token, engine install,
  compiler download, integrity check, MCPG config, tooling, prompt,
  Docker install, AWF download, image pre-pull, extension/user steps.
- push_agent_mcp_startup_steps — AWF path step, Azure WIF refresh
  sidecars, ado-proxy startup, MCPG startup, topology-peer check,
  debug-only backend check. Returns whether ado-proxy is enabled.
- push_agent_create_pr_base_prep_steps — create-pull-request diff-base
  fetch/deepen steps.
- push_agent_run_steps — GitHub App/provider token minting plus the
  actual AWF-sandboxed agent run.
- push_agent_collect_and_stop_steps — token revocation, safe-output
  collection/summary, MCPG/WIF/ado-proxy teardown.
- push_agent_finalize_steps — post_steps, log copy, artifact publish.

build_agent_job itself now reads as a short, linear sequence of calls
to these helpers plus job/variable/condition assembly.

No behavior change: identical steps are emitted in identical order
under identical conditions — this is a pure extraction.

Before/after: clippy::too_many_lines reported build_agent_job at
160/100 lines; it no longer appears in the too_many_lines violation
list for this file.

Verification:
- cargo build --bin ado-aw — succeeds.
- cargo test — full suite, 3406+ tests pass, 0 failed (incl. all 79
  tests in compile::agentic_pipeline).
- cargo clippy --all-targets --all-features — clean.
- Only src/compile/agentic_pipeline.rs is touched.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

This branch has not been deployed

No deployments
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.

0 participants