Skip to content

fix(core): keep projects under a shared root top-level - #1598

Merged
phernandez merged 2 commits into
mainfrom
project-root-top-level-names
Sep 22, 2026
Merged

phernandez merged 2 commits into
mainfrom
project-root-top-level-names

Conversation

@phernandez

Copy link
Copy Markdown
Member

Why

Cloud stores each project under its own top-level prefix in the tenant bucket, and deletes a project by purging that prefix. The prefix is generate_permalink(name), and generate_permalink keeps /. So a project named Research/2026 would sit inside research/, and purging "Research" would delete it too.

Core already prevents overlapping project directories: add_project refuses nested paths. Cloud can't call add_project, though. It needs a race-safe INSERT ... ON CONFLICT, an inactive insert for invite-only projects, a caller-supplied external ID for keyed retries, the OKF seed in the same transaction, and no local config.json writes (see basic-memory-cloud#1763). So Cloud copied the insert and dropped the rules.

What changed

  • New project_permalink(name, *, top_level) in services/project_service.py returns the permalink that addresses a new project, or raises ValueError.
  • add_project calls it with top_level= set by whether a project root is configured. Under BASIC_MEMORY_PROJECT_ROOT the permalink is already the project's directory name, so this mode was meant to be flat ("ensures flat structure"). Local projects without a project root still accept / in names.
  • Cloud will call the same function when it creates projects, pulled in with the next dependency bump (basic-memory-cloud#2117).

Testing

  • project_permalink: a single-segment name passes top-level, a slash name passes locally, and a slash name is refused top-level.
  • add_project under a real BASIC_MEMORY_PROJECT_ROOT refuses Research/2026 and creates nothing.
  • Confirmed the tests catch the bug: disabling the top-level check fails both new tests.
  • just fast-check passes. Project service and API project tests: 123 passed. Project-root, index, and CLI suites: 1182 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015y5WHPT9CNQp1RAttVFuFT

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 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-09-22T23:20:01.964373Z aaf0721 New commits
ℹ️ 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: 8aa632d212

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

# it with the project, would then reach into the nested one.
# Outcome: projects under a shared root stay one directory deep. Local
# projects choose their own paths and may still use '/' in their names.
if top_level and "/" in permalink:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject dot segments as top-level project permalinks

When the project name is . (or otherwise normalizes to .), this check accepts it because the permalink contains no slash. With a configured project root, (base_path / ".").resolve() is the shared root itself, so the project does not own a top-level child directory; removing it with delete_notes=True recursively deletes the shared root and any canonical note content stored there. Reject . and .., or validate that the resolved project path is a strict direct child of the root.

AGENTS.md reference: AGENTS.md:L156-L160

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 e0c9830. generate_permalink keeps periods and only strips hyphens from segment edges, so . and .. passed the empty-segment check, and under a project root root / "." resolves to the root itself. Every segment now has to contain something other than dots and hyphens, which is the rule the existing error message already stated. ., .. and a/.. are added to the rejection test, and reverting the check fails exactly those three cases. This predates this PR, but it belongs with the top-level rule.


# If project_root is set, constrain all projects to that directory
project_root = self.config_manager.config.project_root
name_permalink = project_permalink(name, top_level=project_root is not None)

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 Treat an empty project root as disabled

When BASIC_MEMORY_PROJECT_ROOT is present but empty, the config value is "": this passes top_level=True here, while the subsequent if project_root branch treats the root as disabled and uses the caller's ordinary local path. Such local projects therefore unexpectedly reject names like Research/2026 even though no shared-root layout is active. Pass top_level=bool(project_root) so validation matches the path-selection logic.

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 e0c9830. project_root is Optional[str] with no validator, so an empty env var gives "", which path selection treats as no root. top_level=bool(project_root) now matches it. The new test adds a local Research/2026 project with BASIC_MEMORY_PROJECT_ROOT="" and fails with the old is not None.

phernandez and others added 2 commits September 22, 2026 18:16
Pull the project-name rules out of ProjectService.add_project into
project_permalink(name, *, top_level), so every runtime that creates
projects applies the same rules. Cloud inserts projects through its
own race-safe INSERT ... ON CONFLICT path and could not reuse
add_project, so it had silently dropped these rules.

The new rule: under a shared root (a configured project root, and
Cloud's tenant bucket) a name whose permalink contains '/' is refused.
The permalink becomes the project's directory, so 'Research/2026'
would live inside 'Research', and anything that treats a project
directory as the project's own, such as deleting it with the project,
would reach into the nested one. Local projects choose their own paths
and keep accepting '/' in names.

Refs basicmachines-co/basic-memory-cloud#2102

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015y5WHPT9CNQp1RAttVFuFT
Signed-off-by: phernandez <paul@basicmachines.co>
Two review findings on project_permalink:

- Periods survive generate_permalink, so '.' and '..' passed the
  empty-segment check. As a directory under a project root they name
  the root itself or its parent, and deleting that project's files
  would delete the root. Every segment must now contain something
  other than dots and hyphens, which is the rule the error message
  already stated.
- An empty BASIC_MEMORY_PROJECT_ROOT is no root for path selection,
  but was passed as top_level=True. Use bool(project_root) so local
  projects keep '/' names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015y5WHPT9CNQp1RAttVFuFT
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez force-pushed the project-root-top-level-names branch from e0c9830 to aaf0721 Compare September 22, 2026 23:16
@phernandez
phernandez merged commit 0e5a35d into main Sep 22, 2026
34 checks passed
@phernandez
phernandez deleted the project-root-top-level-names branch September 22, 2026 23:54
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.

1 participant