Skip to content

fix: skip --model CLI startup arg when BYOK provider is configured (#305)#306

Merged
github-actions[bot] merged 3 commits into
mainfrom
spboyer/fix-byok-startup-model
Jun 1, 2026
Merged

fix: skip --model CLI startup arg when BYOK provider is configured (#305)#306
github-actions[bot] merged 3 commits into
mainfrom
spboyer/fix-byok-startup-model

Conversation

@spboyer

@spboyer spboyer commented Jun 1, 2026

Copy link
Copy Markdown
Member

Closes #305

Problem

PR #263 added --model <defaultModelID> to copilot.ClientOptions.CLIArgs
so the embedded Copilot CLI honors the eval-configured model. However, the
Copilot CLI validates that startup --model against the GitHub Copilot
catalog before the per-session ProviderConfig (from PR #240) is
applied. For BYOK / custom provider model IDs that are not in the Copilot
catalog (e.g. minimax-m2.7), startup fails with:

failed to create session: failed to create session: JSON-RPC Error -32603:
Request session.create failed with message: Model "minimax-m2.7" is not available.

even though the same model works fine when supplied as
SessionConfig.Model with SessionConfig.Provider.

Fix

Suppress the startup --model arg whenever providerFromEnv() reports
an enabled custom provider. SessionConfig.Model + SessionConfig.Provider
are still passed per session via Execute, so the SDK selects the right
model against the custom provider without pre-validating against the
GitHub catalog. Normal GitHub Copilot models retain the #263 startup
override behavior.

defaultModelID BYOK env set CLIArgs
"" no []
"claude-..." no ["--model","claude-..."]
"minimax-..." yes []
"" yes []

Changes

  • internal/execution/copilot.go — compute providerFromEnv() once
    before cliArgs, extend modelCLIArgs to accept a customProvider bool
    and skip --model when true. Reuse the same provider for
    engine.provider (avoids reading env vars twice).
  • internal/execution/copilot_engine_test.go — adds
    TestCopilotEngineBuilder_CLIArgsEmptyWhenCustomProvider as the
    regression test for BYOK provider models fail after startup --model is passed to Copilot CLI #305. Hardens the existing two CLIArgs tests by
    explicitly clearing all COPILOT_* BYOK env vars so they stay
    deterministic regardless of the surrounding shell.

Validation

  • go test ./... -count=1 — all packages pass
  • go vet ./... — clean
  • make lint — golangci-lint not installed locally; CI will run it

)

PR #263 added --model <defaultModelID> to copilot.ClientOptions.CLIArgs so
the embedded Copilot CLI honors the eval-configured model. However, the
CLI validates that startup --model against the GitHub Copilot catalog
BEFORE the per-session ProviderConfig from #240 is applied. For BYOK /
custom provider model IDs that are not in the Copilot catalog (e.g.
minimax-m2.7), startup fails with 'Model "..." is not available'.

Suppress the startup --model arg whenever providerFromEnv() reports an
enabled custom provider. SessionConfig.Model + SessionConfig.Provider are
still passed per session via Execute, so the SDK selects the right model
against the custom provider without pre-validating against the GitHub
catalog. Normal GitHub Copilot models retain the #263 behavior.

Adds a regression test covering the BYOK + non-empty defaultModelID
case, and hardens the existing CLIArgs tests against environments that
already have COPILOT_BASE_URL set.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 1, 2026 17:02
@github-actions github-actions Bot enabled auto-merge (squash) June 1, 2026 17:03

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

This PR fixes a regression where BYOK/custom provider model IDs (not present in the GitHub Copilot catalog) cause the embedded Copilot CLI to fail at startup due to an early --model validation step, even though the same model works when applied per-session via SessionConfig + ProviderConfig.

Changes:

  • Compute providerFromEnv() once during engine construction and reuse it for both engine.provider and startup CLI args.
  • Extend modelCLIArgs to skip startup --model whenever a custom/BYOK provider is enabled, avoiding pre-session catalog validation failures.
  • Add a regression test ensuring CLIArgs is empty when a custom provider is configured, and harden existing CLIArgs tests by clearing provider-related env vars.
Show a summary per file
File Description
internal/execution/copilot.go Skips startup --model when a custom provider is enabled; reuses a single providerFromEnv() result.
internal/execution/copilot_engine_test.go Adds regression coverage for BYOK startup behavior and makes CLIArgs tests deterministic wrt env vars.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread internal/execution/copilot_engine_test.go
spboyer and others added 2 commits June 1, 2026 13:21
…derEnv

Replace t.Setenv(name, "") with os.Unsetenv + t.Cleanup so the helper
actually removes variables from the environment rather than setting them
to empty strings. This matches the comment ("unsets") and avoids any
potential confusion for future readers.

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

Satisfies errcheck in golangci-lint v2.10.1; these calls don't realistically
fail in tests and t.Cleanup ensures restoration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 1, 2026 17: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.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new

@github-actions github-actions Bot merged commit 818d7e8 into main Jun 1, 2026
8 checks passed
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.

BYOK provider models fail after startup --model is passed to Copilot CLI

3 participants