fix(providers): detect Anthropic OAuth credentials in provider status#591
fix(providers): detect Anthropic OAuth credentials in provider status#591marcmantei wants to merge 2 commits 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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthroughget_providers now treats Anthropic as configured if ANTHROPIC_API_KEY is set or Anthropic OAuth credentials exist on disk (checked via crate::auth::credentials_path). delete_provider removes the Anthropic OAuth credentials file when removing the Anthropic provider. ChangesAnthropic OAuth Configuration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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
When delete_provider("anthropic") is called, also remove the
anthropic_oauth.json file from disk. Without this, the provider
detection added in the previous commit would still report Anthropic
as configured after deletion.
Mirrors the existing "openai-chatgpt" deletion handling pattern.
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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