Skip to content

Fix Copilot BYOK target resolution for self-hosted provider URLs - #49464

Merged
pelikhan merged 2 commits into
mainfrom
copilot/aw-fix-daily-byok-ollama-test
Aug 1, 2026
Merged

Fix Copilot BYOK target resolution for self-hosted provider URLs#49464
pelikhan merged 2 commits into
mainfrom
copilot/aw-fix-daily-byok-ollama-test

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

The Daily BYOK Ollama workflow was compiling without a concrete Copilot api-proxy target even though COPILOT_PROVIDER_BASE_URL pointed at a local Ollama endpoint. In AWF, that left Copilot BYOK traffic misrouted and produced repeated 503 failures on /v1/models.

  • Root cause

    • GetCopilotAPITarget only considered:
      • explicit engine.api-target
      • GITHUB_COPILOT_BASE_URL
    • Workflows using a literal self-hosted COPILOT_PROVIDER_BASE_URL had no derived Copilot target, so the generated AWF config omitted apiProxy.targets.copilot.host.
  • Target resolution update

    • Extend Copilot target lookup to fall back to a literal COPILOT_PROVIDER_BASE_URL when no explicit Copilot target is set.
    • Preserve the existing behavior of ignoring GitHub expression values for host extraction.
  • Generated workflow impact

    • Recompile the Daily BYOK Ollama workflow so its embedded AWF config now includes the concrete Copilot target:
      "targets": {
        "copilot": {
          "host": "host.docker.internal:11434"
        }
      }
  • Focused coverage

    • Add coverage for:
      • resolving Copilot target from literal COPILOT_PROVIDER_BASE_URL
      • skipping expression-backed provider URLs
      • emitting the Copilot target into AWF config JSON for BYOK workflows

Example of the new fallback path:

if target := extractAPITargetHost(workflowData, "GITHUB_COPILOT_BASE_URL"); target != "" {
	return target
}

return extractLiteralEngineEnvHost(workflowData, constants.CopilotProviderBaseURL)

Copilot AI linked an issue Aug 1, 2026 that may be closed by this pull request
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix daily BYOK Ollama test failure Fix Copilot BYOK target resolution for self-hosted provider URLs Aug 1, 2026
Copilot AI requested a review from pelikhan August 1, 2026 04:49
@pelikhan
pelikhan marked this pull request as ready for review August 1, 2026 05:29
Copilot AI review requested due to automatic review settings August 1, 2026 05:29

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

Fixes Copilot BYOK routing by deriving the AWF API proxy target from literal provider URLs.

Changes:

  • Adds COPILOT_PROVIDER_BASE_URL as a final target fallback.
  • Covers literal and expression-backed URLs.
  • Recompiles the Ollama workflow with the resolved target.
Show a summary per file
File Description
pkg/workflow/engine_api_targets.go Adds BYOK target resolution.
pkg/workflow/awf_helpers_test.go Tests resolution and AWF configuration.
.github/workflows/daily-byok-ollama-test.lock.yml Includes the Ollama proxy target.

Review details

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (59 additions across 3 files).

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Review: Fix Copilot BYOK target resolution for self-hosted provider URLs

The changes are correct and well-structured. No blocking issues found.

What was reviewed:

  • GetCopilotAPITarget now correctly falls back to COPILOT_PROVIDER_BASE_URL when neither engine.api-target nor GITHUB_COPILOT_BASE_URL is configured
  • extractLiteralEngineEnvHost properly guards against GitHub expression values (${{...}}) to avoid misrouting
  • New tests cover the new fallback path, the expression-skip path, and the BuildAWFConfigJSON integration
  • The lock file diff reflects the expected targets.copilot.host injection

Minor observation (non-blocking): The log message at line 177 (No GITHUB_COPILOT_BASE_URL, deriving Copilot API target from literal COPILOT_PROVIDER_BASE_URL) fires even when COPILOT_PROVIDER_BASE_URL is also absent, adding noise in standard non-BYOK workflows. Consider emitting it only when the env var is actually present.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 32 AIC · ⊞ 5.3K

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧪 Test Quality Sentinel Report

Test Quality Score: 80/100 — Excellent

Analyzed 3 test(s): 3 design, 0 implementation, 0 violation(s).

