Skip to content

fix: stop search failures from hanging on Brainstorming#1054

Open
stablegenius49 wants to merge 1 commit intoItzCrazyKns:masterfrom
stablegenius49:pr-factory/issue-965-search-hang
Open

fix: stop search failures from hanging on Brainstorming#1054
stablegenius49 wants to merge 1 commit intoItzCrazyKns:masterfrom
stablegenius49:pr-factory/issue-965-search-hang

Conversation

@stablegenius49
Copy link

@stablegenius49 stablegenius49 commented Mar 11, 2026

Summary

  • catch unhandled search pipeline failures inside both search agents
  • emit a session error event instead of leaving the client stuck on "Brainstorming"
  • persist chat-message searches as status: error when they fail mid-flight so the UI can recover cleanly

Verification

  • ./node_modules/.bin/tsc --noEmit
  • npm run build

Fixes #965.


Summary by cubic

Prevented “Brainstorming” hangs by catching search pipeline errors and surfacing them to the client. Failures now emit a session error and are saved as status: 'error' so the UI can recover and allow retry. Fixes #965.

  • Bug Fixes
    • Wrapped both APISearchAgent and SearchAgent flows in try/catch; failures trigger session.emit('error', { data: message }) instead of hanging.
    • Persist failed searches with status: 'error' and current responseBlocks; successful runs still save as completed.
    • Hardened widget execution to fail soft and return empty output rather than breaking the search pipeline.

Written for commit 38300c8. Summary will update on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lib/agents/search/api.ts">

<violation number="1" location="src/lib/agents/search/api.ts:103">
P2: Raw exception messages are emitted to client-facing session error events, exposing internal error details.</violation>
</file>

<file name="src/lib/agents/search/index.ts">

<violation number="1" location="src/lib/agents/search/index.ts:186">
P1: Emitting `session.emit('error', ...)` in catch can throw synchronously and prevent persisting `status: 'error'`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +186 to +188
session.emit('error', {
data: error instanceof Error ? error.message : 'Search failed',
});
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 11, 2026

Choose a reason for hiding this comment

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

P1: Emitting session.emit('error', ...) in catch can throw synchronously and prevent persisting status: 'error'.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/agents/search/index.ts, line 186:

<comment>Emitting `session.emit('error', ...)` in catch can throw synchronously and prevent persisting `status: 'error'`.</comment>

<file context>
@@ -11,175 +11,200 @@ import { TextBlock } from '@/lib/types';
+        .execute();
+    } catch (error) {
+      console.error('Error while running search:', error);
+      session.emit('error', {
+        data: error instanceof Error ? error.message : 'Search failed',
+      });
</file context>
Suggested change
session.emit('error', {
data: error instanceof Error ? error.message : 'Search failed',
});
try {
session.emit('error', {
data: error instanceof Error ? error.message : 'Search failed',
});
} catch (emitError) {
console.error('Failed to emit session error event:', emitError);
}
Fix with Cubic

} catch (error) {
console.error('Error while running API search:', error);
session.emit('error', {
data: error instanceof Error ? error.message : 'Search failed',
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 11, 2026

Choose a reason for hiding this comment

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

P2: Raw exception messages are emitted to client-facing session error events, exposing internal error details.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/agents/search/api.ts, line 103:

<comment>Raw exception messages are emitted to client-facing session error events, exposing internal error details.</comment>

<file context>
@@ -7,95 +7,102 @@ import { WidgetExecutor } from './widgets';
+    } catch (error) {
+      console.error('Error while running API search:', error);
+      session.emit('error', {
+        data: error instanceof Error ? error.message : 'Search failed',
       });
     }
</file context>
Suggested change
data: error instanceof Error ? error.message : 'Search failed',
data: 'Search failed',
Fix with Cubic

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.

Unable to conduct a search

2 participants