Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib/agents/search/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WidgetExecutor } from './widgets';

class APISearchAgent {
async searchAsync(session: SessionManager, input: SearchAgentInput) {
try {
const classification = await classify({
chatHistory: input.chatHistory,
enabledSources: input.config.sources,
Expand Down Expand Up @@ -96,6 +97,13 @@ class APISearchAgent {
}

session.emit('end', {});
} catch (err) {
console.error('API search agent error:', err);

session.emit('error', {
data: err instanceof Error ? err.message : 'An error occurred during search',
});
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/lib/agents/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TextBlock } from '@/lib/types';

class SearchAgent {
async searchAsync(session: SessionManager, input: SearchAgentInput) {
try {
const exists = await db.query.messages.findFirst({
where: and(
eq(messages.chatId, input.chatId),
Expand Down Expand Up @@ -180,6 +181,24 @@ class SearchAgent {
),
)
.execute();
} catch (err) {
console.error('Search agent error:', err);

session.emit('error', {
data: err instanceof Error ? err.message : 'An error occurred during search',
});

await db
.update(messages)
.set({ status: 'error' })
.where(
and(
eq(messages.chatId, input.chatId),
eq(messages.messageId, input.messageId),
),
)
.execute();
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/lib/hooks/useChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ export const ChatProvider = ({ children }: { children: React.ReactNode }) => {
method: 'POST',
});

if (!res.ok) {
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Reconnect flow lacks top-level fetch failure handling, which can leave reconnect/loading state stuck and reject unhandled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/hooks/useChat.tsx, line 428:

<comment>Reconnect flow lacks top-level fetch failure handling, which can leave reconnect/loading state stuck and reject unhandled.</comment>

<file context>
@@ -425,6 +425,20 @@ export const ChatProvider = ({ children }: { children: React.ReactNode }) => {
           method: 'POST',
         });
 
+        if (!res.ok) {
+          // Session no longer exists (e.g. server restarted) - mark message as error
+          setLoading(false);
</file context>
Fix with Cubic

// Session no longer exists (e.g. server restarted) - mark message as error
setLoading(false);
isReconnectingRef.current = false;
setMessages((prev) =>
prev.map((msg) =>
msg.messageId === lastMsg.messageId
? { ...msg, status: 'error' as const }
: msg,
),
);
return;
}

if (!res.body) throw new Error('No response body');

const reader = res.body?.getReader();
Expand Down