Skip to content

memory: index symlinked dirs/files (PARA notes symlink) - #11424

Closed
EffieFalcon wants to merge 1 commit into
openclaw:mainfrom
EffieFalcon:fix/memory-follow-symlinks
Closed

EffieFalcon wants to merge 1 commit into
openclaw:mainfrom
EffieFalcon:fix/memory-follow-symlinks

Conversation

@EffieFalcon

@EffieFalcon EffieFalcon commented Feb 7, 2026 •

Copy link
Copy Markdown

Problem

memory_search indexes MEMORY.md + memory/**/*.md but the file walker skips symlinks. This breaks the PARA Second Brain “symlink trick” (memory/notes -> notes), so notes/** never gets indexed.

Change

  • Follow symlink targets during the directory walk:
    • if a symlink resolves to a directory, recurse into it
    • if a symlink resolves to a .md file, include it
  • Also follow symlinked extraPaths entries (dir or single .md).
  • Add a realpath-based visited set to prevent symlink cycles.
  • Update unit test accordingly.

Why safe

  • Only follows symlinks that resolve; broken symlinks are ignored.
  • Cycle protection prevents infinite recursion.

Repro

  1. ln -s $(pwd)/notes $(pwd)/memory/notes
  2. create notes/resources/foo.md
  3. openclaw memory index
  4. search for content from foo.md — it should now be indexed.

Greptile Overview

Greptile Summary

This PR updates listMemoryFiles/walkDir to follow symlink targets when indexing markdown memory notes (including symlinked extra paths), and adjusts the unit test to assert that linked .md files 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 configured extraPaths, while attempting to prevent infinite recursion via a realpath-based visited set.

Confidence Score: 3/5

  • This PR is close to mergeable, but symlink cycle protection has gaps that can still lead to infinite recursion in some setups.
  • Core behavior change (following symlinks) is reasonable and tests were updated, but the new cycle guard can be bypassed when realpath fails and it is not consistently shared across all walkDir entry points (notably symlinked extraPaths). Those are correctness issues that can cause hangs during indexing.
  • src/memory/internal.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/memory/internal.ts
Comment on lines +57 to +65
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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/memory/internal.ts
Comment on lines 136 to 148
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@gumadeiras

Copy link
Copy Markdown
Member

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.

https://docs.openclaw.ai/concepts/memory#additional-memory-paths

you could write a little script that traverses symlinks in your setup and generate a list of paths so you can easily add them

@gumadeiras gumadeiras closed this Feb 13, 2026
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