Skip to content

docs: search-index lock-acquisition order and threading model#138

Open
clean6378-max-it wants to merge 3 commits into
masterfrom
docs/search-index-lock-order
Open

docs: search-index lock-acquisition order and threading model#138
clean6378-max-it wants to merge 3 commits into
masterfrom
docs/search-index-lock-order

Conversation

@clean6378-max-it

@clean6378-max-it clean6378-max-it commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Document the four search-index locks, permitted nesting contract, and FTS pointer-swap threading model in docs/architecture.md.
  • Add a Deployment — WSGI workers note in README.md warning against multi-worker Gunicorn/uWSGI on a shared index directory; point to single-worker or CLAUDE_CODE_CHAT_BROWSER_NO_SEARCH_INDEX=1.

Docs-only (Week 30 item #6); defines the invariant for the follow-up concurrency suite (item #7).

Test plan

  • Reviewed lock usage against utils/search_index.py (lines 57–63, 187–219, 521, 641–693)
  • CI green (ruff, pytest, link checks as applicable)
  • Reviewer confirms lock contract matches intended concurrency test assertions

Summary by CodeRabbit

  • Documentation
    • Added a new guide section covering “WSGI workers,” including the recommended single-worker setup and warnings that multi-worker deployments can cause nondeterministic search/index freshness and fallback behavior.
    • Updated search documentation for GET /api/search?q=..., describing SQLite FTS5 usage when available and a live JSONL scan fallback when the index is missing, stale, or temporarily locked.
    • Expanded architecture notes with more detail on index rebuild/publish behavior, locking/threading expectations, and how to disable FTS indexing via configuration.

@coderabbitai

coderabbitai Bot commented Jul 21, 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: 48d8b905-def8-41a3-ac7b-de8369bbb8fc

📥 Commits

Reviewing files that changed from the base of the PR and between 33d5ea0 and 6f5cd4e.

📒 Files selected for processing (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

📝 Walkthrough

Walkthrough

Documents /api/search FTS5 index usage, live-scan fallback behavior, index lifecycle and locking, and single-worker WSGI deployment guidance.

Changes

FTS search documentation

Layer / File(s) Summary
Search index behavior and fallback
docs/architecture.md
Documents local FTS5 querying with live JSONL-scan fallback when the index is unavailable, stale, or locked.
Search index lifecycle and deployment
docs/architecture.md, README.md
Documents index storage, atomic publication, lock coordination, threading contracts, per-process cache scope, and single-worker WSGI configuration.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

  • Issue cppalliance/claude-code-chat-browser#135 — Covers the documented search-index threading, locking, atomic publication, and single-worker WSGI deployment constraints.

Suggested reviewers: timon0305

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main documentation change about search-index locking and threading behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/search-index-lock-order

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: 2

🤖 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 `@docs/architecture.md`:
- Line 156: Update the Publish description for _publish_active_index so it does
not claim unconditional atomic pointer replacement; explicitly mention the
pointer.write_text fallback and qualify the reader guarantee to acknowledge
possible incomplete pointers, or remove that fallback from the implementation if
atomic publication is required.
- Line 158: Update the architecture documentation to distinguish rebuild
isolation from index_locked classification: explain that rebuilding a new SQLite
file does not normally lock the old active database, while query_index_hits
still classifies sqlite3.OperationalError as index_locked for fallback handling.
Avoid implying that rebuild concurrency inherently causes the error, and clarify
this distinction for follow-up tests.
🪄 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: 315eb35c-5452-4512-8803-b4baaaa035be

📥 Commits

Reviewing files that changed from the base of the PR and between 0c43bd7 and e4d8f3c.

📒 Files selected for processing (2)
  • README.md
  • docs/architecture.md

Comment thread docs/architecture.md Outdated
Comment thread docs/architecture.md Outdated
@clean6378-max-it
clean6378-max-it force-pushed the docs/search-index-lock-order branch from e4d8f3c to 10e6b86 Compare July 21, 2026 16:37

@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: 1

🤖 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 `@README.md`:
- Line 84: Update the README guidance for
CLAUDE_CODE_CHAT_BROWSER_NO_SEARCH_INDEX so it states that disabling the index
avoids using or building index files, rather than implying that existing index
files are removed.
🪄 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: 9b567a1f-22b7-4ca1-ac0c-47b5289233d3

📥 Commits

Reviewing files that changed from the base of the PR and between e4d8f3c and 10e6b86.

📒 Files selected for processing (2)
  • README.md
  • docs/architecture.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/architecture.md

Comment thread README.md Outdated
Comment thread docs/architecture.md

The design targets **one WSGI worker process** (for example `python app.py` or `gunicorn --workers 1`). That gives one in-process writer thread, one advisory-lock owner, and consistent in-memory usability cache per operator session.

See [Deployment — WSGI workers](../README.md#deployment-wsgi-workers) in the README for multi-worker warnings.

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.

Broken anchor. This links to #deployment-wsgi-workers, but the README heading is #### Deployment - WSGI workers, which Github slugs to deployment--wsgi-workers. The single-hyphen link won't resolve.
Simplest fix: rename the README heading to #### Deployment: WSGI workers - it slugs to deployment-wsgi-workers, matching this link and drops the em-dash.

Comment thread README.md
> The server **refuses to start** if `--debug` is combined with a non-loopback `--host` (e.g. `0.0.0.0`).
> That check runs only when you start the app with **`python app.py`** (not via `flask run` or other WSGI entrypoints).

#### Deployment — WSGI workers

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.

Em-dash in the heading, and it's why the cross-link at docs/architecture.md:194 is broken.
Suggest #### Deployment: WSGI workers - fixes both at once.

Comment thread docs/architecture.md
- `integration-tests` — API integration subset + coverage artifact
- `js-tests` — `npm ci` + vitest

## Search index (FTS5) — locks and threading

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.

em-dash in the heading.
This one is internally consistent - the links at architecture.md:69 and README.md:78 already use the matching double-hyphen slug search-index-fts5--lock-and-threading - so if you de-em-dash this heading, update both of those links in the same pass or they'll break.

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.

2 participants