Skip to content

fix(search): treat a whitespace-only GLOBAL_SEARCH query as no query - #5409

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/global-search-whitespace-query-w4
Jul 30, 2026
Merged

fix(search): treat a whitespace-only GLOBAL_SEARCH query as no query#5409
pedrofrxncx merged 1 commit into
mainfrom
fix/global-search-whitespace-query-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Bug found while auditing the GLOBAL_SEARCH tool (offset pagination itself is already covered by open PR #5387, which this does not touch or duplicate).

The tool's own docstring promises "Empty string returns the most recently updated resources," but GLOBAL_SEARCH passed input.query straight through to ThreadsStorage.list(), which does if (options?.search) (a truthy check) before applying ilike "%<search>%". A whitespace-only query like " " is truthy, so instead of falling back to "most recent" it silently filters on a literal run of spaces in title — almost always zero results, breaking the documented contract for any client that submits a query the user only whitespace-padded (e.g. a search box blurred after typing then deleting). The same untrimmed pass-through also meant a query like " foo " would fail to match a title of "foo" because the ILIKE pattern included the stray spaces.

Fix: added a small pure normalizeSearchQuery() helper in global-search.ts that trims the query and maps an all-whitespace result to undefined (the same "no filter" value ThreadsStorage.list() already treats as "no search"), and used it in the handler instead of the raw input.query. No change to ThreadsStorage.list() itself, no change to the offset/pagination fields.

Failure scenario before the fix: GLOBAL_SEARCH({ query: " " }) returns { items: [], totalCount: 0 } for an org with recent threads, instead of the documented "most recently updated" listing.

Regression test: apps/api/src/tools/search/global-search.test.ts now covers normalizeSearchQuery directly (pure function, no DB/mocks) for empty string, whitespace-only, padded, and already-trimmed queries.

Reviewer check: bun test apps/api/src/tools/search/global-search.test.ts

Locally ran: bun run fmt, cd apps/api && bunx tsc --noEmit, and the targeted test file above — all green. Full CI covers the rest.


Summary by cubic

Treats whitespace-only GLOBAL_SEARCH queries as no query, restoring the “most recently updated” fallback. Also trims surrounding spaces so padded queries match as expected.

  • Bug Fixes
    • Added normalizeSearchQuery to trim input and map empty/whitespace to undefined; used for the search option in ThreadsStorage.list.
    • Added tests for empty, whitespace-only, padded, and already-trimmed inputs.

Written for commit 1be9287. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx merged commit a3b6606 into main Jul 30, 2026
17 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/global-search-whitespace-query-w4 branch July 30, 2026 05:45
decocms Bot pushed a commit that referenced this pull request Jul 30, 2026
PR: #5409 fix(search): treat a whitespace-only GLOBAL_SEARCH query as no query
Bump type: patch

- decocms (apps/api/package.json): 4.146.0 -> 4.146.1

Deploy-Scope: server
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