-
Notifications
You must be signed in to change notification settings - Fork 312
fix: handle 404 errors for deleted assistant conversations #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle 404 errors for deleted assistant conversations #105
Conversation
When a stored conversation ID no longer exists (e.g., database was reset or conversation was deleted), the UI would repeatedly try to fetch it, causing endless 404 errors in the console. This fix: - Stops retrying on 404 errors (conversation doesn't exist) - Automatically clears the stored conversation ID from localStorage when a 404 is received, allowing the user to start fresh Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdded retry policy to conversation fetching (skip retries for 404/not-found); AssistantPanel now reads conversationError and clears stored conversationId when a 404-like error is observed. Changes
Sequence Diagram(s)sequenceDiagram
participant UI as AssistantPanel
participant Hook as useConversation
participant API as Conversation API
UI->>Hook: call useConversation(conversationId)
Hook->>API: fetch /conversations/:id
alt response 200
API-->>Hook: conversation data
Hook-->>UI: data, isLoading=false, conversationError=null
else response error
API-->>Hook: error (message)
Hook-->>Hook: retry decision (if message contains "not found" or "HTTP 404" -> no retry; else retry up to 3)
Hook-->>UI: data=null, isLoading=false, conversationError=error
alt error indicates 404/not-found
UI->>UI: clear stored conversationId (set to null)
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@ui/src/components/AssistantPanel.tsx`:
- Around line 57-63: The effect currently clears conversationId for any
conversationError; change it so it only clears when the error represents a 404.
In the useEffect that watches conversationError, conversationId and calls
setConversationId(null), check the error's HTTP status (e.g.,
conversationError.status or conversationError.response?.status) and only call
setConversationId(null) when that status === 404; otherwise leave the stored ID
intact and do not clear it. Ensure the conditional still guards on
conversationError and conversationId before checking the status.
leonvanzyl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review: Request Changes
Thanks for addressing this issue! The PR tackles a real problem, but I found a bug that will prevent the retry logic from working as intended.
Critical Issue: 404 Detection Won't Work
The retry function checks:
if (error instanceof Error && error.message.includes('404')) {
return false
}However, the server returns {"detail": "Conversation not found"} for 404 errors. The fetchJSON function in api.ts throws:
throw new Error(error.detail || `HTTP ${response.status}`)So the error message becomes "Conversation not found" — which does not contain the string "404". The retry logic will still retry 3 times before failing.
Suggested fix for useConversations.ts:
retry: (failureCount, error) => {
// Don't retry on "not found" errors (404)
if (error instanceof Error && (
error.message.toLowerCase().includes('not found') ||
error.message === 'HTTP 404'
)) {
return false
}
return failureCount < 3
}Secondary Issue: Overly Broad Error Clearing
The useEffect in AssistantPanel.tsx clears the conversation ID on any error:
if (conversationError && conversationId) {
setConversationId(null) // Clears for ALL errors
}This means network errors, 500 errors, or timeouts will also clear the stored conversation ID, potentially losing valid conversation references during temporary outages.
Suggested fix for AssistantPanel.tsx:
useEffect(() => {
if (conversationError && conversationId) {
const message = conversationError.message.toLowerCase()
// Only clear for 404 errors, not transient network issues
if (message.includes('not found') || message.includes('404')) {
console.warn(`Conversation ${conversationId} not found, clearing stored ID`)
setConversationId(null)
}
}
}, [conversationError, conversationId])Summary
| Issue | Severity | Action |
|---|---|---|
| 404 detection uses wrong string | High | Must fix |
| Error clearing too broad | Medium | Should fix |
The approach is sound — just needs these adjustments to work correctly. Let me know if you have questions!
- Check for 'not found' message (server response) in addition to '404' - Only clear stored conversation ID on actual 404 errors - Prevent unnecessary retries for deleted conversations - Don't clear conversation on transient network errors Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
….md) - Added test-runner.md with valid YAML frontmatter (name: test-runner, model: opus, color: blue) - Description references acceptance validator execution and gate verdicts - Markdown body documents validator framework (FileExistsValidator, TestPassValidator, ForbiddenPatternsValidator) - Documents gate modes (all_pass, any_pass, weighted) and key references - Feature leonvanzyl#105 verified and marked as passing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Thank you! |
Summary
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.