Skip to content

fix: guard against undefined queries/urls in research actions#1036

Open
VibhorGautam wants to merge 1 commit intoItzCrazyKns:masterfrom
VibhorGautam:fix/slice-undefined-crash-964
Open

fix: guard against undefined queries/urls in research actions#1036
VibhorGautam wants to merge 1 commit intoItzCrazyKns:masterfrom
VibhorGautam:fix/slice-undefined-crash-964

Conversation

@VibhorGautam
Copy link

@VibhorGautam VibhorGautam commented Mar 8, 2026

Problem

Every search crashes with TypeError: Cannot read properties of undefined (reading 'slice') when the LLM returns incomplete or malformed tool arguments. This happens because all five research actions call .slice() directly on the queries or urls field without checking if it exists first.

When the LLM doesn't return structured arguments properly (due to context limits, model quirks, or malformed tool calls), actionConfig.arguments is an empty object {}, so input.queries / params.urls is undefined.

Fix

Added nullish coalescing (?? []) before .slice() in all five action files:

  • webSearch.ts
  • academicSearch.ts
  • socialSearch.ts
  • uploadsSearch.ts
  • scrapeURL.ts

If the field is missing, it defaults to an empty array and the action continues without crashing.

Fixes #964


Summary by cubic

Prevented search crashes when the LLM returns missing queries or urls by defaulting to an empty array before slicing. All five research actions now continue safely instead of throwing "Cannot read properties of undefined (reading 'slice')".

Written for commit efda0a2. Summary will update on new commits.

When the LLM returns incomplete tool arguments (e.g. missing the
queries or urls field), calling .slice() on undefined crashes the
entire search. Default to an empty array so execution continues
gracefully.

Fixes ItzCrazyKns#964
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.

1 issue found across 5 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/researcher/actions/academicSearch.ts">

<violation number="1" location="src/lib/agents/search/researcher/actions/academicSearch.ts:33">
P2: Nullish-only guard allows non-array `queries` values through, which can still crash at `input.queries.map(...)`.</violation>
</file>

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

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.

TypeError: Cannot read properties of undefined (reading 'slice')

1 participant