Skip to content

Give same-named repos distinct memory scopes (#179) - #1570

Merged
currentbits merged 1 commit into
mainfrom
memory-scope-collisions-179
Oct 10, 2026
Merged

currentbits merged 1 commit into
mainfrom
memory-scope-collisions-179

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #179.

What changed

  • Key registry: new project_roots table maps each main repo root to its memory key. The first root to claim a folder name keeps the bare key (app), so existing scopes don't move. Later roots with the same name get app-<6 hex of sha1(root)>. Every key lookup in memory.js goes through it.
  • Migration: rows that still hold a live path land in their own repo's scope. Rows already collapsed to a bare basename carry no root, so they can't be split and stay with whoever owns the bare key.
  • Settings > Memory: lists repos that share a folder name, with a Rename box per scope. Renaming moves that scope's memories with it, and is refused when the name is taken. This goes through a new POST /api/project-scope endpoint, a projectCollisions field on /health, and a memory.renameScope IPC call (added to the web settings scope).
  • Bound sessions: the check that an entry belongs to the session's project now resolves through the registry, so a suffixed repo can read its own rows.
  • Text names (app, owner/app) still resolve to the bare key.

Tests

  • memory-server: 237 pass / 0 fail, run with the inherited CODER_* vars unset. New tests cover two real git repos named app staying isolated, stable keys, rename and its refusals, and the migration.
  • test/settingsModal.test.tsx: 87 pass / 0 fail (render, rename, refusal, empty state).
  • electron/test/budget-spend.test.js pins the collisions passthrough in appStatus.

Not included: old session transcripts could be split per thread from the electron side. Left as a follow-up.

🤖 Generated with Claude Code

project_roots registers each main-repo root; the first root to claim a
basename keeps the bare key, later ones get <base>-<sha1(root)[:6]>.
Boot migration splits rows that still hold a live path; rows merged
before the split stay with the bare key. Settings > Memory lists
colliding roots and renames a scope (rows move with it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 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-10T07:55:46.213778Z 06a5f89 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: 06a5f89299

ℹ️ 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 on lines +346 to +349
const taken =
this.db.prepare(`SELECT 1 FROM project_roots WHERE key = ?`).get(next) ||
this.db.prepare(`SELECT 1 FROM entries WHERE project = ? LIMIT 1`).get(next) ||
this.db.prepare(`SELECT 1 FROM session_messages WHERE project = ? LIMIT 1`).get(next)

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 Reject rename targets already used by a code wiki

When the requested key belongs only to an existing code_wiki row—for example, a legacy slug-scoped wiki with no entries, sessions, or project_roots registration—this check treats the key as available. The subsequent UPDATE OR REPLACE either replaces that project's wiki when the source also has one or leaves the existing wiki attached to the newly renamed scope, causing cross-project wiki loss or leakage. Include code_wiki in the collision check before moving the scope.

Useful? React with 👍 / 👎.

@@ -724,6 +744,7 @@ export function startServer(memory, config, host = '127.0.0.1', configFile) {
entryCount: memory.entryCount(),
janitor: memory.janitorSnapshot?.() ?? readJanitorSnapshot(memory.db),
vectors: memory.vectorsHealth?.() ?? { enabled: false, count: 0, model: null },
projectCollisions: memory.projectCollisions?.() ?? [],

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 Keep absolute repository paths off the open health endpoint

When two registered repositories share a basename, this adds their full absolute roots to /health, even though the route is explicitly unauthenticated. Any local client able to probe the memory port can now enumerate those repository paths, including usernames and private directory names. Return collision details from an authenticated API endpoint instead, or omit the roots from the public health payload.

Useful? React with 👍 / 👎.

@currentbits
currentbits merged commit 5c880bb into main Oct 10, 2026
6 checks passed
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.

Memory project keys collide for same-named repos; conventions leak across projects

1 participant