codescout icon indicating copy to clipboard operation
codescout copied to clipboard

Linked worktree: index status reports 0 chunks after a successful build; semantic_search says main was never indexed

Open mic-urs opened this issue 2 weeks ago • 0 comments

Summary

In a linked git worktree that has its own .codescout/project.toml, index(action="build") writes the chunks into the worktree delta store (<main>@<wt> → <main>_<wt>.db). But:

  1. index(action="status") keeps reporting indexed: false, 0 chunks after the build finishes. It appears to read the worktree's own project id (<main>-<wt> from its project.toml), whose .db stays empty.
  2. semantic_search in that worktree returns the delta results (so the index works), but adds main_never_indexed_note: "Main project <main> has no indexed chunks yet", although the main checkout is fully indexed. It seems to open an empty <main>.db created under the worktree's .codescout/embeddings/, not the main checkout's store.

So the build works. The status reporting is wrong, and it is possible that main's chunks are never served to queries from the worktree.

Environment

  • codescout 0.15.0 (~/.cargo/bin/codescout)
  • Linux 7.0 (x86_64); embeddings: nomic-ai/CodeRankEmbed (768d) through a local TEI server (text-embeddings-router, url = http://127.0.0.1:<port>/v1) on a GTX 1660 Ti; sqlite-vec store
  • Claude Code with codescout-companion; plugins updated the same day; automatic index refresh at SessionStart active (the main checkout was refreshed at session start: "INDEX: Refreshing in background (18 commits behind HEAD)")

Layout (names anonymised)

~/work/proj                    main checkout   [main]
~/work/proj/.worktrees/wt      linked worktree [feature-branch]
  • Main .codescout/project.toml: name = "proj", languages = ["markdown"] (docs only)
  • Worktree .codescout/project.toml (created earlier by a separate onboarding inside the worktree): name = "proj-wt", languages = ["python","javascript","markdown"]; same [embeddings] model/url
  • The session was started in the main checkout. The build was run with a per-call pin: index(action="build", workspace="<abs path to worktree>"). No workspace(activate) on the worktree.

Steps and observations

  1. index(action="status", workspace=<main>) → indexed: true, file_count: 5, chunk_count: 454, git_sync: up_to_date. verify → complete.
  2. index(action="status", workspace=<wt>) → indexed: false, project_id: "proj-wt", "No chunks indexed for project 'proj-wt'".
  3. index(action="build", workspace=<wt>) → started.
  4. During the build (~12.5 min), status showed status: running, done: 0, total: 0, chunks_so_far: 0 the whole time. The note says "chunk_count climbs from 0 on an initial build", but it never climbed. Meanwhile, read-only on disk:
    • <wt>/.codescout/embeddings/proj_wt.db grew 13.6 MB → 26.2 MB; select count(*) from code_chunk = 3072 mid-build, 5146 at the end; select distinct project_id from code_chunk = proj@wt
    • so the build is clearly writing the delta id delta_project_id(main, wt) = proj@wt, sanitized to proj_wt.db (sanitize_db_name maps @ → _)
  5. After the build: status → indexing: { status: "done", files_indexed: 5146, detail: "elapsed_ms=751161 delta_chunks=5146 dirty_paths=221", total_files: 0, total_chunks: 0 }, and still indexed: false, "No chunks indexed for project 'proj-wt'".
    • Minor: files_indexed: 5146 is the chunk count; the file count is dirty_paths=221.
  6. semantic_search(query=..., workspace=<wt>) → correct, relevant results from the worktree code (served from the delta), plus main_never_indexed_note: "Main project 'proj' has no indexed chunks yet. Results below come only from this worktree's delta -- main's own code is not represented."

Store files after the build (read-only sqlite3 -readonly)

File code_chunk rows Note
<main>/.codescout/embeddings/proj.db 454 the real main index
<wt>/.codescout/embeddings/proj.db 0 16 KB, created at the moment the build started
<wt>/.codescout/embeddings/proj-wt.db 0 16 KB, from the earlier onboarding in the worktree
<wt>/.codescout/embeddings/proj_wt.db 5146 delta store, project_id = 'proj@wt'

Expected

  • status on the worktree reports the delta chunks (or main + delta), and progress climbs during the build.
  • semantic_search from the worktree finds main's store in the main checkout (<main>/.codescout/embeddings/) and serves main + delta; no "never indexed" note when main is indexed.
  • files_indexed reports files, not chunks.

Suspected cause (from reading the source, unverified)

  • retrieval/sync.rs::delta_project_id → "{main}@{wt}"; sqlite_vec_ext.rs::sanitize_db_name turns @ into _ → proj_wt.db.
  • The status/indexed check seems to use the worktree's own project.toml name (proj-wt) and not the delta id, so it opens proj-wt.db (empty).
  • The main-store lookup from the worktree seems to resolve the embeddings dir relative to the worktree root (<wt>/.codescout/embeddings/proj.db, opened empty and created on first use), not the main checkout's root. This is also the likely reason main's chunks are never served from the worktree.
  • A worktree carrying its own project.toml with a different name may be the trigger. I don't know whether a worktree without its own project.toml behaves correctly.

Impact

  • Users (and agents) are told the worktree is not indexed when it is, which invites needless rebuilds. The session-start reminder had to say "trust semantic_search, not status".
  • Queries from a worktree probably miss everything the main checkout contributes. Here main is docs-only, so the impact was small, but in a repo where main holds most of the code it would be large and silent.

Happy to run more read-only diagnostics if useful.

mic-urs avatar Nov 16 '26 13:11 mic-urs