Skip to content

fix: Create memory directory and symlink identity files during workspace setup - #2884

Closed
webdevtodayjason wants to merge 1 commit into
openclaw:mainfrom
webdevtodayjason:fix/ensure-memory-directory-on-setup
Closed

webdevtodayjason wants to merge 1 commit into
openclaw:mainfrom
webdevtodayjason:fix/ensure-memory-directory-on-setup

Conversation

@webdevtodayjason

@webdevtodayjason webdevtodayjason commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Creates memory/ directory during workspace setup when ensureBootstrapFiles is true
  • Symlinks identity files (SOUL.md, USER.md, AGENTS.md, IDENTITY.md) into memory/ so they are indexed by memory search
  • Gracefully handles symlink failures on Windows and preserves existing files

Problem

The memory search system looks for files in ~/clawd/memory/ but workspace setup only created identity files at the workspace root. This caused:

  • clawdbot memory status to report "no memory files found"
  • The AI to incorrectly claim "I have no memories" despite having identity files
  • Users having to manually create the memory/ directory and copy/symlink files

Solution

During ensureAgentWorkspace() with ensureBootstrapFiles: true:

  1. Create memory/ subdirectory
  2. Symlink identity files into it so memory search can index them
  3. Skip if files already exist (preserves user customizations)
  4. Gracefully handle symlink failures (e.g., Windows without privileges)

Test plan

  • Added unit tests for memory directory creation
  • Added test for symlink creation
  • Added test for not overwriting existing files
  • All 6 workspace tests pass
  • Lint passes

🤖 Generated with Claude Code

Greptile Overview

Greptile Summary

This PR updates workspace bootstrapping (src/agents/workspace.ts) to create a memory/ subdirectory during ensureAgentWorkspace({ ensureBootstrapFiles: true }) and attempts to symlink the identity/bootstrap files (SOUL/USER/AGENTS/IDENTITY) into that directory so the memory search subsystem can index them. It also adds unit coverage in src/agents/workspace.test.ts for directory creation, symlink creation, and non-overwrite behavior.

Overall, the change aligns workspace setup with other parts of the codebase (e.g., the memory CLI and internal scanner) which look for memory/ under the workspace directory. The main risks are around cross-platform symlink behavior and the fact that the new memory/ directory is created unconditionally whenever ensureBootstrapFiles is enabled.

Confidence Score: 3/5

  • This PR is likely safe to merge, but has cross-platform test fragility and some silent-failure behavior worth addressing.
  • Core logic is straightforward (mkdir + best-effort symlinks) and scoped to workspace bootstrapping, but the new tests assume symlinks always work and the implementation suppresses all symlink-related errors, which can hide real failures and cause CI issues on Windows or restricted environments.
  • src/agents/workspace.test.ts (symlink assertions on Windows), src/agents/workspace.ts (error swallowing / unconditional mkdir behavior)

(5/5) You can turn off certain types of comments like style here!

…ace setup

The memory search system expects files in ~/clawd/memory/ but workspace setup
only created identity files (SOUL.md, USER.md, AGENTS.md, IDENTITY.md) at the
workspace root. This caused the memory index to report "no memory files found"
even though identity files existed.

Changes:
- Create memory/ directory during ensureAgentWorkspace when ensureBootstrapFiles is true
- Symlink identity files (SOUL.md, USER.md, AGENTS.md, IDENTITY.md) into memory/
  so they are discoverable by the memory search indexer
- Add memoryDir to the return type of ensureAgentWorkspace
- Gracefully handle symlink creation failures (e.g., Windows without privileges)
- Skip symlink creation if target file already exists (preserves user customizations)

Fixes issue where clawdbot would claim "I have no memories" despite having
identity files, because the memory search index was empty.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jan 27, 2026

@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.

2 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/agents/workspace.ts
Comment on lines +180 to +182
// Ensure memory/ directory exists and symlink identity files for memory search indexing
const memoryDir = path.join(dir, DEFAULT_MEMORY_DIR);
await fs.mkdir(memoryDir, { recursive: true });

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.

[P1] ensureAgentWorkspace({ ensureBootstrapFiles: true }) now always creates memory/ even when the workspace isn't brand-new. This can be an unexpected side effect (e.g., consumers calling this just to ensure identity files exist), and it also means the comment/test "does not create memory directory when ensureBootstrapFiles is false" is the only guard. If the intent is "create memory/ only for new workspaces" or "only if memory search is enabled", this should be gated on that condition rather than unconditional mkdir.

This matters when callers use ensureBootstrapFiles: true for reasons unrelated to memory indexing and don't expect new directories to appear.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.ts
Line: 180:182

Comment:
[P1] `ensureAgentWorkspace({ ensureBootstrapFiles: true })` now *always* creates `memory/` even when the workspace isn't brand-new. This can be an unexpected side effect (e.g., consumers calling this just to ensure identity files exist), and it also means the comment/test "does not create memory directory when ensureBootstrapFiles is false" is the only guard. If the intent is "create memory/ only for new workspaces" or "only if memory search is enabled", this should be gated on that condition rather than unconditional `mkdir`.