📊 Metrics (3 tests)
Metric Value
Analyzed 3 (Go: 3, JS: 0)
✅ Design 3 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 2 (67%)
Duplicate clusters 0
Inflation YES (49 test lines vs ~10 prod lines ≈ 4.9:1)
🚨 Violations 0
Test File Classification Issues
TestGetCopilotAPITarget — new row: literal COPILOT_PROVIDER_BASE_URL pkg/workflow/awf_helpers_test.go:957 design_test / behavioral_contract / high_value None
TestGetCopilotAPITarget — new row: empty when COPILOT_PROVIDER_BASE_URL is GitHub expression pkg/workflow/awf_helpers_test.go:969 design_test / behavioral_contract / high_value None
TestBuildAWFConfigJSONIncludesCopilotLiteralBYOKTarget pkg/workflow/awf_helpers_test.go:1003 design_test / behavioral_contract / high_value None

Verdict

passed. 0% implementation tests (threshold: 30%). Build tag present. No mock violations. Score penalized 10 pts for test inflation (49 added test lines vs ~10 production lines), but all 3 tests verify genuine behavioral contracts for the new BYOK self-hosted provider URL resolution.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 43.3 AIC · ⊞ 8.4K ·
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.

✅ Test Quality Sentinel: 80/100. 0% implementation tests (threshold: 30%).

@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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Skills-Based Review

Applied /diagnosing-bugs and /tdd — one observation on test coverage.

Summary

What the PR does well

  • Root cause is clearly identified and addressed at the right layer (GetCopilotAPITarget).
  • The expression-skipping guard in extractLiteralEngineEnvHost prevents misrouting when the URL is a GitHub Actions secret reference — good defensive coding.
  • Three focused tests cover the new fallback path, the expression-skip path, and end-to-end AWF config JSON output.
  • Lock file is recompiled and the embedded AWF config now includes the concrete Copilot target — the fix is visible in the generated artifact.

One gap

The new GetCopilotAPITarget fallback means GetCopilotAllowlistTargets now reaches the same BYOK host via two internal code paths (direct extractLiteralEngineEnvHost call + the new GetCopilotAPITarget fallback). The seen-map deduplication handles this correctly at runtime, but no test exercises that path, so a future refactor could silently introduce duplicates. See the inline comment for a suggested test case.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 42.1 AIC · ⊞ 7K
Comment /matt to run again

// Final fallback: derive from a literal BYOK provider URL so AWF's api-proxy preserves
// non-default hosts and ports for self-hosted OpenAI-compatible backends such as Ollama.
awfHelpersLog.Print("No GITHUB_COPILOT_BASE_URL, deriving Copilot API target from literal COPILOT_PROVIDER_BASE_URL")
return extractLiteralEngineEnvHost(workflowData, constants.CopilotProviderBaseURL)

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.

[/tdd] The new GetCopilotAPITarget fallback causes GetCopilotAllowlistTargets to encounter the BYOK host from two code paths; the deduplication logic is not exercised by the new tests.

Add a case to TestGetCopilotAllowlistTargets that sets only COPILOT_PROVIDER_BASE_URL and asserts the host appears exactly once in the result slice.

@copilot please address this.

@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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Verdict: No blocking issues found

The Copilot BYOK target fallback logic is narrow, safe, and well-tested.

Review notes
  • The new fallback in GetCopilotAPITarget only activates when both engine.api-target and GITHUB_COPILOT_BASE_URL are unset, and it correctly reuses the existing extractAPITargetHost host/port parsing so behavior is consistent with other BYOK env-var handling (OpenAI, Anthropic).
  • GitHub Actions expression values (${{ ... }}) in COPILOT_PROVIDER_BASE_URL are correctly skipped via a strings.Contains(rawValue, "${{") guard in extractLiteralEngineEnvHost, preventing an unresolved expression string from leaking into the generated AWF config as a bogus host.
  • Test coverage is solid: it adds cases for the literal fallback, the expression-skip path, and an integration test (TestBuildAWFConfigJSONIncludesCopilotLiteralBYOKTarget) verifying the target actually appears in the generated JSON.
  • The regenerated daily-byok-ollama-test.lock.yml diff is minimal (2 lines) and matches the expected targets.copilot.host addition for both the main and threat-detection jobs.
  • Ran an independent second pass plus a grumpy-coder sub-agent pass; neither surfaced any correctness, concurrency, security, or maintainability issue within the changed lines.

🔎 Code quality review by PR Code Quality Reviewer · auto · 105.6 AIC · ⊞ 7.8K
Comment /review to run again

@pelikhan
pelikhan merged commit 7ad1e24 into main Aug 1, 2026
83 of 95 checks passed
@pelikhan
pelikhan deleted the copilot/aw-fix-daily-byok-ollama-test branch August 1, 2026 06:21
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.2

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw] Daily BYOK Ollama Test failed

3 participants