Skip to content

Conversation

@nioasoft
Copy link

@nioasoft nioasoft commented Jan 26, 2026

Summary

  • Fix endless 404 errors when stored conversation ID no longer exists
  • Stop retrying on 404 errors (conversation doesn't exist)
  • Automatically clear invalid conversation ID from localStorage

Test plan

  • Delete assistant.db or reset database while having active conversation
  • Refresh browser - should see warning in console and no repeated 404 errors
  • Assistant should work normally with new conversation

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling when a conversation is no longer available to avoid stale state and errors.
    • Added automatic retry for transient conversation-loading failures to improve reliability (fewer interruptions).

✏️ Tip: You can customize this high-level summary in your review settings.

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>
@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

Added 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

Cohort / File(s) Summary
Conversation hook
ui/src/hooks/useConversations.ts
Added retry policy: do not retry when error message contains "not found" (case-insensitive) or equals "HTTP 404"; otherwise retry up to 3 times.
UI error handling
ui/src/components/AssistantPanel.tsx
Expanded hook destructure to include conversationError; added effect to clear local conversationId when a 404/not-found error is returned.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰
A missing chat, a tiny fright,
I sniff the trails and make it right.
If 404s block the way we roam,
I'll clear the path and lead us home.
Hop on — fresh convo, fresh foam!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: handle 404 errors for deleted assistant conversations' directly and accurately summarizes the main change: adding error handling for 404 errors when conversation IDs no longer exist, which is the core purpose across both modified files.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link

@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

🤖 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.

Copy link
Owner

@leonvanzyl leonvanzyl left a 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>
rudiheydra added a commit to rudiheydra/AutoBuildr that referenced this pull request Jan 28, 2026
….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>
@leonvanzyl leonvanzyl merged commit 51dc1bb into leonvanzyl:master Jan 29, 2026
3 checks passed
@leonvanzyl
Copy link
Owner

Thank you!

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.

2 participants