codescout icon indicating copy to clipboard operation
codescout copied to clipboard

Semantic index can complete while omitting the documentation corpus

Open mic-urs opened this issue 3 months ago • 1 comments

$## Summary\nA local SQLite-vec semantic index can report completion and be queryable while storing no docs/ paths. This makes semantic-search results look healthy but excludes project documentation.\n\n## Observed\nOn a repository checkout with 1,086 tracked documentation files and no configured ignored paths, the active index reported 486 indexed files and 21,557 chunks. Direct inspection of the code_chunk metadata table found:\n\n- docs/: 0 distinct indexed files\n- scripts/: 2 distinct indexed files (19 tracked)\n- src/: 298 distinct indexed files\n- tests/: 153 distinct indexed files\n\nA representative documentation file was not ignored by Git.\n\n## Expected behavior\nAll readable, supported, non-ignored files discovered by the index walk should be represented in the persisted index. At minimum, a successful index must not claim completion when an entire eligible top-level directory has zero stored files.\n\n## Existing evidence\nThe isolated lower-level checks already pass:\n\n- indexable_files sees Markdown under docs/;\n- stream_index stores a temporary Markdown document;\n- a full-checkout stream_index test sends docs/ chunks to a recording store.\n\nThis narrows the defect to the live indexing path rather than Markdown recognition, chunking, SQLite-vec persistence in isolation, or the local ONNX embedder in isolation.\n\n## Likely seam to investigate\nInstrument the path from index(action="build") through its background task and RetrievalClient::sync_project with per-directory/per-language counters for: enumerated, unreadable, chunked, submitted for embedding, successfully embedded, stored, and pruned. Capture the resolved root and ignore patterns at job start.\n\n## Regression coverage requested\nAdd an integration test that invokes the same asynchronous tool path as index(action="build") against a temporary checkout containing src/, docs/, and scripts/, then asserts persisted file paths in the final store. A direct stream_index unit test alone does not cover this failure mode.\n\n## Impact\nDocumentation, trackers, and design decisions can be invisible to semantic search while status remains confidence-inducing.

mic-urs avatar Aug 26 '26 07:08 mic-urs

Fixed — and the cause turned out to be different from every candidate in the issue, which is worth writing down because your own evidence is what ruled them out.

Fix: a5f8e5ad (patch-id f248f9e159cf60f848ddf487182f3dc3125ba21b) — "stop one oversized chunk from truncating the whole index build". Companions: e5821fec (index(action="verify")) and 196f1b94 (durable skip marker read back in status).

It was not a filter. We checked every mechanism you listed — extension allowlist ("md" | "mdx" => "markdown", never removed), gitignore/ignored_paths handling (fail-soft, so it cannot over-prune), ALWAYS_SKIP_DIRS (.git, .codescout only), language detection, project-root resolution, and a max-file-size cap (there is none). None of them excluded docs/.

It was an abort. POST /v1/embeddings rejects the whole request when a single member exceeds the model's context ceiling, so one oversized chunk failed its entire flush batch and then aborted the walk through ?. Batches already flushed stayed committed — so the result was a durably truncated index that index(action="status") called healthy, its only check being a non-zero chunk count. A directory sorting late in the walk order is exactly what disappears.

That is also why your three isolated checks all passed, and that observation was the useful part of the report: none of them used an embedder with a context ceiling, so the aborting condition was inexpressible in them. The missing ingredient was a fixture (CeilingEmbedder), not a test level.

Now: flush_pending isolates a failed batch into one request per chunk, stores what embeds, and reports the rest through a skipped channel with the per-chunk cause — while still aborting loudly on a genuinely dead embedder, discriminated by a minimal probe. Your stated minimum bar ("must not claim completion when an entire eligible top-level directory has zero stored files") shipped as empty_eligible_dirs in index(action="verify").

Regression coverage: one_oversized_chunk_is_skipped_and_the_rest_of_the_walk_still_indexes (asserts conservation — added + skipped == control_added against a healthy-embedder control over the identical tree), a_dead_embedder_aborts_instead_of_skipping_every_chunk, and verify_names_an_eligible_directory_the_index_holds_nothing_for, which reconstructs your exact reported shape (src/ populated, docs/ at zero).

Verified not reproducible today on this checkout: index(action="verify") returns expected_files: 2266, stored_files: 2265, empty_eligible_dirs: [], the single miss being a file added one commit after the last index. docs/ is now the largest indexed directory in the corpus.

One gap you asked for that is still open: the integration test at the index(action="build") tool layer does not exist — all regression coverage sits at the stream_index / verify_index_coverage level, which is the level you explicitly said would not cover it. The counter-argument is sound (the level was never the problem, the ceiling-bearing fixture was), but your stated ask is unmet and worth saying so plainly.

Internally: docs/issues/archive/2026-08-26-index-status-claims-complete-without-checking-coverage.md and .../2026-08-26-dense-embedder-slot-context-drops-large-embeds.md.

mareurs avatar Sep 15 '26 08:09 mareurs