Repository navigation
memory: index symlinked dirs/files (PARA notes symlink) - #11424
EffieFalcon wants to merge 1 commit into
Conversation
| async function walkDir(dir: string, files: string[], visitedRealDirs = new Set<string>()) { | ||
| // Prevent symlink cycles (e.g. notes -> memory/notes -> notes) | ||
| try { | ||
| const real = await fs.realpath(dir); | ||
| if (visitedRealDirs.has(real)) { | ||
| return; | ||
| } | ||
| visitedRealDirs.add(real); | ||
| } catch { |
There was a problem hiding this comment.
Cycle guard can be bypassed
If fs.realpath(dir) fails (e.g., permission error / transient FS error), walkDir skips adding the directory to visitedRealDirs and continues walking it anyway. With symlinks present, that can reintroduce infinite recursion because the cycle protection becomes a no-op on the failing segment. Consider treating realpath failures as “do not descend” (or at least still track a stable key like the unresolved path) so a symlink loop can’t spin forever under partial-permission setups.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/memory/internal.ts
Line: 57:65
Comment:
**Cycle guard can be bypassed**
If `fs.realpath(dir)` fails (e.g., permission error / transient FS error), `walkDir` skips adding the directory to `visitedRealDirs` and continues walking it anyway. With symlinks present, that can reintroduce infinite recursion because the cycle protection becomes a no-op on the failing segment. Consider treating realpath failures as “do not descend” (or at least still track a stable key like the unresolved path) so a symlink loop can’t spin forever under partial-permission setups.
How can I resolve this? If you propose a fix, please make it concise.| try { | ||
| const stat = await fs.lstat(inputPath); | ||
| if (stat.isSymbolicLink()) { | ||
| // Follow symlinked extra paths (directories or single markdown files) | ||
| try { | ||
| const st = await fs.stat(inputPath); | ||
| if (st.isDirectory()) { | ||
| await walkDir(inputPath, result); | ||
| } else if (st.isFile() && inputPath.endsWith(".md")) { | ||
| result.push(inputPath); | ||
| } | ||
| } catch {} | ||
| continue; |
There was a problem hiding this comment.
Symlinked extra dir lacks cycle set
In the extraPaths handling, when inputPath is a symlink to a directory you call walkDir(inputPath, result) without passing a shared visitedRealDirs set. That means symlink cycles reachable via extraPaths won’t be detected across recursive calls (each walkDir creates its own set), so a loop like extra -> ../extra can recurse indefinitely. Pass a shared visitedRealDirs from listMemoryFiles into all walkDir invocations (including the symlink-following branch).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/memory/internal.ts
Line: 136:148
Comment:
**Symlinked extra dir lacks cycle set**
In the `extraPaths` handling, when `inputPath` is a symlink to a directory you call `walkDir(inputPath, result)` without passing a shared `visitedRealDirs` set. That means symlink cycles reachable via `extraPaths` won’t be detected across recursive calls (each `walkDir` creates its own set), so a loop like `extra -> ../extra` can recurse indefinitely. Pass a shared `visitedRealDirs` from `listMemoryFiles` into all `walkDir` invocations (including the symlink-following branch).
How can I resolve this? If you propose a fix, please make it concise.|
additional memory paths does not accept symlinks and require explicit paths by design to mitigate security concerns. It already reads markdown files recursively for whatever paths you add. you could write a little script that traverses symlinks in your setup and generate a list of paths so you can easily add them |
Problem
memory_searchindexesMEMORY.md+memory/**/*.mdbut the file walker skips symlinks. This breaks the PARA Second Brain “symlink trick” (memory/notes -> notes), sonotes/**never gets indexed.Change
.mdfile, include itextraPathsentries (dir or single.md).Why safe
Repro
ln -s $(pwd)/notes $(pwd)/memory/notesnotes/resources/foo.mdopenclaw memory indexfoo.md— it should now be indexed.Greptile Overview
Greptile Summary
This PR updates
listMemoryFiles/walkDirto follow symlink targets when indexing markdown memory notes (including symlinked extra paths), and adjusts the unit test to assert that linked.mdfiles and linked directories are included.The change fits into the memory indexing pipeline by expanding the set of markdown files discovered under
MEMORY.md,memory/, and configuredextraPaths, while attempting to prevent infinite recursion via a realpath-based visited set.Confidence Score: 3/5
realpathfails and it is not consistently shared across allwalkDirentry points (notably symlinkedextraPaths). Those are correctness issues that can cause hangs during indexing.(2/5) Greptile learns from your feedback when you react with thumbs up/down!