Skip to content

fix(api): provider endpoint mismatches preventing copilot save#511

Open
ibhagwan wants to merge 2 commits intospacedriveapp:mainfrom
ibhagwan:fix/copilot-provider-endpoints
Open

fix(api): provider endpoint mismatches preventing copilot save#511
ibhagwan wants to merge 2 commits intospacedriveapp:mainfrom
ibhagwan:fix/copilot-provider-endpoints

Conversation

@ibhagwan
Copy link
Copy Markdown
Contributor

Fix #415

And remove three endpoint mismatches between frontend and backend caused the GitHub Copilot provider's save, test, and remove buttons to fail with 405 Method Not Allowed. These affected all providers for save.

  • change update_provider annotation from post to put to match frontend
  • fix test button URL from /providers/test to /providers/test-model
  • add github-copilot entry in build_test_llm_config since default_provider_config returns None for providers that require token exchange
  • widen GITHUB_COPILOT_DEFAULT_BASE_URL visibility to pub(crate)
  • add unit test for build_test_llm_config with github-copilot

fix(api): Copilot provider shows as available after remove when env var is set

get_providers fell back to the GITHUB_COPILOT_API_KEY env var when the TOML key was absent, so the provider stayed visible in settings after a remove — the env var can't be unset from a running process.

Only check the TOML key for Copilot status in the config-exists path. The env var fallback remains for the no-config-file case (fresh install).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Ensure GitHub Copilot is registered in test LLM configs when missing; add pre-removal checks that detect copilot API key presence in TOML or environment before deleting provider; expose Copilot base URL at crate scope and add a unit test verifying registration.

Changes

Cohort / File(s) Summary
Provider logic & tests
src/api/providers.rs
In build_test_llm_config insert a github-copilot ProviderConfig when no default exists; in delete_provider add pre-removal detection that resolves llm.<key> from TOML (including secret: / env:) and falls back to checking *_API_KEY env var, returning an error instructing to unset the env var if present; add unit test build_test_llm_config_registers_github_copilot_provider.
Config re-export & visibility
src/config.rs, src/config/providers.rs
Change GITHUB_COPILOT_DEFAULT_BASE_URL visibility to pub(crate) in src/config/providers.rs and add pub(crate) use providers::GITHUB_COPILOT_DEFAULT_BASE_URL; in src/config.rs to expose the constant at crate scope; update test comment to exclude github_copilot_key from shorthand verification.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jamiepine
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: fixing provider endpoint mismatches that prevent Copilot provider save functionality.
Description check ✅ Passed The description provides detailed context about the endpoint mismatches, environment variable fallback issue, and specific code changes related to the changeset.
Linked Issues check ✅ Passed The PR successfully addresses all objectives from issue #415: fixes endpoint mismatches for save/test/remove operations, enables github-copilot in build_test_llm_config, and fixes provider visibility after removal when env var is set.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue #415 requirements: endpoint fixes, provider config registration for github-copilot, visibility adjustments, and removal behavior corrections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vsumner
Copy link
Copy Markdown
Collaborator

vsumner commented Mar 29, 2026

Review Summary

P2 Suggestion (non-blocking)

The Copilot special case in build_test_llm_config duplicates provider construction logic. Consider extracting a shared helper or documenting why default_provider_config can't handle this pattern.

P3 Architecture Note

The sandbox refactoring (deleting detection.rs and 4 test files) appears unrelated to the Copilot endpoint fixes. If this is intentional cleanup, it should ideally be a separate PR for cleaner history.

@ibhagwan
Copy link
Copy Markdown
Contributor Author

P3 Architecture Note
The sandbox refactoring (deleting detection.rs and 4 test files) appears unrelated to the Copilot endpoint fixes. If this is intentional cleanup, it should ideally be a separate PR for cleaner history.

This PR does not modify detection.rs at all, probably a local leftover during the review?

