Skip to content

feat(core): enforce one-way locked notes in mutation APIs - #1486

Merged
phernandez merged 2 commits into
mainfrom
feat/locked-notes
Sep 6, 2026
Merged

phernandez merged 2 commits into
mainfrom
feat/locked-notes

Conversation

@phernandez

@phernandez phernandez commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Why

Implements the v0.24.0 locked-note scope agreed in #993: agents may set locked: true, but cannot use Basic Memory note APIs to edit, overwrite, delete, or unlock that note afterward. Direct filesystem edits are explicitly outside the contract.

Scope Clarification

  • locked: true is a one-way guard for the note-mutation API, not filesystem security.
  • Imports are treated like raw file writes and are outside this lock contract. Do not add atomic import-versus-API synchronization or migrate importers into the guarded note-write path for this feature.
  • Direct filesystem edits remain authoritative and may remove the lock. Deleting a file or its directory directly overrides the lock; Basic Memory must not block those deletions or restore files merely because they were locked.
  • API delete_note and API directory deletion are explicitly bound by the lock. These filesystem exceptions do not apply to note API operations.

What Changed

  • Reject PUT, PATCH, and DELETE with HTTP 423 when the existing canonical Markdown has the YAML boolean locked: true.
  • Reject API directory deletion before deleting any siblings when an accepted member is locked or a current local file has acquired a lock before indexing.
  • Leave imports as unrestricted raw file writes; preserve direct filesystem deletion and reconciliation.
  • Preserve allowed moves and their lock metadata; reads, indexing, and offline unlocking continue to work.
  • Document the contract in docs/LOCKED_NOTES.md.

Implementation Details

The accepted mutation runner reads the existing NoteContent before preparing the proposed replacement or edit. Incoming metadata, body frontmatter, or find/replace operations never authorize an unlock. Checks reuse the existing canonical mutation fence; no new database locks, identity system, privileged unlock route, or audit machinery were introduced. The local freshener reconciles direct file edits before individual note mutations.

The directory path checks accepted Markdown before any deletion. A local read-only preflight also inspects current Markdown files before accepting the bulk delete, so an offline lock does not require waiting for the watcher. Hosted runtimes retain the accepted-content check. No new locks or file-write machinery were added. Importer and FileService behavior are unchanged from the base branch.

Testing

  • just fast-check: passed.
  • uv run pytest test-int/test_locked_notes.py --no-cov -q: 16 passed on SQLite.
  • uv run pytest tests/indexing/test_accepted_note_mutation_runner.py tests/indexing/test_directory_delete_runner.py tests/importers/test_importer_base.py --no-cov -q: 64 passed.
  • uv run pytest test-int/mcp/test_delete_directory_integration.py test-int/cli/test_cli_tool_delete_note_integration.py --no-cov -q: 14 passed.
  • BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/test_locked_notes.py --no-cov -q: 16 passed against real PostgreSQL.
  • codex review --uncommitted: no actionable regressions; reviewer independently passed all 16 locked-note integration tests before the follow-up push.
  • just doctor: passed.
  • New tests use real APIs, files, and databases, without parameterization or mocked lock enforcement. Rejection assertions read back canonical content, file bytes, and content versions.

Risks / Follow-ups

  • This is a note-mutation contract, not filesystem security or Teams authorization. Direct file edits can remove the flag.
  • Moves remain allowed and preserve protection; their normal permalink update policy is unchanged.
  • Schema enforcement and team-scoped permissions from the broader Use frontmatter to enforce validation and set conditional (read-only / team-scoped) permissions #993 proposal are not implemented here.
  • Native/full CI will run on the PR; local validation is not a claim that CI has finished.

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez added this to the v0.24.0 milestone Sep 6, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 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-06T03:49:13.373313Z 26c8050 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 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: 1dc2803af7

ℹ️ 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 thread src/basic_memory/importers/base.py Resolved
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

Please review head 26c8050 against the clarified scope in the PR description. API note edits/overwrites/deletes and API directory deletion respect locked: true. Imports and direct filesystem edits/deletions are intentionally outside the contract; do not add import synchronization or filesystem access control. The directory offline-lock finding is fixed with a read-only preflight. Both prior threads have replies and are resolved. All 16 real locked-note integration tests pass on SQLite and PostgreSQL, plus 14 existing MCP/CLI deletion integration tests; pre-push local review found no actionable regressions.

@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: 26c80506a8

ℹ️ 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 thread src/basic_memory/index/local_notes.py Resolved
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

Head remains 26c8050. Replied to and resolved the unindexed-file thread with the deletion-set evidence: this endpoint only deletes indexed Entity snapshots and never performs recursive directory removal. Unindexed raw files are not deletion targets and remain untouched. The lock must protect every note the API would mutate/delete; untouched unindexed files are outside this API contract, not a veto over sibling note deletion. Please keep filesystem discovery expansion out of scope. Imports/raw filesystem edits and deletions remain intentionally unrestricted as confirmed by the maintainer.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 26c80506a8

ℹ️ 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 cf54013 into main Sep 6, 2026
43 checks passed
@phernandez
phernandez deleted the feat/locked-notes branch September 6, 2026 04:16
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