Repository navigation
Conversation
A note with `locked: true` refuses every API change, including one that removes the lock, so Cloud users had to email support to unlock notes an AI tool had locked (basic-memory-cloud#3350). The note's actor now carries a closed `NoteLockAuthority`: `PersonInWebApp | AgentWriter`, defaulting to `AgentWriter`. Only a runtime actor resolver that authenticated a person can set `PersonInWebApp`; local API, MCP and CLI callers never do. For a person, a full replacement (PUT) of a locked note is accepted only when it removes `locked` (or sets it to false) and changes nothing else: same body, same frontmatter apart from the server-stamped `updated_by`. Edits and deletes of a locked note stay refused for everyone, and agents keep the exact one-way behavior they have today. LOCKED_NOTE_MESSAGE now tells agents to ask a person to unlock the note in the web app, or to edit the file directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Joe P <joe@basicmemory.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2656c8e734
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| def unchanged_fields(metadata: dict[str, object]) -> dict[str, object]: | ||
| return { | ||
| key: value | ||
| for key, value in metadata.items() | ||
| if key not in (LOCKED_FIELD, UPDATED_BY_FIELD) |
There was a problem hiding this comment.
Require an author before ignoring updated_by
When a resolver grants PersonInWebApp() but leaves author=None—a combination explicitly exercised by test_person_can_unlock_by_setting_locked_false—NoteAuthorship.for_write returns None, so no trusted value overwrites updated_by. Because this comparison always removes updated_by from both documents, the same PUT can unlock the note while adding, changing, or deleting that field, and the altered canonical Markdown is accepted despite the unlock-only contract. Ignore this field only when a trusted authorship stamp will replace it, or make the verified author part of the authority value.
AGENTS.md reference: AGENTS.md:L157-L161
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1df16be. is_unlock_only now ignores updated_by only when the write stamps it (an author is present). With no author, a changed updated_by is an edit and the unlock gets 423. Covered by test_person_without_author_cannot_change_updated_by_while_unlocking, which fails with the old rule.
An unlock may ignore updated_by only because the server overwrites it. With no author on the write nothing overwrites it, so a changed value is the caller's edit and the unlock is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Joe P <joe@basicmemory.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1df16beefe
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| reject_locked_note_unless_unlock_only( | ||
| current_note_content, | ||
| proposed_markdown=prepared_write.prepared.markdown_content, | ||
| updated_by_is_stamped=authorship is not None, |
There was a problem hiding this comment.
Include the destination path in the unlock-only check
When a verified person removes locked while changing only directory or file_name, the default update_permalinks_on_move=False preserves the current permalink, so the prepared Markdown passes this check even though data.file_path changed. The subsequent persistence path therefore moves and unlocks the note in one PUT, contrary to the unlock-only contract; compare the prepared file path with the existing entity path before accepting the unlock.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining this one. Core already lets any writer move a locked note: move is not refused, because a move keeps the note's content, which is what the lock protects. So a person who unlocks and moves in one PUT ends in a state they could reach with two allowed calls, and an agent still can't unlock at all. The web app's unlock save keeps the same directory and title, so it never takes this path.
| return unchanged_fields(locked_metadata) == unchanged_fields( | ||
| proposed_metadata | ||
| ) and remove_frontmatter(locked_markdown) == remove_frontmatter(proposed_markdown) |
There was a problem hiding this comment.
Compare unlocks before automatic permalink insertion
For an accepted locked note whose raw Markdown has no permalink—for example, an imported or previously indexed note—prepare_update_entity_content always inserts the entity's resolved permalink before this comparison. Consequently, a person's PUT that changes only locked: true to false is rejected because the prepared metadata contains the server-added key, leaving such notes impossible to unlock through the advertised web-app path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d185780. The check now compares against what the server writes on any update: the locked frontmatter without locked, plus the entity permalink when the file had none, plus the server's own updated_by stamp. A note whose file has no permalink can be unlocked; a different permalink is still refused. Unit tests in tests/markdown/test_note_lock.py cover both and fail without the permalink default. (Locally, index-file writes a permalink into the file, so I couldn't build this case through the API.)
Every update writes the note's permalink and, when the write names an author, its updated_by stamp. An unlock now expects exactly those: the locked frontmatter without the lock, the entity permalink when the file had none, and the server's own updated_by stamp. A note whose file has no permalink can be unlocked, and a caller cannot pass a different updated_by off as the stamp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Joe P <joe@basicmemory.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1857801cc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return expected_metadata == proposed_without_lock and remove_frontmatter( | ||
| locked_markdown | ||
| ) == remove_frontmatter(proposed_markdown) |
There was a problem hiding this comment.
Preserve edge whitespace during unlock validation
When a locked note's body begins with meaningful indentation (for example, an indented Markdown code block) or has other significant edge whitespace, PUT preparation strips that whitespace, and these default remove_frontmatter() calls strip it from both sides again during comparison. The write is therefore accepted as unlock-only even though it persists a semantically changed body; use byte-preserving body extraction (strip=False) throughout the replacement preparation and comparison path.
AGENTS.md reference: AGENTS.md:L157-L161
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining for this PR as a pre-existing gap. I checked it: a POST of ---\nlocked: true\n---\n\n indented code\n more\n\nText.\n already stores the body as indented code\n more\n\nText., so edge whitespace is normalized on every API write, not by the unlock. The unlock PUT of that stored note kept the body byte-for-byte. The only remaining case is a locked file written outside Basic Memory with edge whitespace. Its unlock would get the same normalization as every later web save of that note. Switching the comparison to strip=False wouldn't keep those bytes; it would make such notes impossible to unlock from the web. Byte-preserving body handling for PUT is a separate change to replacement preparation, so I'll suggest it as a follow-up.
Why
A note with
locked: truerefuses every API change, including a change that removes the lock. Cloud users have no file on disk to edit, so unlocking a note an AI tool had locked meant emailing support. Two support tickets in November needed a manual edit in production storage. Tracked in basicmachines-co/basic-memory-cloud#3350.The lock exists to stop agents from changing or unlocking a protected note by accident. A person working in the web app should be able to remove it.
What changed
markdown/note_lock.pyNoteLockAuthority = PersonInWebApp | AgentWriter, withAGENT_WRITERas the default.is_unlock_only(locked_markdown, proposed_markdown). It is true only when the proposed note dropslocked(or sets it tofalse) and keeps the same body and the same other frontmatter.updated_byis ignored because the server stamps it on every write.LOCKED_NOTE_MESSAGEnow tells agents to ask a person to unlock the note in the web app, or to edit the file directly.NoteContentMutationActorContextandAcceptedNoteMutationActorcarrylock_authority. Routes never set it. Only a runtime actor resolver that authenticated a person can, so every local API, MCP and CLI caller stays an agent._run_accepted_note_updatedocs/LOCKED_NOTES.mddescribes the person exception.How it was tested
tests/markdown/test_note_lock.py: the unlock-only rule. Accepted: the key removed,locked: false, a reordered key, anupdated_bystamp. Refused: still locked, a body edit, a retitle, an added key,locked: "true", no frontmatter, malformed frontmatter.tests/api/v2/test_note_lock_authority.py: real API with a resolver standing in for Cloud.locked: falsealso unlocks.test_agent_cannot_unlockfails.test-int/test_locked_notes.py,test-int/mcp/test_locked_note_results.py,test-int/cli/test_locked_note_refusals.py, cross-project move, and authorship.Locally,
tyonly reports the missingpymilvusmodule, and the onlytests/servicesfailures are semantic tests that need the sqlite vector extension. Both are environment issues unrelated to this change.Risk
Nothing changes for callers that don't set
lock_authority. The Cloud change that sets it for web-app sessions comes in a follow-up PR on basic-memory-cloud.🤖 Generated with Claude Code