fix(providers): detect Anthropic OAuth credentials in provider status#591
fix(providers): detect Anthropic OAuth credentials in provider status#591marcmantei wants to merge 1 commit into
Conversation
The get_providers() endpoint only checks for ANTHROPIC_API_KEY env var or config file key to determine if Anthropic is available. It does not check for anthropic_oauth.json, causing the dashboard to report Anthropic as "not configured" for users authenticating via OAuth (Claude Pro/Max subscription). This mirrors the existing pattern already used for OpenAI OAuth detection via openai_oauth_configured. Minimal alternative to spacedriveapp#430. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
WalkthroughThe change updates Anthropic provider availability detection in ChangesAnthropic OAuth Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
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)
1575-1616:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
delete_provider("anthropic")doesn't remove the OAuth credentials file — provider stays "configured" after deletion.Now that
get_providersreturnsanthropic: truewheneveranthropic_oauth.jsonexists (line 377), a user who authenticates via OAuth and then removes the Anthropic provider through the Settings UI will find the provider is still shown as configured. The generic TOML-key removal path (lines 1600–1604) only removesanthropic_keyfromconfig.toml; it never touches the OAuth credentials file on disk.The fix mirrors the existing "openai-chatgpt" branch (lines 1498–1514): handle
"anthropic"specially before the generic path, remove the credentials file, and clear in-memory credentials if thellm_managerexposes a corresponding method.🐛 Proposed fix
if provider == "openai-chatgpt" { // ... existing block ... } + if provider == "anthropic" { + let instance_dir = (**state.instance_dir.load()).clone(); + let cred_path = crate::auth::credentials_path(&instance_dir); + if cred_path.exists() { + tokio::fs::remove_file(&cred_path).await.map_err(|error| { + tracing::error!(%error, path = %cred_path.display(), "failed to remove Anthropic OAuth credentials"); + StatusCode::INTERNAL_SERVER_ERROR + })?; + } + // Fall through to also remove the TOML key if present. + } + // GitHub Copilot ...🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/api/providers.rs` around lines 1575 - 1616, The provider removal path only removes the TOML key via provider_toml_key but doesn't delete the Anthropic OAuth file, so delete_provider("anthropic") leaves anthropic_oauth.json present causing get_providers to still report anthropic:true; fix by handling the "anthropic" provider specially before the generic TOML removal: detect provider == "anthropic", remove the on-disk OAuth file (anthropic_oauth.json) if it exists, and if the state.llm_manager exposes an in-memory clearing call (e.g., a method analogous to the ChatGPT branch such as clear_anthropic_oauth/clear_anthropic_credentials) invoke it to clear credentials from memory, then return the same ProviderUpdateResponse success flow instead of falling through to only removing the toml key.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/api/providers.rs`:
- Line 377: delete_provider currently only removes the TOML key for the
"anthropic" provider leaving its OAuth file (anthropic_oauth.json) on disk so
anthropic_oauth_configured remains true; add a dedicated branch in
delete_provider (mirror the "github-copilot" handling) that checks for provider
== "anthropic", calls crate::auth::credentials_path(&instance_dir).remove_file()
(or std::fs::remove_file) to delete the OAuth file, and clear any in-memory
Anthropic state so the provider is fully unconfigured; place this block before
the generic fallback removal to ensure the OAuth file is removed when deleting
"anthropic".
---
Outside diff comments:
In `@src/api/providers.rs`:
- Around line 1575-1616: The provider removal path only removes the TOML key via
provider_toml_key but doesn't delete the Anthropic OAuth file, so
delete_provider("anthropic") leaves anthropic_oauth.json present causing
get_providers to still report anthropic:true; fix by handling the "anthropic"
provider specially before the generic TOML removal: detect provider ==
"anthropic", remove the on-disk OAuth file (anthropic_oauth.json) if it exists,
and if the state.llm_manager exposes an in-memory clearing call (e.g., a method
analogous to the ChatGPT branch such as
clear_anthropic_oauth/clear_anthropic_credentials) invoke it to clear
credentials from memory, then return the same ProviderUpdateResponse success
flow instead of falling through to only removing the toml key.
🪄 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: 4408824a-3626-490d-a558-ec7dcbc53f4e
📒 Files selected for processing (1)
src/api/providers.rs
| let instance_dir = (**state.instance_dir.load()).clone(); | ||
| let secrets_store = state.secrets_store.load(); | ||
| let openai_oauth_configured = crate::openai_auth::credentials_path(&instance_dir).exists(); | ||
| let anthropic_oauth_configured = crate::auth::credentials_path(&instance_dir).exists(); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm crate::auth::credentials_path exists and returns an Anthropic-specific path.
rg -n "fn credentials_path" --type rust -C 5Repository: spacedriveapp/spacebot
Length of output: 1930
🏁 Script executed:
#!/bin/bash
# Search for delete_provider function and examine handling for anthropic and openai-chatgpt providers
rg -n "fn delete_provider" --type rust -A 150 | head -300Repository: spacedriveapp/spacebot
Length of output: 9296
Add dedicated handler for Anthropic OAuth credentials deletion in delete_provider.
The Anthropic provider uses OAuth credentials stored in anthropic_oauth.json, similar to OpenAI's openai_chatgpt_oauth.json and GitHub Copilot's token file. When a user deletes the Anthropic provider, only the TOML key is removed (line ~1603). The OAuth credentials file remains on disk, causing anthropic_oauth_configured to stay true on subsequent get_providers calls. The provider will incorrectly show as still configured after deletion.
Add special handling for "anthropic" in delete_provider before the generic fallback (after line 1530, following the "github-copilot" pattern) to remove the OAuth file via crate::auth::credentials_path and clear in-memory state.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/api/providers.rs` at line 377, delete_provider currently only removes the
TOML key for the "anthropic" provider leaving its OAuth file
(anthropic_oauth.json) on disk so anthropic_oauth_configured remains true; add a
dedicated branch in delete_provider (mirror the "github-copilot" handling) that
checks for provider == "anthropic", calls
crate::auth::credentials_path(&instance_dir).remove_file() (or
std::fs::remove_file) to delete the OAuth file, and clear any in-memory
Anthropic state so the provider is fully unconfigured; place this block before
the generic fallback removal to ensure the OAuth file is removed when deleting
"anthropic".
Summary
get_providers()endpoint only checks forANTHROPIC_API_KEYenv var or config file key to determine if Anthropic is availableanthropic_oauth.json, causing the Settings UI to report Anthropic as "not configured" for OAuth users (Claude Pro/Max subscription)openai_oauth_configuredpattern already in place for OpenAIMinimal 3-line alternative to #430.
Changes
src/api/providers.rs: Checkanthropic_oauth.jsonexistence alongside API key checksTest plan
spacebot auth loginto authenticate via OAuth (no API key set)🤖 Generated with Claude Code
via Happy