Skip to content

fix(mcp): refuse overwrites resolving to another path - #1525

Closed
phernandez wants to merge 2 commits into
mainfrom
fix/1479-moved-overwrite-refusal
Closed

phernandez wants to merge 2 commits into
mainfrom
fix/1479-moved-overwrite-refusal

Conversation

@phernandez

@phernandez phernandez commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Why

Refs #1479. With the default retained permalink, renaming a note leaves its old identity live while its title-derived file path is free. write_note(overwrite=True) currently creates a second file instead of updating or refusing.

This draft makes option B (refuse and return the current location) concrete for policy review. The choice between refusal and following a move is still open; this PR does not authorize landing that choice.

What Changed

Before an overwrite-enabled create, resolve the requested path strictly. If that identity resolves to a different current path, return NOTE_PATH_CONFLICT in JSON or an actionable text refusal naming the path and stable note ID. No file is written. Normal creates and same-path overwrites retain their existing behavior.

Implementation Details

Uses the existing project-routed typed resolver; no fuzzy search, title guessing, or new API contract. Only a real HTTP 404 permits creation to continue; operational errors propagate. A retained permalink makes the reported rename discoverable. Moves that deliberately update permalinks are outside this identity-based guard.

Strict explicit Markdown paths select the current file owner before generated permalink aliases. This lets a replacement at a vacated path be overwritten without touching the moved note. Verbatim custom permalinks retain their existing precedence.

The preflight adds one resolution request to overwrite-enabled calls. It is not a transaction or a concurrent-move guarantee. The implementation preserves the existing canonical write safeguards and does not follow a moved target automatically.

Testing

  • Real MCP text/JSON reproduction on main: both fail by returning Created and creating the duplicate.
  • uv run pytest test-int/mcp/test_moved_note_overwrite.py --no-cov -q: 2 passed after fix; unchanged moved-file bytes and no second Markdown file.
  • Existing write unit/integration coverage: 79 passed.
  • Final resolver and moved-note SQLite suite: 59 passed, including replacement ownership and literal custom permalink precedence.
  • Final moved-note and custom permalink PostgreSQL regressions: 4 passed.
  • BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/mcp/test_moved_note_overwrite.py test-int/mcp/test_write_note_integration.py --no-cov -q: 17 passed.
  • just fast-check, just doctor, just man-regen, and git diff --check: passed.

Risks / Follow-ups

Policy approval is still required before marking this draft ready to land. Strict resolution can conservatively refuse aliases that resolve to another path; it never writes to that alternate path. Explicit overwrite=False remains ordinary create/conflict behavior. No claim is made that arbitrary same-title notes or changed permalinks identify a moved note.

@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-08T14:32:48.488903Z 6cc9e83 Draft marked ready
ℹ️ 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: f4bc316c39

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

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 6cc9e83fbe

ℹ️ 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
phernandez marked this pull request as ready for review September 8, 2026 14:23

@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: 6cc9e83fbe

ℹ️ 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 +449 to +451
existing = await knowledge_client.resolve_entity_response(
requested_path, strict=True
)

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 Check only path identity before refusing writes

When another note's title happens to equal the requested filename, this general-purpose resolver returns that note even though it does not own the path, causing a valid overwrite=True create to return NOTE_PATH_CONFLICT. For example, an archived note titled README.md makes writing a new root note titled README fail because resolving README.md matches the archived note by title. This preflight should query exact path ownership and only separately check the retained-permalink case, rather than treating every strict title/permalink resolution as a path conflict.

Useful? React with 👍 / 👎.

@phernandez

Copy link
Copy Markdown
Member Author

Superseded by #1521, which now owns the typed write operation and includes the moved-note refusal and exact-path replacement regressions from this PR. The general LinkResolver patch is no longer needed. Local SQLite/PostgreSQL validation has passed; fresh CI and Codex review are running on #1521.

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