Repository navigation
fix(memory): support symlinks in memory file discovery - #2961
kira-ariaki wants to merge 2 commits into
Conversation
walkDir now follows symbolic links using fs.stat() to determine if the target is a file or directory. This enables: - Symlinked markdown files inside memory/ to be indexed - Symlinked directories inside memory/ to be traversed - Graceful handling of dangling symlinks (silently skipped) Fixes an issue where dirent.isFile() returned false for symlinks, causing them to be excluded from memory search indexing. Cross-platform notes: - Works on Linux/macOS/Windows (symlink support varies by platform) - Windows may require elevated permissions to create symlinks, but reading existing symlinks works without special privileges
|
Symlinking outside of the workspace could introduce a number of problems in terms of security, recurrence, and scoping. Would it maybe be better to add support for custom search paths and force the user to add them manually? Adding explicit, user‑configured search paths is safer than automatically following arbitrary symlinks |
|
Thanks for the feedback! You raise a valid point about security considerations. A few thoughts:
That said, I agree that explicit search paths could be a nice enhancement for power users who want more control. Would you prefer that as a follow-up PR, or should we gate symlink traversal behind a config flag (e.g., |
Yes, but it can lead to unwanted situations where the user thinks it’s symlinking a single directory, but that directory could also contain symlinks, resulting in unwanted/insecure behavior. Or a simple attack where a symlink is created in the workspace to give it access to things outside of the workspace. We could think about hierarchical symlinking in terms of allowing Let's put a pin on the symlinking for a couple of days and i'll get back on this after we've discussed implications Could you do a follow up PR for explicit search paths? thanks! |
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to #2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
| it("includes symlinked markdown files", async () => { | ||
| const tempDir = await makeTempDir(); | ||
| const memoryDir = path.join(tempDir, "memory"); | ||
| await fs.mkdir(memoryDir); | ||
|
|
||
| // Create a real file outside memory/ | ||
| const realFile = path.join(tempDir, "notes.md"); | ||
| await fs.writeFile(realFile, "# Notes\nSome content"); | ||
|
|
||
| // Create a symlink inside memory/ pointing to the real file | ||
| const symlinkPath = path.join(memoryDir, "linked-notes.md"); | ||
| await fs.symlink(realFile, symlinkPath); | ||
|
|
||
| const files = await listMemoryFiles(tempDir); | ||
| expect(files).toContain(symlinkPath); | ||
|
|
||
| // Cleanup | ||
| await fs.rm(tempDir, { recursive: true }); | ||
| }); |
There was a problem hiding this comment.
[P1] Tests may be flaky on Windows/CI where creating symlinks is restricted.
These tests call fs.symlink(...) directly; on Windows this often requires Developer Mode or elevated privileges, so CI or many dev setups will fail even though runtime symlink reading works. It’s usually safer to detect symlink support and it.skip() (or expect a specific error) when symlink creation isn’t permitted.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/memory/internal.test.ts
Line: 13:31
Comment:
[P1] Tests may be flaky on Windows/CI where creating symlinks is restricted.
These tests call `fs.symlink(...)` directly; on Windows this often requires Developer Mode or elevated privileges, so CI or many dev setups will fail even though runtime symlink *reading* works. It’s usually safer to detect symlink support and `it.skip()` (or `expect` a specific error) when symlink creation isn’t permitted.
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
Because Consider guarding against this by tracking visited realpaths (or inodes) for directories you recurse into and/or rejecting symlink targets whose resolved path is outside Prompt To Fix With AIThis is a comment left during a code review.
Path: src/memory/internal.ts
Line: 49:66
Comment:
[P0] Following symlinks can recurse infinitely (symlink loops) and/or escape the `memory/` subtree.
Because `walkDir` now calls `fs.stat()` and then recurses into `full` when the symlink points to a directory, a symlink like `memory/loop -> memory/` (or any parent/ancestor) will cause unbounded recursion. Similarly, a symlink like `memory/out -> /` will traverse outside the intended workspace memory area.
Consider guarding against this by tracking visited realpaths (or inodes) for directories you recurse into and/or rejecting symlink targets whose resolved path is outside `memoryDir`.
How can I resolve this? If you propose a fix, please make it concise. |
- Add canCreateSymlinks() sync helper to detect symlink capability - Use it.skipIf(!symlinksAvailable) for all symlink-related tests - Tests will be skipped instead of failing on Windows/CI without admin rights Addresses greptile P1 feedback on PR openclaw#2961
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
|
Closing as duplicate of #11424. If this is incorrect, comment and we can reopen. |
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
…A7 pin caught it; would fail every live Tier-2 turn) — bind byte/type-exact to SJ's VERBATIM mint (openclaw#2961). checkClaims branches on tier: Tier-2 binds channel-claim===requested + tier===2 (JSON number) + sub present-non-empty recorded as user_scope (NOT the composed value — SJ resolves it to the bare Clerk id via passcode linkage) + act.sub===machineSub; Tier-1 sub===externalId + tier===1 (number, no channel — absent on Tier-1). Cache still keyed on request identity (cross-user isolation intact). Red-first + exact-type tests (tier:'2' string REJECTED, tier-confusion REJECTED, Tier-1 no-channel ACCEPTED). 202 tests green QGR-Finding: A7-tier2-binding Generated-With: Claude Code Co-Authored-By: cto <[email protected]> Co-Authored-By: Claude <[email protected]>
Add a `paths` option to `memorySearch` config, allowing users to explicitly specify additional directories or files to include in memory search. Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following symlinks (which has security implications), users can now explicitly declare additional search paths. - Add `memorySearch.paths` config option (array of strings) - Paths can be absolute or relative (resolved from workspace) - Directories are recursively scanned for `.md` files - Single `.md` files can also be specified - Paths from defaults and agent overrides are merged - Added 4 test cases for listMemoryFiles
Summary
walkDirnow follows symbolic links usingfs.stat()to determine if the target is a file or directory. This enables:memory/to be indexedmemory/to be traversedProblem
The current
walkDirimplementation usesdirent.isFile()to check if an entry is a file. However, for symbolic links,dirent.isFile()returnsfalse(the dirent type is "symbolic-link", not "file"), causing symlinks to be excluded from memory search indexing.This is especially relevant for:
memory/Solution
For entries that are symbolic links, we now call
fs.stat()(which follows symlinks) to determine the actual target type:Cross-platform notes
Test plan
Related: #2884
Greptile Overview
Greptile Summary
This PR updates
walkDirinsrc/memory/internal.tsto treat symlink entries specially bystat()ing them (following the link) so symlinked.mdfiles and symlinked directories undermemory/are included inlistMemoryFiles()results, while dangling symlinks are skipped. It also adds Vitest coverage insrc/memory/internal.test.tsfor symlinked file discovery, symlinked directory traversal, and dangling symlink handling.Confidence Score: 3/5
memory/if users add cyclic or external symlinks. The added tests also directly create symlinks, which can fail on Windows or restricted CI environments, reducing confidence without conditional skipping.(5/5) You can turn off certain types of comments like style here!