Skip to content

Add Copilot pre-flight diagnostic for GHES environments#20975

Merged
lpcox merged 5 commits intomainfrom
claude/add-copilot-pre-flight-diagnostic
Mar 14, 2026
Merged

Add Copilot pre-flight diagnostic for GHES environments#20975
lpcox merged 5 commits intomainfrom
claude/add-copilot-pre-flight-diagnostic

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 14, 2026

This PR adds a pre-flight diagnostic step for GitHub Copilot CLI on GitHub Enterprise Server (GHES) environments to provide clear error messages before execution fails.

Problem Solved

On GHES, Copilot CLI failures are opaque - users get generic errors like "Error loading models: 400 Bad Request" when the actual issue is licensing (403 from token exchange endpoint). This diagnostic provides clear, actionable error messages before Copilot CLI execution.

Changes Made

  • Created copilot_preflight_diagnostic.sh: Shell script that validates COPILOT_GITHUB_TOKEN can exchange for Copilot access by testing ${GITHUB_API_URL}/copilot_internal/v2/token
  • Added pre-flight diagnostic step injection: Modified copilot_engine_execution.go to inject the diagnostic step before Copilot CLI execution
  • Comprehensive unit tests: Added tests in copilot_engine_test.go to validate the pre-flight diagnostic behavior
  • Updated existing tests: Modified multiple test files to account for the new pre-flight step (2 steps instead of 1)

Key Features

Token Exchange Test: Validates that the GitHub token can be exchanged for Copilot access before running the CLI.

Error Detection:

  • HTTP 403 "not licensed" → Clear message to contact GHES admin for licensing
  • HTTP 403 "token type" → Instructions to use fine-grained PAT with Copilot Requests permission
  • HTTP 401 → Token invalid or expired
  • HTTP 404 → GHES version may not support Copilot

GHES-Specific Checks: Validates engine.api-target configuration matches GITHUB_API_URL

Smart Skipping: Diagnostic is skipped when:

  • copilot-requests feature is enabled (uses GitHub Actions token)
  • Custom command is specified in engine configuration

Files Changed

  • actions/setup/sh/copilot_preflight_diagnostic.sh - Pre-flight diagnostic script
  • pkg/workflow/copilot_engine_execution.go - Inject diagnostic step before execution
  • pkg/workflow/copilot_engine_test.go - Comprehensive unit tests
  • Updated multiple test files to expect 2 steps (preflight + execution)

Claude AI and others added 2 commits March 14, 2026 18:27
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@Claude Claude AI assigned Claude and lpcox Mar 14, 2026
@lpcox
Copy link
Collaborator

lpcox commented Mar 14, 2026

@claude[agent] fix the pr title and summary

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@Claude
Copy link
Contributor Author

Claude AI commented Mar 14, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh pr view --json title,body /home/REDACTED/.nvm/bash_completion /home/REDACTED/.nvm/install.sh /home/REDACTED/.nvm/nvm-exec /home/REDACTED/.nvm/nvm.sh /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@Claude Claude AI changed the title Completing task Addressing PR comments Mar 14, 2026
@Claude Claude AI requested a review from lpcox March 14, 2026 19:02
@lpcox
Copy link
Collaborator

lpcox commented Mar 14, 2026

@claude[agent] fix the pr title and summary

@Claude
Copy link
Contributor Author

Claude AI commented Mar 14, 2026

@claude[agent] fix the pr title and summary

I'm unable to update the PR title and description due to GitHub API access restrictions (HTTP 403).

The PR should have:

  • Title: "Add Copilot pre-flight diagnostic for GHES environments"
  • Description: Detailed summary of the pre-flight diagnostic implementation

