fix: guard against undefined queries/urls in research actions#1036
Open
VibhorGautam wants to merge 1 commit intoItzCrazyKns:masterfrom
Open
fix: guard against undefined queries/urls in research actions#1036VibhorGautam wants to merge 1 commit intoItzCrazyKns:masterfrom
VibhorGautam wants to merge 1 commit intoItzCrazyKns:masterfrom
Conversation
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
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thequeriesorurlsfield 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.argumentsis an empty object{}, soinput.queries/params.urlsisundefined.Fix
Added nullish coalescing (
?? []) before.slice()in all five action files:webSearch.tsacademicSearch.tssocialSearch.tsuploadsSearch.tsscrapeURL.tsIf 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
queriesorurlsby 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.