Skip to content

fix(rag): preserve the index when document discovery fails - #21

Merged
ipiton merged 5 commits into
ipiton:mainfrom
glockbender:codex/preserve-index-on-discovery-errors
Nov 17, 2026
Merged

ipiton merged 5 commits into
ipiton:mainfrom
glockbender:codex/preserve-index-on-discovery-errors

Conversation

@glockbender

@glockbender glockbender commented Nov 14, 2026 •

Copy link
Copy Markdown

A temporarily unavailable source should not look like a deletion. Discovery records failures under their logical paths and retains still-included indexed files under those paths. Other paths continue to update. An optional source that has never been indexed, such as a missing CHANGELOG.md, does not block indexing.

The current main integration uses the directory walker from #23. It computes the logical path before handling walk errors and updates the caller to use the documentScan result. New tests cover unreadable subtrees through a configured directory symlink, healthy sibling updates and pruning, and recovery. Explicit exclusions still prune old records, even when a source cannot be read. Adopting a different root cannot relabel unavailable records from the old root. An explicit root replacement removes them.

Validation:

  • make test vet eval
  • go test -race ./internal/rag
  • The linked-subtree test ran on macOS with permissions enforced, alongside the plain-directory case, without skips.
  • Independent code and documentation reviews.
  • Fork CI for the revised branch.

The existing branch incorporates current main and retains its published history. The test fixtures use no downloaded model or private documents.

@ipiton ipiton left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The problem is real — a temporarily unavailable source must not be pruned as deleted. But failing the whole run on any discovery error breaks the default setup. A configured root that doesn't exist is a normal case today: the shipped preset is docs,README.md,CHANGELOG.md, and T97 coverage reports such roots by name. With this PR a project that simply has no CHANGELOG.md can no longer be indexed at all:

engine.docService.config.IndexDirs = []string{"docs", "README.md", "CHANGELOG.md"} // no CHANGELOG.md on disk
err := engine.IndexDocuments(ctx)
// main: nil
// this PR: failed to collect documents: access configured index source ".../CHANGELOG.md": ... no such file or directory

The same applies to the watcher path, and to a single unreadable file or a file removed mid-scan inside a large directory.

Suggested direction: let collectDocuments also return the roots/paths it could not scan, and have the pruning step skip indexed files under those prefixes. A missing root that never had files stays harmless (and keeps the T97 report), a temporarily missing one keeps its records, and an unreadable file is left untouched instead of failing the run. Your existing regression tests (preserved chunks/metadata, retry after restore) fit this model as-is; only the "returns an error" assertions would change to "logs + preserves".

@ipiton

ipiton commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks — the reworked design is exactly what I had in mind, and the new tests cover the cases well. The missing-CHANGELOG.md preset now indexes fine.

#22, #23 and #24 are merged into main. #21 now needs another update from main: besides the docs/CHANGELOG.md conflict, it merges textually with #23 but does not compile:

  1. internal/rag/documents.go: fix(rag): index explicitly configured directory symlinks #23 walks via fs.WalkDir(os.DirFS(fullPath), ".", func(rel string, ...) and declares path := filepath.Join(fullPath, rel) after the error check, while this PR calls unavailable(path, err) inside that check → undefined: path.
  2. internal/rag/directory_symlink_test.go (from fix(rag): index explicitly configured directory symlinks #23) still calls docs, err := ds.collectDocuments(), which no longer matches the new documentScan return value.

Please merge main in, fix both, and make sure the walk-error path records the logical path under a configured directory symlink (worth a test for an unreadable subdirectory inside a linked root). I'll merge once CI is green.

@glockbender

Copy link
Copy Markdown
Author

Updated this branch against current main at 3e6fe5e. The configured symlink walker now computes the logical path before handling walk errors, and the symlink test uses the new documentScan return value.

The new regression runs both a plain directory and a configured symlink. It verifies that an unreadable subtree is recorded as docs/hidden, its indexed chunks are retained, and healthy sibling updates and deletions still apply. The test also checks recovery when access returns. The additional regressions cover explicit exclusions and index-root changes.

make test vet eval and go test -race ./internal/rag passed. The focused linked-subtree case ran with filesystem permissions enforced and was not skipped.

All five upstream GitHub checks passed on 3ae9c3b.

@ipiton
ipiton merged commit a920915 into ipiton:main Nov 17, 2026
5 checks passed
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