Skip to content

fix(mcp): refuse create_memory_project path mismatch - #1846

Merged
phernandez merged 3 commits into
mainfrom
fix/1811-create-project-path-mismatch
Oct 24, 2026
Merged

phernandez merged 3 commits into
mainfrom
fix/1811-create-project-path-mismatch

Conversation

@phernandez

Copy link
Copy Markdown
Member

Salvages #1840 by @MbappeWU onto an in-repo branch so CI runs. Their two commits are kept as authored; one commit on top adjusts the fix.

Fixes #1811.

What changes

create_memory_project (and bm_project(command="create"), which calls it) used to answer "✓ Project already exists" when the name matched a project stored at another directory, then re-indexed that project. The requested path was ignored.

  • Same name, same local directory: idempotent, re-indexes, as before.
  • Same name, different local directory: an ALREADY_EXISTS refusal naming the stored path, raised before any indexing.
  • Cloud routing: no path comparison.

Changes on top of #1840

  • Refusal, not an error-shaped result. fix(mcp): refuse create_memory_project path mismatch #1840 returned # Error ... text or an error: PATH_MISMATCH dict as a successful tool result. Every other refusal in this tool raises refusal(...), so this one does too.
  • Local only. Hosted project paths are tenant-relative and derived from the project name (BASIC_MEMORY_PROJECT_ROOT), so a requested path never moves a cloud project. Normalizing it with os.path.abspath on the client resolved it against the MCP process's working directory: a retry with path="manual" for a project stored at /manual would have been refused.

Verification

  • just fast-check: clean.
  • just fast-test over tests/mcp/test_tool_project_management.py, tests/mcp/test_tool_bm_project.py, tests/test_man_pages.py, and the two touched test-int/mcp files: passing.
  • New test: a cloud-routed retry with path="manual" for a stored /manual returns already_exists.

🤖 Generated with Claude Code

https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-24T02:48:55.673005Z bc47bb4 Manual request
ℹ️ 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.

MbappeWU and others added 3 commits October 23, 2026 21:46
Add regression coverage for #1811: same name with a different path
must fail, while the same directory stays idempotent. Update the
manual page and integration cases that previously encoded the bug.

Signed-off-by: MbappeWU <MbappeWU@users.noreply.github.com>
When create_memory_project finds an existing name, compare normalized
paths the same way the API add_project path does. Equal paths keep the
idempotent re-index success. Different paths fail fast with both paths
named and without re-indexing.

Fixes #1811

Signed-off-by: MbappeWU <MbappeWU@users.noreply.github.com>
The mismatch now raises an ALREADY_EXISTS refusal instead of returning an
error-shaped success, matching the other refusals in this tool (C11).

Cloud creates skip the check. Hosted project paths are tenant-relative
and derived from the project name, so a requested path never moves a
cloud project, and normalizing it client-side resolved it against this
process's working directory: a retry with path="manual" for a project
stored at "/manual" would have been refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CoZ3jWnMJsyQsik4tPySk
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez force-pushed the fix/1811-create-project-path-mismatch branch from 5a199fb to bc47bb4 Compare October 24, 2026 02:46
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@phernandez

Copy link
Copy Markdown
Member Author

Rebased onto origin/main at 86c974ec9, which already fixes the Postgres test-isolation failure behind the red shard. Current PR head: bc47bb42677766e1227644fac8e5af5f864f9c81. Contributor authorship and all three signed-off commits are preserved.

The failed job had 12 setup errors in test_postgres_operand_search.py: duplicate search_index_fts_chunks primary keys. The upstream fix drops the dependent chunk table when the integrity test drops search_index, and explicitly resets chunk rows between tests. No additional product change was needed in this PR.

Local verification after rebase:

  • BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest tests/repository/test_index_integrity.py tests/repository/test_postgres_operand_search.py tests/mcp/test_tool_project_management.py tests/mcp/test_tool_bm_project.py -q --no-cov — 91 passed, 4 skipped.
  • uv run pytest tests/mcp/test_tool_project_management.py tests/mcp/test_tool_bm_project.py tests/test_man_pages.py test-int/mcp/test_output_format_json_integration.py test-int/mcp/test_project_management_integration.py -q --no-cov — 157 passed.
  • just typecheck — passed.
  • git diff --check — passed.

Full current-head CI and the fresh Codex review are running. No merge performed.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: bc47bb4267

ℹ️ 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".

@phernandez

Copy link
Copy Markdown
Member Author

Verification complete on bc47bb4: all 31 checks passed, including the formerly failing Postgres unit shard 3/3. Codex reviewed this exact head with no findings and left a thumbs-up at 2026-10-24T02:48:58Z; there are no review threads. The PR is ready to merge. No merge performed.

@phernandez
phernandez merged commit e03c2f2 into main Oct 24, 2026
31 checks passed
@phernandez
phernandez deleted the fix/1811-create-project-path-mismatch branch October 24, 2026 16:53
groksrc added a commit that referenced this pull request Oct 30, 2026
#1989)

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
#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](https://claude.com/claude-code)

---------

Signed-off-by: Drew Cain <groksrc@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

create_memory_project reports success for an existing name with a different path

2 participants