Skip to content

Add no-op early exit guard to Hourly CI Cleaner#7425

Merged
pelikhan merged 4 commits intomainfrom
copilot/add-no-op-exit-guard
Dec 23, 2025
Merged

Add no-op early exit guard to Hourly CI Cleaner#7425
pelikhan merged 4 commits intomainfrom
copilot/add-no-op-exit-guard

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

Prevents unnecessary token consumption when CI is passing on main. The workflow was executing the full agent on every scheduled run, even when no fixes were needed.

Changes

Created pre-activation job for CI status check

  • Added check_ci_status job that runs before the agent
  • Queries last CI workflow run on main branch
  • Outputs ci_needs_fix, ci_status, and ci_run_id for use by agent job

Added job-level conditional to agent

  • Agent job now depends on check_ci_status (in addition to activation)
  • Agent job has if: needs.check_ci_status.outputs.ci_needs_fix == 'true' condition
  • Agent job never starts when CI is passing (true early exit)

Simplified agent prompt

  • Removed CI status check instructions from prompt
  • Agent only runs when CI is failing, so no need to check status
  • Agent receives CI status and run ID from job outputs

Behavior

jobs:
  check_ci_status:
    # Queries CI status and sets outputs
    outputs:
      ci_needs_fix: true/false
      ci_status: success/failure
      ci_run_id: <run_id>

  agent:
    needs: [activation, check_ci_status]
    if: needs.check_ci_status.outputs.ci_needs_fix == 'true'
    # Only runs when CI needs fixing

When CI is passing:

  • check_ci_status job runs and sets ci_needs_fix=false
  • Agent job skipped entirely (never starts)
  • Tokens: ~0 for agent execution

When CI is failing:

  • check_ci_status job runs and sets ci_needs_fix=true
  • Agent job executes normally
  • Agent fixes issues and creates PR
  • Tokens: Normal consumption

Combined with the 2-3 hour schedule reduction (#7410), this eliminates wasteful execution while maintaining CI health.

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Add no-op early exit guard to Hourly CI Cleaner</issue_title>
<issue_description>## Objective

Add an early exit mechanism to the Hourly CI Cleaner workflow that skips execution when there is no work to do, preventing unnecessary token consumption.

Context

The Copilot Token Report (discussion #7407) recommends adding a no-op exit guard to the Hourly CI Cleaner. This will prevent the workflow from consuming tokens when there are no CI runs to clean up.

Approach

  1. Add a preliminary step that checks if there are CI runs to clean
  2. Use GitHub API to query for qualifying runs
  3. If no runs found, exit early with success status
  4. Document the no-op behavior in workflow comments

Implementation Strategy

Add an early check before the main Copilot agent execution:

steps:
  - name: Check for CI runs to clean
    id: check
    run: |
      # Query for qualifying CI runs
      count=$(gh api ... | jq 'length')
      echo "count=$count" >> $GITHUB_OUTPUT
      
  - name: Run CI Cleaner
    if: steps.check.outputs.count > 0
    # ... existing Copilot agent execution

Files to Modify

  • Hourly CI Cleaner workflow file (identified in previous issue)

Acceptance Criteria

  • Workflow checks for work before executing
  • Early exit occurs when no CI runs need cleaning
  • Token consumption drops for no-op runs
  • Workflow still cleans CI runs when work exists
  • Logs clearly indicate no-op vs. execution runs

Expected Impact

AI generated by Plan Command for discussion #7407

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 23, 2025 19:09
- Remove exit 1 from CI check step to allow graceful continuation
- Add conditional execution (if: env.CI_NEEDS_FIX == 'true') to all setup steps
- Update workflow description to mention early exit behavior
- Add comments explaining early exit guard mechanism
- Update agent prompt to check CI status and exit early if passing
- Prevents token consumption when CI is healthy

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
… passing

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Add no-op early exit guard to Hourly CI Cleaner Add no-op early exit guard to Hourly CI Cleaner Dec 23, 2025
Copilot AI requested a review from mnkiefer December 23, 2025 19:16
@@ -31,6 +31,8 @@ sandbox:
- "/usr/local/lib/node_modules:/usr/local/lib/node_modules:ro"
- "/opt/hostedtoolcache/go:/opt/hostedtoolcache/go:ro"
steps:
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot move early exit check in pre_activation job

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 302538c. Moved the CI check to a check_ci_status job that runs before the agent. The agent job now has a job-level if: condition and only executes when ci_needs_fix == 'true', providing a true early exit without starting the agent container.

- Create check_ci_status job that runs before agent
- Add job-level if condition to skip agent when CI is passing
- Remove conditional checks from individual setup steps
- Update prompt to reference check_ci_status outputs
- Agent job now depends on check_ci_status and only runs when ci_needs_fix=true

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan December 23, 2025 20:06
@pelikhan pelikhan marked this pull request as ready for review December 23, 2025 21:00
@pelikhan pelikhan merged commit 5ce3ba8 into main Dec 23, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/add-no-op-exit-guard branch December 23, 2025 21:00
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.

[plan] Add no-op early exit guard to Hourly CI Cleaner

3 participants