Skip to content

fix(mcp): unify note writes with typed outcomes - #1521

Merged
phernandez merged 5 commits into
mainfrom
fix/993-overwrite-error
Sep 8, 2026
Merged

phernandez merged 5 commits into
mainfrom
fix/993-overwrite-error

Conversation

@phernandez

@phernandez phernandez commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Why

write_note inferred an existing-note conflict from exception text, then resolved an identifier and attempted a second write. That masked locked-note failures and made moved-note behavior depend on the general link resolver. This consolidates #1525 into one explicit write operation.

Fixes #1479. Related to #993.

What Changed

  • A path-addressed write returns typed created, updated, already-exists, target-moved or locked outcomes. The MCP tool consumes validated variants with an exhaustive match.
  • The exact current file owner is the overwrite target. When the path is vacant and a supplied frontmatter permalink or generated path alias identifies a moved note, return NOTE_PATH_CONFLICT with its current path. overwrite=False can deliberately create a separate note.
  • Preserve actual replacement refusals and canonical content. Remove exception-text matching and the MCP resolver round trip; no general LinkResolver changes are needed.
  • Document moved-note behavior and retain the real MCP/CLI lock and moved-note regressions.

Implementation Details

NoteContentMutationService.write_note owns target selection. Internal frozen dataclasses carry the outcomes; /knowledge/write serializes them as a Pydantic discriminated union; KnowledgeClient validates that response once.

The new operation dispatches through public create/update methods so runtime overrides retain their pre-acceptance work. Those methods share actor resolution, transaction ownership, acceptance hooks, cache invalidation and post-commit publication. Existing create/update HTTP contracts and the core accepted-write guards remain intact. Legacy structured service errors are translated once into recoverable outcomes; other refusals retain their status and detail.

Testing

  • uv run pytest tests/mcp/test_tool_write_note.py tests/mcp/test_tool_write_note_kebab_filenames.py tests/mcp/test_tool_write_note_metadata.py test-int/mcp/test_write_note_integration.py test-int/mcp/test_moved_note_overwrite.py test-int/mcp/test_locked_note_results.py test-int/cli/test_locked_note_refusals.py --no-cov -q — 121 passed.
  • uv run pytest test-int/test_note_write_outcomes.py tests/indexing/test_accepted_note_mutation_runner.py tests/cloud/test_cloud_services.py --no-cov -q — 65 passed before the final runtime-override regression additions.
  • uv run pytest test-int/test_note_write_outcomes.py test-int/mcp/test_moved_note_overwrite.py --no-cov -q — final 9 passed, including runtime override refusals and transaction-hook rollback.
  • PostgreSQL: the write/MCP/CLI integration suite passed 29 tests. BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/test_note_write_outcomes.py test-int/mcp/test_moved_note_overwrite.py test-int/mcp/test_locked_note_results.py --no-cov -q passed all 15 final runtime-dispatch cases.
  • Review regression: custom-frontmatter moved-note cases failed in both output formats before the fix. uv run pytest tests/mcp/test_tool_write_note.py test-int/test_note_write_outcomes.py test-int/mcp/test_moved_note_overwrite.py test-int/mcp/test_locked_note_results.py --no-cov -q then passed 81 tests; the added malformed-frontmatter API case passed separately. BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/mcp/test_moved_note_overwrite.py --no-cov -q passed all 5 cases.
  • CI telemetry correction: the full Python 3.14 SQLite unit run had one failure (7,132 passed): its old create-endpoint span assertion. Added API/client spans for the new write operation and updated the telemetry contract. uv run pytest tests/mcp/test_tool_telemetry.py tests/api/v2/test_knowledge_router_telemetry.py test-int/test_note_write_outcomes.py --no-cov -q passed all 15 cases.
  • just fast-check and just doctor passed.

Risks / Follow-ups

Cloud must deploy the Core version containing /knowledge/write before clients using this endpoint are released. Existing HTTP create/update callers remain compatible. This is not a Cloud deployment or a change to the concurrency protocol. PR #1525 is superseded by this implementation and its behavioral tests.

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez added this to the v0.24.0 milestone Sep 8, 2026
@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-08T15:33:39.716547Z dbcc297 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.

@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 8322d33d18

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

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 735301d8ac

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

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez changed the title fix(mcp): preserve overwrite refusal details fix(mcp): unify note writes with typed outcomes Sep 8, 2026
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@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: 1b2ecc102d

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

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 1b02c1ceb7

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

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: dbcc2975be

ℹ️ 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 merged commit 3452c82 into main Sep 8, 2026
35 checks passed
@phernandez
phernandez deleted the fix/993-overwrite-error branch September 8, 2026 16:10
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.

[BUG] write_note(overwrite=True) creates a second note instead of replacing one whose file has been moved

1 participant