Could you please update these manually, or grant the necessary API permissions? The commit de9842f has the proper title in its message.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh pr view --json title,body,number (http block)
    • Triggering command: /usr/bin/gh gh pr list --head claude/add-copilot-pre-flight-diagnostic --json number,title,body --limit 1 /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test (http block)
    • Triggering command: `/usr/bin/gh gh pr edit --title Add Copilot pre-flight diagnostic for GHES environments --body ## Summary

This PR adds a pre-flight diagnostic step for GitHub Copilot CLI on GitHub Enterprise Server (GHES) environments to provide clear error messages before execution fails.

Changes

  • Created copilot_preflight_diagnostic.sh script with t /home/REDACTED/.nvm/nvm-exec /home/REDACTED/.nvm/nvm.sh /home/REDACTED/.nvm/package.json /home/REDACTED/.nvm/rename_test.sh /home/REDACTED/.nvm/test conf�� get --local /usr/sbin/git credential.usernsed` (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@Claude Claude AI changed the title Addressing PR comments Add Copilot pre-flight diagnostic for GHES environments Mar 14, 2026
lpcox and others added 2 commits March 14, 2026 12:26
Update all Copilot engine tests to account for the new pre-flight
diagnostic step (2 steps instead of 1). Extract a shared helper
for finding the Copilot execution step, and regenerate WASM golden
files to include the new step.

Fixes:
- TestFirewallArgsInCopilotEngine
- TestFirewallBlockedDomainsInCopilotEngine
- TestFirewallLogLevelInCopilotEngine
- TestChrootModeInAWFContainer
- TestChrootModeEnvFlags
- TestMCPScriptsWithFirewallIncludesHostDockerInternal
- TestEngineAWFEnableApiProxy
- TestWasmGolden_CompileFixtures (golden files)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…0985)

* Initial plan

* fix: correct test conditions for preflight step count checks

Fix two categories of incorrectly written tests introduced with the
Copilot pre-flight diagnostic step:

1. copilot_engine_test.go: Two "skips preflight" sub-tests checked
   `len(steps) != 2` but preflight is intentionally skipped, returning
   only 1 step. Change condition to `!= 1`.

2. engine_agent_import_test.go: Claude and Codex tests expected 2 steps
   (preflight + execution) like Copilot, but those engines only return 1
   execution step. Change to `!= 1` and use `steps[0]`.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review March 14, 2026 21:30
Copilot AI review requested due to automatic review settings March 14, 2026 21:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a Copilot CLI pre-flight diagnostic step (primarily for GHES) to detect token/licensing/config issues early and provide clearer, actionable errors before/alongside Copilot execution.

Changes:

  • Introduces copilot_preflight_diagnostic.sh to validate token exchange against the Copilot internal token endpoint and emit GHES-focused guidance.
  • Updates Copilot engine execution to inject the preflight diagnostic step ahead of the CLI execution step (with skip logic).
  • Updates unit tests and multiple golden/locked workflow fixtures to reflect the additional step.

Reviewed changes