@ibhagwan ibhagwan force-pushed the fix/copilot-provider-endpoints branch 2 times, most recently from 0904a72 to 80a69de Compare April 2, 2026 11:33
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/api/providers.rs`:
- Around line 497-503: The tuple elements for the LLM provider flags are passed
in the wrong order—swap the values so they match the declaration order
(github_copilot then azure) instead of passing azure first and
copilot_configured second; update the tuple construction that currently chains
doc.get("llm")... .is_some_and(|url| !url.trim().is_empty()), copilot_configured
to use github_copilot, azure (or the matching variable names you declared) so
github_copilot aligns with its declared variable and azure aligns with its
declared variable.
- Around line 210-224: The ProviderConfig literal for "github-copilot" is
missing required fields api_version and deployment; update the struct literal in
the providers.insert block to include those fields (matching how other
ProviderConfig instances are created) — e.g. add api_version: None and
deployment: None (or the empty/default values used elsewhere in the codebase) so
the ProviderConfig for GitHub Copilot compiles alongside the existing fields
(api_type, base_url, api_key, name, use_bearer_auth, extra_headers).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc77f7ac-8040-4688-9697-eb7bd4e271f8

📥 Commits

Reviewing files that changed from the base of the PR and between 0904a72 and 80a69de.

📒 Files selected for processing (3)
  • src/api/providers.rs
  • src/config.rs
  • src/config/providers.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/config.rs

@ibhagwan ibhagwan force-pushed the fix/copilot-provider-endpoints branch 3 times, most recently from 6359cee to a4d7f6c Compare April 2, 2026 11:52
@ibhagwan
Copy link
Copy Markdown
Contributor Author

ibhagwan commented Apr 2, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/api/providers.rs (1)

847-856: ⚠️ Potential issue | 🔴 Critical

Backend/frontend HTTP method mismatch will cause save to fail with 405 Method Not Allowed.

The backend annotation now expects PUT, but the frontend updateProvider function (interface/src/api/client.ts:1596-1606) still uses method: "POST":

updateProvider: async (...) => {
    const response = await fetch(`${getApiBase()}/providers`, {
        method: "POST",  // ← Frontend uses POST
        ...
    });
}

This mismatch will break the provider update functionality. Either update the frontend to use PUT in this PR or revert the backend to POST to maintain consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/api/providers.rs` around lines 847 - 856, The route annotation for
Provider updates in the backend (the #[utoipa::path(... put ...)] on the
providers endpoint) expects HTTP PUT, but the frontend function updateProvider
in interface/src/api/client.ts still sends method: "POST", causing 405 errors;
fix by making the client use PUT to match the backend (or alternatively change
the backend annotation back to POST), i.e., update the request method in
updateProvider to "PUT" so it aligns with the utoipa #[put] path for the
/providers endpoint.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/api/providers.rs`:
- Around line 847-856: The route annotation for Provider updates in the backend
(the #[utoipa::path(... put ...)] on the providers endpoint) expects HTTP PUT,
but the frontend function updateProvider in interface/src/api/client.ts still
sends method: "POST", causing 405 errors; fix by making the client use PUT to
match the backend (or alternatively change the backend annotation back to POST),
i.e., update the request method in updateProvider to "PUT" so it aligns with the
utoipa #[put] path for the /providers endpoint.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: de4633a5-6c01-49e6-855e-3d5f06ae9d1d

📥 Commits

Reviewing files that changed from the base of the PR and between 5c85557 and a4d7f6c.

📒 Files selected for processing (3)
  • src/api/providers.rs
  • src/config.rs
  • src/config/providers.rs

… and remove

Fix spacedriveapp#415

Three endpoint mismatches between frontend and backend caused the
GitHub Copilot provider's save, test, and remove buttons to fail
with 405 Method Not Allowed. These affected all providers for save.

- change update_provider annotation from post to put to match frontend
- fix test button URL from /providers/test to /providers/test-model
- add github-copilot entry in build_test_llm_config since
  default_provider_config returns None for providers that require
  token exchange
- widen GITHUB_COPILOT_DEFAULT_BASE_URL visibility to pub(crate)
- add unit test for build_test_llm_config with github-copilot

fix(api): Copilot provider shows as available after remove when env var is set

get_providers fell back to the GITHUB_COPILOT_API_KEY env var when the
TOML key was absent, so the provider stayed visible in settings after
a remove — the env var can't be unset from a running process.

Only check the TOML key for Copilot status in the config-exists path.
The env var fallback remains for the no-config-file case (fresh install).
@ibhagwan ibhagwan force-pushed the fix/copilot-provider-endpoints branch from a4d7f6c to 9c40bf2 Compare April 2, 2026 12:32
@ibhagwan
Copy link
Copy Markdown
Contributor Author

ibhagwan commented Apr 2, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ibhagwan
Copy link
Copy Markdown
Contributor Author

ibhagwan commented Apr 2, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/api/providers.rs (1)

210-226: Consider centralizing Copilot provider bootstrap config.

This literal can drift from other Copilot config construction paths. A small shared helper for the common fields (api_type, name, auth mode, default base URL) would reduce divergence risk over time.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/api/providers.rs` around lines 210 - 226, The GitHub Copilot provider
construction in the providers.rs branch (provider == "github-copilot")
duplicates common fields and may drift; extract a shared helper (e.g., a
function named make_copilot_provider_config or an associated constructor like
ProviderConfig::copilot_default) that returns a ProviderConfig populated with
the common values (api_type = ApiType::OpenAiChatCompletions, base_url =
GITHUB_COPILOT_DEFAULT_BASE_URL, name = "GitHub Copilot", use_bearer_auth =
true, and other defaults), then replace the inline ProviderConfig creation here
to call that helper and only override instance-specific fields such as api_key
(set to credential) and any api_version/deployment if needed; ensure
LlmManager::get_copilot_token usage remains compatible with the new helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/api/providers.rs`:
- Around line 1624-1637: The current env-var removal check only looks for a
single env_var computed as env_var = format!("{}_API_KEY",
provider.to_uppercase().replace("-", "_")) and sets env_configured accordingly;
for the "ollama" provider you must also consider OLLAMA_BASE_URL, otherwise the
handler can report removal while Ollama remains configured. Update the logic
around env_var and env_configured (and the early return that constructs
ProviderUpdateResponse) to check a list of environment variables: always check
the computed "<PROVIDER>_API_KEY", and if provider == "ollama" also check
"OLLAMA_BASE_URL"; set env_configured to true if any of these are
present/non-empty, and update the response message to mention all relevant env
var names when returning early.

---

Nitpick comments:
In `@src/api/providers.rs`:
- Around line 210-226: The GitHub Copilot provider construction in the
providers.rs branch (provider == "github-copilot") duplicates common fields and
may drift; extract a shared helper (e.g., a function named
make_copilot_provider_config or an associated constructor like
ProviderConfig::copilot_default) that returns a ProviderConfig populated with
the common values (api_type = ApiType::OpenAiChatCompletions, base_url =
GITHUB_COPILOT_DEFAULT_BASE_URL, name = "GitHub Copilot", use_bearer_auth =
true, and other defaults), then replace the inline ProviderConfig creation here
to call that helper and only override instance-specific fields such as api_key
(set to credential) and any api_version/deployment if needed; ensure
LlmManager::get_copilot_token usage remains compatible with the new helper.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ec80f32-dc5d-4249-8619-22972a087b2e

📥 Commits

Reviewing files that changed from the base of the PR and between 5c85557 and ee7d255.

📒 Files selected for processing (3)
  • src/api/providers.rs
  • src/config.rs
  • src/config/providers.rs

@ibhagwan ibhagwan force-pushed the fix/copilot-provider-endpoints branch 5 times, most recently from 7838f0d to 0a5ea4f Compare April 2, 2026 15:54
…iders

- Change Copilot from TOML-only check to has_value() pattern, consistent with
  all other providers. Now env var GITHUB_COPILOT_API_KEY works like other
  provider env vars in get_providers().

- Add helpful error message in delete_provider() when attempting to remove
  a provider that is only configured via environment variable. The message
  explains which env var to unset and that a restart is required.
  For Ollama, checks both OLLAMA_BASE_URL and OLLAMA_API_KEY env vars.

- Add comment in test explaining why github_copilot_key is excluded from
  all_shorthand_keys_register_providers_via_toml test (uses token exchange,
  not standard shorthand registration).

- Extract copilot_default_provider_config() helper to reduce duplication in
  Copilot provider construction.
@ibhagwan ibhagwan force-pushed the fix/copilot-provider-endpoints branch from 0a5ea4f to 36ace52 Compare April 2, 2026 16:07
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.

Github Copilot provider not working

2 participants