Skip to content

fix: improve robustness across model providers and search pipeline#1039

Open
VibhorGautam wants to merge 2 commits intoItzCrazyKns:masterfrom
VibhorGautam:fix/robustness-improvements
Open

fix: improve robustness across model providers and search pipeline#1039
VibhorGautam wants to merge 2 commits intoItzCrazyKns:masterfrom
VibhorGautam:fix/robustness-improvements

Conversation

@VibhorGautam
Copy link

@VibhorGautam VibhorGautam commented Mar 8, 2026

Summary

Addresses 6 open issues with a single set of targeted fixes across the model provider layer and search pipeline. All changes are minimal and focused on preventing crashes and improving error visibility.

Issues fixed

Issue Problem Fix
#981 Ollama num_ctx hardcoded to 32000, overrides model config Replaced with configurable contextWindowSize option; Ollama uses its own default when not set
#836 vLLM endpoints crash with "Cannot read properties of undefined (reading 'message')" Added null-safety checks (?.) on response.message in OpenAI provider
#789 Ollama crash with "Cannot read properties of undefined (reading 'content')" Added null-safety checks on res.message and chunk.message in Ollama provider
#799 YouTube video embeds fail to load (youtube-nocookie.com doesn't resolve) Normalize embed URLs from youtube-nocookie.com to youtube.com in video search
#763 UI hangs on "Answering..." when SearXNG returns CAPTCHA/error Added HTTP status check in SearXNG client, try-catch in all search actions, early return on empty results
#997 Search/scrape errors are silent, no way to debug Added console.error logging for SearXNG failures, scrape failures, and search errors

Changes by file

  • src/lib/models/types.ts - Added contextWindowSize to GenerateOptions
  • src/lib/models/providers/ollama/ollamaLLM.ts - Use configurable context window instead of hardcoded 32000; null-safety on message access
  • src/lib/models/providers/openai/openaiLLM.ts - Null-safety on response.choices[0].message
  • src/lib/searxng.ts - Check HTTP status before parsing; return empty results on error instead of crashing
  • src/lib/agents/search/researcher/actions/webSearch.ts - Try-catch around SearXNG call, skip on failure
  • src/lib/agents/search/researcher/actions/academicSearch.ts - Same pattern
  • src/lib/agents/search/researcher/actions/socialSearch.ts - Same pattern
  • src/lib/agents/search/researcher/actions/scrapeURL.ts - Log errors to console before returning error result
  • src/lib/agents/media/video.ts - Try-catch around SearXNG call; normalize youtube-nocookie.com URLs

How to test

  1. npm install && npm run dev
  2. context length hardcoded for ollama provider #981: Configure an Ollama model - verify it no longer forces num_ctx: 32000 (check Ollama server logs, the model should load with its own default context size)
  3. Perplexica fails to work with vLLM endpoints, throwing TypeError: Cannot read properties of undefined (reading 'message') during search operations. #836/TypeError: Cannot read properties of undefined (reading 'content') #789: If you have a vLLM or non-standard Ollama endpoint, queries should return a proper error instead of crashing
  4. Embedded videos fail to load because iframe uses youtube-nocookie.com #799: Search for a video topic (e.g. "how to make pasta") - click a video in the carousel and confirm the YouTube embed loads
  5. UI hangs on "Answer" spinner when SearXNG returns CAPTCHA error #763: If your SearXNG instance has suspended engines or returns errors, the search should complete gracefully instead of hanging
  6. Errors don't contain logs for debugging - how to debug parsing errors? #997: Check the terminal for detailed error logs when a search or scrape fails

Summary by cubic

Improves robustness across model providers and the search pipeline to prevent crashes and hangs, with clearer error logs. Adds a configurable context window for ollama and makes SearXNG error handling strict to avoid silent failures.

  • Bug Fixes
    • ollama: replace hardcoded num_ctx with contextWindowSize; fall back to the model’s default when unset.
    • Providers: add null-safety for message/content in ollama and openai to handle vLLM/older endpoints.
    • Search: searchSearxng() now throws on non-2xx and non-JSON responses; web/academic/social/video actions catch errors, early-exit on empty results, and log with console.error to avoid UI hangs.
    • Media: normalize YouTube embeds from youtube-nocookie.com to youtube.com so iframes load.

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

This addresses several reported issues in one pass:

- Remove hardcoded num_ctx (32000) in the Ollama provider. It now uses
  the contextWindowSize option from GenerateOptions, letting Ollama fall
  back to whatever the model was loaded with instead of forcing 32K.
  (fixes ItzCrazyKns#981)

- Add null-safety checks on response.message in both OpenAI and Ollama
  providers. Some endpoints (vLLM, older Ollama builds) can return
  responses where message or content is missing, causing "Cannot read
  properties of undefined" crashes. (fixes ItzCrazyKns#836, ItzCrazyKns#789)

- Normalize YouTube embed URLs from youtube-nocookie.com to youtube.com
  in the video search widget. Some SearXNG instances return the
  privacy-enhanced domain which doesn't resolve on certain networks.
  (fixes ItzCrazyKns#799)

- Handle SearXNG errors gracefully instead of crashing. Added HTTP
  status check in searchSearxng(), try-catch wrappers in webSearch,
  academicSearch, socialSearch, and video search actions, and early
  returns on empty results. The UI no longer hangs indefinitely when
  SearXNG returns a CAPTCHA or error. (fixes ItzCrazyKns#763)

- Add console.error logging for scrape failures, search failures, and
  SearXNG errors so issues are visible in the terminal. (fixes ItzCrazyKns#997)
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.

4 issues found across 9 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/media/video.ts">

<violation number="1" location="src/lib/agents/media/video.ts:62">
P2: Unvalidated upstream result shapes can still cause runtime errors when calling `.replace` on non-string `iframe_src`.</violation>
</file>

<file name="src/lib/searxng.ts">

<violation number="1" location="src/lib/searxng.ts:43">
P2: `res.ok` guard is incomplete: `res.json()` can still throw on 2xx non-JSON/malformed responses, bypassing the intended safe fallback.</violation>

<violation number="2" location="src/lib/searxng.ts:45">
P2: Non-2xx SearXNG responses are swallowed as empty results, masking backend failures and bypassing existing error-handling flows.</violation>
</file>

<file name="src/lib/agents/search/researcher/actions/webSearch.ts">

<violation number="1" location="src/lib/agents/search/researcher/actions/webSearch.ts:121">
P2: Per-query catch swallows search exceptions, causing failed searches to return successful empty/partial results instead of propagating to centralized 500 handling.</violation>
</file>

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

Non-2xx responses now throw so the error propagates to callers (which
already have try-catch). Also wrapped res.json() in a try-catch to
handle cases where a 2xx response has malformed/non-JSON body.
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.

1 participant