Skip to content

Fix autoresearch crash on zero-result search queries#54

Merged
TroyHernandez merged 2 commits into
mainfrom
fix/autoresearch-empty-search
Jun 3, 2026
Merged

Fix autoresearch crash on zero-result search queries#54
TroyHernandez merged 2 commits into
mainfrom
fix/autoresearch-empty-search

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

Problem

autoresearch() crashes mid-run when any search query returns zero results. Tagging the result rows with date, source, query, and angle assigns a length-1 value onto a 0-row data.frame:

Error in $<-.data.frame(*tmp*, "date", value = "") :
  replacement has 1 row, data has 0

Hit in practice when the query planner emits a site:github.com/OWNER/REPO path-scoped query that the search backend can't satisfy (returns 0 rows).

Fix

  • .validate_autoresearch_search_results() now builds every column (title, url, snippet, date, source) at full nrow(x) length, then filters empty URLs once. This fixes the 0-row crash and a latent bug where the old code assigned x$date (full length) onto an already-url-filtered out (shorter), misaligning rows.
  • autoresearch_run_searches() uses rep.int(..., nrow(df)) to tag query/angle, matching the safe pattern already used for the round column.

Test

Regression test in test_autoresearch.R covering the zero-result validator path, the mixed-URL filter alignment, and the full search loop with an empty backend. Full suite green (128 tests).

A search query returning 0 rows made .validate_autoresearch_search_results
and autoresearch_run_searches assign a length-1 value (date, source, query,
angle) onto a 0-row data.frame, erroring with 'replacement has 1 row, data
has 0'. Build all columns at full length before filtering empty URLs, which
also keeps date/source aligned when the URL filter drops rows. Add a
regression test for the empty-result and mixed-URL paths.
@TroyHernandez TroyHernandez merged commit 8f4b2e1 into main Jun 3, 2026
4 checks passed
@TroyHernandez TroyHernandez deleted the fix/autoresearch-empty-search branch June 3, 2026 20:03
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