This matters when callers use `ensureBootstrapFiles: true` for reasons unrelated to memory indexing and don't expect new directories to appear.


How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +59 to +83
describe("ensureAgentWorkspace", () => {
it("creates memory directory with symlinks to identity files", async () => {
const tempDir = await makeTempWorkspace("moltbot-workspace-");

const result = await ensureAgentWorkspace({
dir: tempDir,
ensureBootstrapFiles: true,
});

// Check memory directory was created
expect(result.memoryDir).toBe(path.join(tempDir, DEFAULT_MEMORY_DIR));
const memoryDirStat = await fs.stat(result.memoryDir!);
expect(memoryDirStat.isDirectory()).toBe(true);

// Check symlinks exist in memory directory
const memoryFiles = await fs.readdir(result.memoryDir!);
expect(memoryFiles).toContain(DEFAULT_SOUL_FILENAME);
expect(memoryFiles).toContain(DEFAULT_USER_FILENAME);
expect(memoryFiles).toContain(DEFAULT_AGENTS_FILENAME);
expect(memoryFiles).toContain(DEFAULT_IDENTITY_FILENAME);

// Check symlinks point to correct files
const soulLink = await fs.readlink(path.join(result.memoryDir!, DEFAULT_SOUL_FILENAME));
expect(soulLink).toBe(`../${DEFAULT_SOUL_FILENAME}`);
});

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.

[P1] This test assumes symlinks are created and that readlink() returns ../SOUL.md. On Windows (or environments without symlink privileges) the implementation intentionally swallows symlink failures, so this test will be flaky/fail there. Consider asserting "file exists OR symlink was skipped" (or skipping on Windows) and avoid hard-coding the readlink value.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.test.ts
Line: 59:83

Comment:
[P1] This test assumes symlinks are created and that `readlink()` returns `../SOUL.md`. On Windows (or environments without symlink privileges) the implementation intentionally swallows symlink failures, so this test will be flaky/fail there. Consider asserting "file exists OR symlink was skipped" (or skipping on Windows) and avoid hard-coding the readlink value.


How can I resolve this? If you propose a fix, please make it concise.

Comment thread src/agents/workspace.ts
Comment on lines +192 to +203
for (const { source, target } of identityFilesToSymlink) {
try {
await fs.access(target);
// Target already exists, skip
} catch {
// Target doesn't exist, create symlink
try {
const relativePath = path.relative(memoryDir, source);
await fs.symlink(relativePath, target);
} catch {
// Symlink creation failed (e.g., on Windows without privileges), skip silently
}

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.

[P2] The symlink creation loop swallows all errors from both fs.access(target) and fs.symlink(...), including cases like permission denied to the directory, invalid paths, or partial failures. That can make workspace setup silently incomplete on non-Windows platforms too. At least consider narrowing the catches (e.g., only ignore EEXIST / EPERM / EACCES for symlink creation) or logging at verbose/debug level so users can diagnose why memory indexing isn't seeing identity files.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.ts
Line: 192:203

Comment:
[P2] The symlink creation loop swallows *all* errors from both `fs.access(target)` and `fs.symlink(...)`, including cases like permission denied to the directory, invalid paths, or partial failures. That can make workspace setup silently incomplete on non-Windows platforms too. At least consider narrowing the catches (e.g., only ignore `EEXIST` / `EPERM` / `EACCES` for symlink creation) or logging at verbose/debug level so users can diagnose why memory indexing isn't seeing identity files.


How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +93 to +96
expect(result.memoryDir).toBeUndefined();
const memoryDirPath = path.join(tempDir, DEFAULT_MEMORY_DIR);
await expect(fs.access(memoryDirPath)).rejects.toThrow();
});

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.

[P2] await expect(fs.access(memoryDirPath)).rejects.toThrow() is quite broad: it will pass for any error (including transient permission issues) and doesn't verify it's actually missing. If you want to assert "directory does not exist", check for code === "ENOENT".

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.test.ts
Line: 93:96

Comment:
[P2] `await expect(fs.access(memoryDirPath)).rejects.toThrow()` is quite broad: it will pass for any error (including transient permission issues) and doesn't verify it's actually missing. If you want to assert "directory does not exist", check for `code === "ENOENT"`.


How can I resolve this? If you propose a fix, please make it concise.

@steipete

Copy link
Copy Markdown
Contributor

AI-assisted stale triage closure (2026-02-23).

Closing this PR as stale/conflicted.

Why this is being closed:

  • PR is currently conflicted (DIRTY) and has not been refreshed for current code shape.
  • The workspace/session setup area has moved significantly since this branch was created, making this patch stale to review safely.

This is AI-closed housekeeping, not a rejection of the intended reliability improvement.

If still relevant, please open a new PR from latest main with a minimal rebased diff and link this PR.

@steipete steipete closed this Feb 23, 2026
@steipete

Copy link
Copy Markdown
Contributor

Adding instruction files that are always loaded into the agent context don't need to be in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants