Skip to content

fix(integrations): reuse an existing OpenClaw project stored elsewhere - #1989

Merged
groksrc merged 3 commits into
mainfrom
fix/1988-openclaw-existing-project
Oct 30, 2026
Merged

groksrc merged 3 commits into
mainfrom
fix/1988-openclaw-existing-project

Conversation

@groksrc

@groksrc groksrc commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #1988. With this change, the OpenClaw plugin starts on Basic Memory 1.0 when its project already exists in a different folder. Before, every plugin tool failed, including reads and list_memory_projects.

The bug

At startup the plugin calls bm_project(command="create") with its project name and projectPath. projectPath defaults to the workspace root. Since #1846, BM refuses a same-name create at a different path with ALREADY_EXISTS. Before #1846 it reused the project by name.

The refusal failed startup. Every tool call waits on startup, and the retry sent the same create, so every tool call failed. The default projectPath has changed between plugin releases ("." and ~/.basic-memory/openclaw/), so upgrading can trigger this with no config change.

What changes

  • projectPath not set (bm-client.ts, startupProjectPath): startup lists projects. If a row with the plugin's name has a local_path, it creates the project at that folder, which BM treats as idempotent. Cloud-only rows are skipped, because their paths are tenant-relative. One info line names the folder used.
  • projectPath set and mismatched: the plugin keeps the refusal, because the user chose that path. The refusal no longer fails startup:
    • Calls routed to the plugin's project throw a ProjectUnavailableError carrying the refusal, which names both paths. Calls that name another project, by name or by project_id, still reach BM. It isn't a BmToolError, because writeNote would read its ALREADY_EXISTS as an existing note.
    • listProjects and listWorkspaces still work, so the user can see where the project is stored.
    • Memory health() reports unavailable with the refusal text, instead of ready.
  • Only structured refusals are kept. A plain tool failure, such as a locked database, still fails startup, and the next tool call retries it as before.
  • config.ts gains projectPathConfigured, which tells the default apart from an explicit ".".
  • Docs: the README and BASIC_MEMORY.md now describe how projectPath resolves. BASIC_MEMORY.md wrongly said it defaulted to memoryDir and had to be absolute.

Regression tests

  • bm-client.test.ts, "an existing project at another folder":
    • Adopts the stored folder.
    • Creates at the default path when no project has the name.
    • Keeps a configured path, reports the refusal, and still lists projects.
    • Retries a create that failed without a refusal.
  • basic-memory-capability.test.ts: health reports the refused project as unavailable.
  • integration/bm-client.integration.test.ts: the same two startup cases against a real bm mcp from this checkout, so they exercise fix(mcp): refuse create_memory_project path mismatch #1846's server-side refusal.

The three regression unit tests fail when run against the old bm-client.ts and capability code, and pass with this change.

Verification

  • just package-check-openclaw: exit 0, 286 tests pass (typecheck, lint, build, npm pack --dry-run).
  • bun run test:int (real bm mcp): both new tests pass.
  • Known failure: the existing test "round-trips Memory Quest fields" fails. It asserts the text "Note already exists", but the tool now returns "A note already exists at ...". It fails the same way with this PR's source changes reverted, and this PR doesn't touch tools/. CI doesn't run the integration suite, which is probably why nobody has noticed.
  • Live gateway: verified on OpenClaw 2026.10.9 with 5c5d0da6 and bm 1.0.0. The old build reproduces the bug, and this build fixes it. Details are in the PR comment with the live results.

🤖 Generated with Claude Code

The OpenClaw plugin stopped working on Basic Memory 1.0 when its project
already existed at a folder other than the configured one. Startup asks
bm_project to create the project at projectPath, which defaults to the
workspace root. Since #1846, BM refuses a same-name create at a different
path with ALREADY_EXISTS. Startup failed, and every tool call, including
project listing, failed with it.

- projectPath unset: startup looks up a project with the plugin's name and
  creates it at the stored folder, which BM treats as idempotent. The
  default has changed between plugin releases, so upgrades hit this.
