Skip to content

Search UX tooltip and distinct /api/search error codes (#117)#126

Merged
wpak-ai merged 3 commits into
masterfrom
fix/search-ux-and-api-errors
Jun 30, 2026
Merged

Search UX tooltip and distinct /api/search error codes (#117)#126
wpak-ai merged 3 commits into
masterfrom
fix/search-ux-and-api-errors

Conversation

@clean6378-max-it

@clean6378-max-it clean6378-max-it commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add search-window info tooltip to templates/search.html explaining the default 30-day indexed window, undated-chat inclusion, and the all-history checkbox.
  • Replace the broad except Exception handler in api/search.py with narrowed handlers returning structured {"error", "code"} bodies for 400, 404, 503, and 500.
  • Frontend search handler displays the human-readable error field from failed API responses.
  • Add max query length validation (500 chars → 400) and optional workspace hash validation (404 when unknown).

Problem

Part A: Users did not understand why some search results were missing (30-day window, undated chats always included).
Part B: /api/search returned generic 500 for all failures, preventing clients from distinguishing malformed input, missing workspace, index lock, and internal errors.

Test plan

  • pytest tests/test_api_search.py -q (19 passed)
  • Full pytest -q (533 passed, 21 skipped)
  • mypy api/search.py
  • Parametrized 400 cases: empty query, invalid type, invalid since_days, query too long
  • 404: unknown workspace hash
  • 503: simulated sqlite3.OperationalError
  • 500: unexpected internal error with internal_error code
  • No regression in TestSearchWindow / happy-path behavior

Out of scope

  • FTS vs live-scan refactor
  • Repo-wide structured errors for all blueprints
  • Search module duplication extraction (T21)

Closes #117

Summary by CodeRabbit

  • New Features

    • Added a “search window” help tooltip explaining the default recent-history behavior and how to include older chats.
    • Added/strengthened optional workspace filtering so results are constrained to the selected workspace.
  • Bug Fixes

    • Improved /api/search input validation and returns structured, code-based error responses with clearer status handling.
    • More resilient client-side handling of malformed or empty search responses.
    • Updated the results window note to indicate when undated chats are included.

Add a search-window info tooltip, return structured 400/404/503/500
responses with machine-readable codes, validate query length and
workspace hash, and show API error messages in the search UI.
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b66419f0-b8bd-4f7f-a5b6-ca817ab126b2

📥 Commits

Reviewing files that changed from the base of the PR and between 4e8320e and 463e35d.

📒 Files selected for processing (4)
  • api/search.py
  • static/css/style.css
  • templates/search.html
  • tests/test_api_search.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • templates/search.html
  • static/css/style.css
  • tests/test_api_search.py
  • api/search.py

📝 Walkthrough

Walkthrough

Adds explicit /api/search validation and structured error codes, workspace-based result filtering, search-window help text in the UI, and updated tests for the new response shapes and failure modes.

Search API hardening and UI tooltip

Layer / File(s) Summary
Search helpers and workspace checks
api/search.py
Adds search request constants, structured error formatting, workspace ID validation, workspace existence checks, and result filtering by workspace.
Search route validation and response shape
api/search.py
Reworks search() to validate query parameters early, resolve workspace access before search execution, compute the search window, return the updated success payload, and map backend failures to distinct structured error responses.
Search API status-code coverage
tests/test_api_search.py
Updates search API tests for structured error bodies, parameter validation, workspace resolution failures, and workspace-filtered results.
Search tooltip and error rendering
static/css/style.css, templates/search.html
Adds tooltip copy and styling for the search window message, and updates search result handling to parse JSON defensively and render structured error details.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • cppalliance/cppa-cursor-browser#102: Refactored the search handler to delegate to services/search, which this PR extends with validation, workspace scoping, and structured errors.

🐇 I hopped through search with careful glee,
Now windows and errors are plain to see.
A tooltip, a code, and a workspace gate,
Help old results and new ones relate.
Hop hop—search now speaks more clearly to me!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main change: search UX tooltip plus distinct /api/search error codes.
Linked Issues check ✅ Passed The PR covers the tooltip, undated-chat/window copy, distinct API error codes, and adds tests for the new behaviors.
Out of Scope Changes check ✅ Passed The changes stay focused on search UX and /api/search behavior, with no obvious unrelated edits.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/search-ux-and-api-errors

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/search.py`:
- Around line 57-66: The _workspace_exists helper currently joins
client-controlled workspace_id values directly into os.path.isdir, which can be
abused with absolute paths or .. segments. Update _workspace_exists to
explicitly allow only known-safe workspace IDs before joining paths: keep the
existing "global" and "cli:" handling, and for regular IDs validate they match
the expected workspace hash/ID format before calling
os.path.join(workspace_path, workspace_id). Reject or return false for anything
outside that allowed pattern so workspace existence checks cannot be used as a
local path oracle.
- Around line 107-112: Move workspace discovery into the existing
structured-error guard in the search flow so failures are converted to the JSON
error contract. Specifically, in the request handling around workspace_filter,
resolve_workspace_path should be called inside the try block (the same guard
used by the search endpoint), and any discovery/storage exceptions should be
caught and routed through _search_error instead of escaping before the handler
can format a 500/503 response.

In `@templates/search.html`:
- Around line 17-24: The search help tooltip is not exposed to assistive
technologies because the trigger in search.html uses a focusable span with only
aria-label, while the guidance text is just visual content. Update the tooltip
trigger to a semantic control such as a button, and connect it to the help text
using aria-describedby with the tooltip content marked appropriately (for
example, role="tooltip") so screen readers can access the 30-day/full-history
guidance. Keep the existing search-info-tooltip, search-info-tooltip-text, and
search-info-icon structure as the anchor points while changing the accessibility
semantics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fdfda060-7323-48ea-8cff-b4a8c4d5fc20

📥 Commits

Reviewing files that changed from the base of the PR and between fb97d03 and 4e8320e.

📒 Files selected for processing (4)
  • api/search.py
  • static/css/style.css
  • templates/search.html
  • tests/test_api_search.py

Comment thread api/search.py Outdated
Comment thread api/search.py Outdated
Comment thread templates/search.html Outdated

@bradjin8 bradjin8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the following issues.

[Optional] templates/search.html line 123-126:

result-count banner could mention undated chats when windowed ("last 30 days; undated chats included"). Tooltip covers discoverability; banner would reinforce after search.

Comment thread templates/search.html
Comment thread api/search.py
Comment thread api/search.py
Comment thread api/search.py
Comment thread templates/search.html
Comment thread api/search.py
@clean6378-max-it

Copy link
Copy Markdown
Collaborator Author

Please check the following issues.

[Optional] templates/search.html line 123-126:

result-count banner could mention undated chats when windowed ("last 30 days; undated chats included"). Tooltip covers discoverability; banner would reinforce after search.

windowNote when windowed now includes undated chats

@bradjin8 bradjin8 requested a review from wpak-ai June 30, 2026 19:15
@wpak-ai wpak-ai merged commit 347d771 into master Jun 30, 2026
17 checks passed
@wpak-ai wpak-ai deleted the fix/search-ux-and-api-errors branch June 30, 2026 21:13
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.

cppa-cursor-browser: Search UX polish and distinct /api/search error codes

3 participants