Skip to content

fix: report unreadable caches from search API routes - #360

Open
dajiaohuang wants to merge 1 commit into
daaain:mainfrom
dajiaohuang:repostew/fix-corrupt-cache-api-20261015
Open

dajiaohuang wants to merge 1 commit into
daaain:mainfrom
dajiaohuang:repostew/fix-corrupt-cache-api-20261015

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 15, 2026 •

Copy link
Copy Markdown

Summary

Addresses the API error paths reported in #335. With serve --no-convert and an unreadable cache, /api/search and /api/projects currently return HTTP 500 with a raw DatabaseError(...) representation, even though /api/ping already diagnoses the unreadable cache.

  • Route corruption raised by the search readiness check through the existing unavailable-index diagnostic and HTTP 400 path.
  • Report an unreadable projects cache as a readable HTTP 400 error, without substituting an empty successful result.
  • Keep unrelated SQLite errors unchanged. No cache deletion, retry, repair, or extra readiness query is added to a healthy search.

This is scoped to the two backend error responses; it does not change the frontend restart hint discussed in #335.

Validation

  • New real-loopback HTTP regression cases for both endpoints failed on the base (500 instead of 400), then passed with the fix.
  • python -m pytest --noconftest -o addopts= test/test_api.py -q: 21 passed, including the existing search no-full-scan test and a new check that unrelated database errors still propagate. Temporary files and HOME were isolated; pytest reported four warnings for optional plugins not installed.
  • Locked Ruff 0.14.7 check and format-check: passed on both changed files.
  • Additional synthetic-only acceptance: install, CLI help, file/directory/session-id conversion, HTML in both themes, Markdown/JSON/stdout, date filtering, token statistics, cache/search API, append/watch detection; actual Chromium page/filter/search checks in both themes passed.

Full just ci, upstream shared fixtures, TUI/provider discovery, large real-archive performance and network-dependent timeline behavior were not run. Local acceptance used only newly constructed synthetic records, an isolated HOME/cache and a loopback server; it did not access user archives or execute transcript commands.

Summary by CodeRabbit

  • Bug Fixes
    • Search and project requests now return a clear error when the cache database is unreadable.
    • Search requests handle an unreadable index through the existing unavailable-index error response.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ef7fac17-fa24-45d9-9834-6263f09afb44
📥 Commits

Reviewing files that changed from the base of the PR and between 9834d25 and 8a06a9d.

📒 Files selected for processing: 2
  • claude_code_log/api.py
  • test/test_api.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The projects and search API paths now handle recognized corrupt-cache errors. Tests verify sanitized HTTP 400 responses and confirm that other database errors still propagate.

Changes: Corrupt Cache API Handling

Layer / File(s) Summary
API handling and validation
claude_code_log/api.py, test/test_api.py
SearchApi.projects converts recognized corruption errors to an unreadable-cache ValueError and re-raises other database errors. SearchApi.search treats recognized corruption errors from index_ready as an unavailable index. Tests check HTTP 400 responses with sanitized messages and verify that a missing projects table still raises sqlite3.OperationalError.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 8a06a

Unreadable caches on the search and projects endpoints now produce a readable HTTP 400 instead of a raw HTTP 500. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 clearly and concisely describes the main change: reporting unreadable cache errors from the search API routes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

This branch has not been deployed

No deployments
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