- projectPath set and mismatched: the refusal stands, but it no longer
  fails startup. Project-scoped calls report it, listing still works, and
  memory health reports the project as unavailable. Transient tool
  failures still fail startup so the next call retries them.
- Docs: describe how projectPath resolves; BASIC_MEMORY.md wrongly said it
  defaulted to memoryDir.

Regression tests cover both cases against a stubbed BM, the health
report, transient-failure retry, and both cases against a real bm mcp.

Fixes #1988

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T03:36:51.621176Z abb2962 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: abb2962597

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread integrations/openclaw/bm-client.ts Outdated
command: "list",
output_format: "json",
}),
).find((project) => project.name.toLowerCase() === name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Select the local project row before adopting its path

When cloud credentials expose identically named projects in multiple workspaces, the first name match need not represent the local project. In project_management.py, _merge_workspace_projects sorts the cloud-default workspace first, but _select_attached_cloud_entry can attach the local path to a later row based on the project's configured workspace. Consequently, this lookup can adopt a cloud-only row's tenant-relative path even when the local project already exists at the workspace root. The subsequent local create then returns ALREADY_EXISTS, disabling previously working memory operations. Select the row carrying the local path for local startup, rather than treating the first merged name match as the target backend's project.

AGENTS.md reference: integrations/openclaw/AGENTS.md:L86-L86

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed and fixed in 6dff6f3.

_merge_workspace_projects (project_management.py:101-200) emits one row per workspace for a name. Only the row that _select_attached_cloud_entry picks carries local_path, and a cloud-only row's path is tenant-relative. The server's create compares against the local project list, so the first name match could send a cloud path to a local create and get ALREADY_EXISTS.

Startup now matches only rows with a non-null local_path and creates at that path. A name that exists only in the cloud falls back to the configured path, which is the pre-PR behavior.

Two regression tests in bm-client.test.ts:

  • "adopts the local row, not a cloud-only row of the same name": a cloud-only row sorts first.
  • "creates at the default path when only a cloud row has the name".

Both fail on abb2962 and pass now. just package-check-openclaw: 285 pass. The real-bm integration tests for this PR still pass.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed with an isolated probe of abb2962: when a cloud-only row preceded a local+cloud row with the same name, startupProjectPath selected the cloud-only path. Commit 6dff6f3 now selects the matching row's local_path, which addresses this finding on code inspection. I have not run the full suite or validated this on a live OpenClaw gateway.

With cloud credentials, bm_project list returns one row per workspace for
a project name, sorted by workspace priority. Only the row attached to
the local project carries local_path; a cloud-only row's path is
tenant-relative. Startup took the first name match, so it could pass a
cloud path to a local create, which BM refuses with ALREADY_EXISTS.

Match only rows with local_path and create at that path. A name that
exists only in the cloud falls back to the configured path, as before.

Addresses the Codex review on #1989.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>

@groksrc groksrc left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The path-selection finding is addressed in 6dff6f3. One remaining P2 finding concerns calls that explicitly target another project. Validation used isolated probes of the client source with mocked transport; the full suite and a live OpenClaw gateway were not tested.

Comment thread integrations/openclaw/bm-client.ts Outdated
args: Record<string, unknown>,
): Promise<unknown> {
await this.waitForStartup()
if (this.projectSetupError) throw this.projectSetupError

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[P2] Scope the saved setup refusal to the affected project

This unconditional guard rejects every content call when the plugin's project setup was refused, including calls with an explicit project or project_id targeting a different, healthy project. Listing projects succeeds, but selecting one of those projects still throws the unrelated startup refusal before contacting BM.

I reproduced this with the client source at abb2962: after a mocked ALREADY_EXISTS response during startup, readNote("other", { projectId: "other-project-uuid" }) threw the saved setup error and forwarded zero read calls. The guard remains unconditional in 6dff6f3.

Please apply the saved refusal only to calls targeting the unavailable plugin project, and add coverage showing that reads and writes to an explicitly selected healthy project still reach BM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed and fixed in 5c5d0da.

callTool now throws the saved refusal only when args.project names the plugin's project, matched case-insensitively as BM matches names. Calls that name another project by name or by project_id reach BM. Every callTool call sets args.project, either through routedProject() or through routing().

Writing the requested test turned up a second bug. writeNote treats any ALREADY_EXISTS BmToolError as an existing note. So a write to the refused project told the agent "note already exists" instead of explaining the project problem. The refusal is now thrown as a separate ProjectUnavailableError, whose message names the project and BM's reason. projectUnavailableReason() and the health check still report BM's text.

Coverage, in bm-client.test.ts under "lets calls that name another project through after a refusal":

  • After a refused startup, readNote(..., { projectId }) and writeNote(..., "other-project") both reach BM.
  • Default-routed and differently-cased plugin-project calls are still refused without contacting BM.

The test fails on 6dff6f3 and passes now. just package-check-openclaw: 286 pass. The real-bm integration tests for this PR pass. The one integration failure is the Memory Quest text assertion, which fails on main too (noted in the PR description). Still not run on a live OpenClaw gateway.

After BM refused the plugin's project at startup, every content call threw
that refusal, including calls naming another healthy project by name or
id. The guard now applies only to calls routed to the plugin's project,
matched case-insensitively as BM matches names.

The refusal is now thrown as ProjectUnavailableError instead of the raw
BmToolError. writeNote reads an ALREADY_EXISTS BmToolError as an existing
note, so a write to the refused project reported "note already exists"
instead of the project problem.

Addresses the second review finding on #1989.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
@groksrc

groksrc commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Verified on a live OpenClaw gateway: the old build reproduces #1988, and this PR's build (5c5d0da6) fixes it.

Setup. The tests ran on drew-tests with OpenClaw 2026.10.9 and bm 1.0.0 from this branch. The test config matches the report:

  • The project is openclaw-test, with no projectPath, so the plugin defaults to the workspace root, ~/.openclaw/workspace.
  • The existing project is stored at ~/.basic-memory-openclaw-test/project.

Before: the old plugin build. The bug reproduces.

  • openclaw gateway call memory.search fails:
    BM MCP tool bm_project failed: {"error": "ALREADY_EXISTS", "message": "Project 'openclaw-test' already exists at /Users/drew/.basic-memory-openclaw-test/project, not /Users/drew/.openclaw/workspace." ...}
  • memory.status returns unavailable with the message "Basic Memory is not reachable". That is misleading, because BM is running.

After: this PR's build, same config.

  • The gateway log shows using existing project "openclaw-test" at /Users/drew/.basic-memory-openclaw-test/project.
  • memory.status returns ready.
  • memory.search for "Quillfeather" returns openclaw-test/conversations/conversations-2026-10-29.
  • An agent turn ran list_memory_projects, search_notes, write_note, read_note and delete_note. All five worked against the stored project.

Explicit projectPath that doesn't match. Here projectPath is set to ~/.openclaw/workspace.

  • memory.status returns unavailable, with the message ALREADY_EXISTS: Project 'openclaw-test' already exists at /Users/drew/.basic-memory-openclaw-test/project, not /Users/drew/.openclaw/workspace.
  • search_notes with no project fails with Basic Memory project "openclaw-test" is unavailable: ALREADY_EXISTS: .... It is not misreported as an existing note.
  • list_memory_projects still works.
  • search_notes with project: "openclaw-fresh" returns results.

Not covered. The cloud-row selection from the first review finding was tested only against stubbed project lists, not against a real cloud account.

Seen, not changed. list_memory_projects still marks another project (openclaw-fresh) as the default. The cause is in the server: bm_project create returns early for an existing project and ignores set_default. That predates this PR. The plugin always routes by explicit project name, so its calls are unaffected.

The gateway's original config is restored. The PR build is still installed on drew-tests.

@groksrc
groksrc merged commit 727a470 into main Oct 30, 2026
28 checks passed
@groksrc
groksrc deleted the fix/1988-openclaw-existing-project branch October 30, 2026 04:03
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.

OpenClaw plugin fails all tools when its project already exists at a different path (1.0.0, after #1846)

1 participant