Copilot reviewed 91 out of 91 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
actions/setup/sh/copilot_preflight_diagnostic.sh New shell diagnostic script to validate Copilot token exchange and GHES configuration hints.
pkg/workflow/copilot_engine_execution.go Injects the preflight diagnostic GitHub Actions step before Copilot CLI execution.
pkg/workflow/copilot_engine_test.go Adds/updates tests for preflight injection and skip behavior; updates step-count expectations.
pkg/workflow/enable_api_proxy_test.go Adds a shared helper to assert preflight+execution steps; updates Copilot-related assertions.
pkg/workflow/tools_timeout_test.go Updates to account for preflight step and validate env vars on the execution step.
pkg/workflow/sandbox_mounts_test.go Updates step indexing to account for preflight step in Copilot execution.
pkg/workflow/mcp_scripts_firewall_test.go Updates to use the shared helper and target the execution step after preflight.
pkg/workflow/gh_cli_mount_test.go Updates to use the shared helper and target the execution step after preflight.
pkg/workflow/firewall_log_level_test.go Updates to use the shared helper and target the execution step after preflight.
pkg/workflow/firewall_blocked_domains_test.go Updates to use the shared helper and target the execution step after preflight.
pkg/workflow/firewall_args_test.go Updates to use the shared helper and target the execution step after preflight.
pkg/workflow/engine_agent_import_test.go Updates step-count and step indexing expectations due to preflight insertion.
pkg/workflow/testdata/wasm_golden/TestWasmGolden_CompileFixtures/basic-copilot.golden Golden workflow updated to include the preflight diagnostic step.
pkg/workflow/testdata/wasm_golden/TestWasmGolden_CompileFixtures/smoke-copilot.golden Golden workflow updated to include the preflight diagnostic step.
pkg/workflow/testdata/wasm_golden/TestWasmGolden_CompileFixtures/with-imports.golden Golden workflow updated to include the preflight diagnostic step.
.github/workflows/ace-editor.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/agent-persona-explorer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/bot-detection.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/chroma-issue-indexer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/ci-doctor.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/code-simplifier.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/contribution-check.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/constraint-solving-potd.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/daily-cli-tools-tester.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/daily-firewall-report.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/daily-performance-summary.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/daily-regulatory.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/daily-semgrep-scan.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/daily-team-status.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/dependabot-burner.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/dependabot-go-checker.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/example-permissions-warning.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/firewall.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/functional-pragmatist.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/github-remote-mcp-auth-test.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/glossary-maintainer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/gpclean.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/grumpy-reviewer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/hourly-ci-cleaner.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/issue-monster.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/issue-triage-agent.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/jsweep.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/layout-spec-maintainer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/mcp-inspector.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/mergefest.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/metrics-collector.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/notion-issue-summary.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/org-health-report.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/pdf-summary.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/plan.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/poem-bot.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/portfolio-analyst.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/pr-nitpick-reviewer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/pr-triage-agent.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/python-data-charts.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/q.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/refiner.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/release.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/repo-audit-analyzer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/repo-tree-map.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/repository-quality-improver.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/research.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/security-compliance.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/security-review.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/slide-deck-maintainer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-copilot-arm.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-copilot.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-multi-pr.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-project.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-temporary-id.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-test-tools.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-workflow-call-with-inputs.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/smoke-workflow-call.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/stale-repo-identifier.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/sub-issue-closer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/super-linter.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/technical-doc-writer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/terminal-stylist.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/test-dispatcher.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/test-project-url-default.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/test-workflow.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/tidy.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/ubuntu-image-analyzer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/video-analyzer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/weekly-editors-health-check.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/weekly-issue-summary.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/weekly-safe-outputs-spec-review.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/workflow-generator.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/workflow-health-manager.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/workflow-normalizer.lock.yml Locked workflow updated to include preflight diagnostic step.
.github/workflows/workflow-skill-extractor.lock.yml Locked workflow updated to include preflight diagnostic step.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +490 to +494
// Use COPILOT_GITHUB_TOKEN for the diagnostic
// #nosec G101 -- This is a GitHub Actions expression template, not a hardcoded credential
step = append(step, " COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}")
step = append(step, " GITHUB_SERVER_URL: ${{ github.server_url }}")
step = append(step, " GITHUB_API_URL: ${{ github.api_url }}")
Comment on lines +35 to +38
HTTP_STATUS=$(curl -s -o /tmp/copilot_token_exchange.json -w "%{http_code}" \
-H "Authorization: Bearer ${COPILOT_GITHUB_TOKEN}" \
-H "Accept: application/json" \
"$TOKEN_EXCHANGE_URL" 2>&1 || echo "000")
Comment on lines 304 to 309
if len(steps) == 0 {
t.Fatal("Expected at least one execution step")
}

stepContent := strings.Join(steps[0], "\n")
stepContent := strings.Join(steps[1], "\n")

@pelikhan
Copy link
Contributor

@copilot

  • move copilot preflight steps after the step that validates the presence of agentic engine steps.
  • extend agentic engine interface engine to provide a set of preflight steps to be included, move the copilot steps in the copilot implemementation

@lpcox lpcox merged commit 9079cb1 into main Mar 14, 2026
56 of 57 checks passed
@lpcox lpcox deleted the claude/add-copilot-pre-flight-diagnostic branch March 14, 2026 21:53
Copilot AI requested a review from pelikhan March 14, 2026 21:53
Copilot stopped work on behalf of pelikhan due to an error March 14, 2026 21:53
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.

5 participants