fix: use relative paths for index keys to support shared worktree indexes#5
Merged
giancarloerra merged 1 commit intogiancarloerra:mainfrom Mar 16, 2026
Conversation
9ee8f46 to
c03d19c
Compare
…exes When SOCRATICODE_PROJECT_ID is set to share a Qdrant collection across git worktrees, the indexer still used absolute paths as keys in the file hash map, chunk IDs, and for deleting file chunks. This caused every worktree to see all files as "new" and trigger a full re-index, defeating the purpose of the shared project ID feature. Switch all internal keying from absolute paths to relative paths: - chunkId() now hashes on relativePath for stable IDs across worktrees - File hash map (change detection) keyed by relativePath - deleteFileChunks() filters on relativePath Qdrant field - Deleted file detection uses relative path sets Absolute paths are now only used for actual file I/O (stat, readFile).
c03d19c to
505fbd7
Compare
Owner
|
Thanks, cstuncsik, once again, clean implementation and very good idea, much appreciated! |
Contributor
Author
|
You're welcome Thank you for your project, I really like it I also wanted to solve the same problem couple of months ago and made a proof of concept but then I just forgot about it |
Owner
|
I think somehow it remained a problem even if there are a lot of products around trying to do it. Interesting you were also starting to solve it...well thanks for contributing with your ideas, the worktrees was an important missing one! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
SOCRATICODE_PROJECT_IDenv var (added in #2) allows multiple directories to share a single Qdrant collection, which is essential for git worktree workflows. However, sharing the collection alone isn't enough — the indexer internally keys everything by absolute path:/Users/me/n8n/packages/cli/src/foo.ts)chunkId(filePath, startLine)deleteFileChunks(): filters Qdrant by thefilePathpayload field (absolute)This means when a worktree at
/tmp/worktree-xyz/shares the same collection as/Users/me/n8n/:The
SOCRATICODE_PROJECT_IDfeature effectively becomes useless for its primary use case.Solution
Switch all internal keying from absolute paths to relative paths. The
relativePathis already computed everywhere (viaglob("**/*", { absolute: false })), just not used as the canonical key.Changes
src/services/indexer.ts:chunkId()— hash onrelativePathinstead of absolutefilePath, producing stable IDs across worktreesindexProject()— hash mapget/set/hasall userelativePath; deleted file detection uses relative path setupdateProjectIndex()— same pattern of changeschunkByAstRegions,chunkByLines,chunkByCharacters,chunkFileContent) — passrelativePathtochunkId()getProjectHashes()detects absolute-path keys in existing indexes and transparently converts them to relative paths on load — no manual re-index neededsrc/services/qdrant.ts:deleteFileChunks()— filter onrelativePathQdrant field instead offilePathAbsolute paths are now only used for actual file I/O (
fsp.stat(),fsp.readFile()).Backward compatibility
Existing indexes with absolute-path hash keys are automatically migrated to relative paths when loaded. The migration is transparent and one-time — after the first checkpoint/save, the hash map is persisted with relative keys. No manual re-index required.
Test plan
chunkId()produces identical IDs regardless of absolute path prefixdeleteFileChunks()to use relative pathSOCRATICODE_PROJECT_ID