fix: use inline config for AI proxy to avoid configId lookup failure (#166)#167
Conversation
When backend mode is enabled, AI service requests (test connection, repo analysis, etc.) used configId to look up the config in the backend DB. This failed when the auto-sync hadn't pushed the config yet (2s debounce window), causing "AI config not found" 404 errors. Now always sends the full config inline via proxyAIRequestWithConfig, matching what the form test connection already does successfully. Fixes #166 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds BackendAdapter.proxyAIRequestWithFallback which first tries a config-id based /proxy/ai call and falls back to an inline-config /proxy/ai call when the backend reports the AI config is missing; AIService.requestText now routes proxied OpenAI-family, Claude, and Gemini requests through this fallback helper. ChangesProxy Request Fallback
sequenceDiagram
participant AIService
participant BackendAdapter
participant BackendAPI
AIService->>BackendAdapter: proxyAIRequestWithFallback(configId, config, body, signal)
BackendAdapter->>BackendAPI: POST /proxy/ai (with configId)
alt Backend returns 200
BackendAPI-->>BackendAdapter: JSON response
BackendAdapter-->>AIService: return response
else Backend returns 404 or AI_CONFIG_NOT_FOUND
BackendAdapter->>BackendAPI: POST /proxy/ai (with inline config in body)
BackendAPI-->>BackendAdapter: JSON response
BackendAdapter-->>AIService: return response
else other error
BackendAPI-->>BackendAdapter: error
BackendAdapter-->>AIService: throws translated error (Error with statusCode/code)
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
🤖 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/services/aiService.ts`:
- Line 157: The code currently always sends this.config.apiKey inline when
calling backend.proxyAIRequestWithConfig (seen where data = await
backend.proxyAIRequestWithConfig(this.config, ...)), which exposes secrets for
saved configs; change the call sites (the calls at proxyAIRequestWithConfig
around the blocks handling requestBody/options) to first attempt using a minimal
payload containing only configId (this.config.id) and any non-secret metadata,
and only on a backend error indicating AI_CONFIG_NOT_FOUND or HTTP 404 retry
with the full inline config including this.config.apiKey; implement this retry
flow around backend.proxyAIRequestWithConfig and ensure errors are caught and
inspected for the specific not-found code before sending the fallback inline
config to avoid unnecessary secret transit.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Address CodeRabbit review: avoid sending API key inline when the config exists in the backend DB. Added proxyAIRequestWithFallback that first tries configId lookup, and only falls back to inline config on 404. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/services/backendAdapter.ts`:
- Around line 269-274: The fallback check should not rely on localized message
text; change the error propagation so throwTranslatedError preserves a stable
machine-readable indicator (e.g., attach err.code = 'AI_CONFIG_NOT_FOUND' or set
err.cause?.status = 404) and then replace the message substring checks in the
catch block with a check against that property (e.g., if ((err as any).code !==
'AI_CONFIG_NOT_FOUND' && (err as any).cause?.status !== 404) throw err). Update
throwTranslatedError to copy the original error code/status into the thrown
Error and use that stable field here instead of checking for "AI config not
found".
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2ad7d540-01ea-4cf6-89e6-17ab02df7ff1
📒 Files selected for processing (2)
src/services/aiService.tssrc/services/backendAdapter.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/services/aiService.ts
Address CodeRabbit review: throwTranslatedError now attaches statusCode and code to the Error object. proxyAIRequestWithFallback checks these stable properties instead of matching localized message strings. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
AIService.requestText()usedconfigIdlookup path whenconfig.idwas set, but the config might not yet be synced to the backend DB (auto-sync has a 2s debounce)proxyAIRequestWithConfig(inline config path) to send the full config data directly to the backend, matching what the form test connection already doesProblem
In backend mode, there were two code paths for AI proxy requests:
proxyAIRequest(configId)id)proxyAIRequestWithConfig(config)id)The
configIdpath failed when auto-sync hadn't pushed the config yet (2s debounce window after saving), causing:Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit