Repository navigation
feat: Add disable_permalinks config flag - #313
Conversation
- Add disable_permalinks bool field to BasicMemoryConfig (defaults to False) - Update sync_service to skip permalink updates when flag is enabled - Update entity_service to skip permalink generation when flag is enabled - Update dependency injection to pass app_config to EntityService - Add comprehensive unit and integration tests - Preserve relation formatting throughout When disable_permalinks=True: - New notes won't have permalinks added to frontmatter - Sync operations won't update permalinks - Existing permalinks in notes still work for reading - Move operations won't update permalinks even if update_permalinks_on_move=True Closes #307 Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
|
Claude finished @phernandez's task —— View job Code Review Complete ✅I've reviewed this PR implementing the ✅ Code Quality & Standards
✅ Testing & Documentation
✅ Basic Memory Architecture
✅ Security & Performance
Code-Specific ObservationsExcellent Implementation Details:
Minor Suggestions:
SummaryThis is a well-implemented feature that cleanly adds the ability to disable automatic permalink generation in Basic Memory. The implementation:
The PR is ready for merge. Great work on maintaining code quality and thorough testing! 🎯 |
Resolved merge conflict in config.py by keeping both new fields: - disable_permalinks from PR #313 - skip_initialization_sync from main - api_url from PR #313 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task —— View job Code Review Complete ✅I've reviewed PR #313 implementing the SummaryThis PR adds a clean, well-tested feature that allows users to disable automatic permalink generation. The implementation is solid with comprehensive test coverage and follows all Basic Memory coding standards. ✅ Code Quality & Standards
Code Quality Notes:
✅ Testing & Documentation
✅ Basic Memory Architecture
Architecture Notes:
✅ Security & Performance
Performance Notes:
🔍 Code-Specific ObservationsExcellent Implementation Details:
Implementation Highlights:
📋 Test Coverage AnalysisUnit Tests (
|
Fixed issue where entities created with disable_permalinks=True were still getting permalinks auto-generated from file paths. Solution: - Use empty string "" as sentinel value in schema._permalink to indicate permalinks are disabled - Updated permalink property to return None when it sees the empty string sentinel - Fixed type annotations to allow Optional[Permalink] return type - Fixed create_or_update_entity to handle None permalinks properly Tests: - All disable_permalinks unit tests now pass - Rewrote integration tests to use current DB API (engine_session_factory) - Added comprehensive integration test coverage for disable_permalinks feature 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task —— View job Code Review Complete ✅I've thoroughly reviewed PR #313 implementing the ✅ Code Quality & Standards
Code Quality Highlights:
✅ Testing & Documentation
Test Quality: 361 lines of tests for ~40 lines of logic - excellent test-to-code ratio ✅ Basic Memory Architecture
Architecture Notes:
✅ Security & Performance
Performance Notes:
🔍 Code-Specific ObservationsImplementation Highlights:1. src/basic_memory/config.py:96-99 - Excellent docstring disable_permalinks: bool = Field(
default=False,
description="Disable automatic permalink generation in frontmatter. When enabled, new notes won't have permalinks added and sync won't update permalinks. Existing permalinks will still work for reading.",
)2. src/basic_memory/schemas/base.py:253-256 - Clever sentinel value pattern @property
def permalink(self) -> Optional[Permalink]:
# Empty string is a sentinel value indicating permalinks are disabled
if self._permalink == "":
return None
return self._permalink or generate_permalink(self.file_path)3. src/basic_memory/services/entity_service.py:758-760 - Proper flag precedence if not app_config.disable_permalinks and (
app_config.update_permalinks_on_move or old_permalink is None
):4. src/basic_memory/sync/sync_service.py:533-536 - Consistent behavior across services if (
self.app_config.update_permalinks_on_move
and not self.app_config.disable_permalinks
and self.file_service.is_markdown(new_path)
):5. src/basic_memory/deps.py:263, 273 - Proper DI integration async def get_entity_service(
...
app_config: AppConfigDep,
) -> EntityService:
return EntityService(
...
app_config=app_config,
)Code Locations Reference:
📋 Test Coverage SummaryUnit Tests (test_entity_service_disable_permalinks.py):✅ Lines 14-57: Create entity without permalink Integration Tests (test_disable_permalinks_integration.py):✅ Lines 25-75: API entity creation 🎯 Final AssessmentStrengths:
Code Quality Observations:Excellent practices:
Minor Note: ✅ Recommendation: APPROVE & READY TO MERGEThis PR demonstrates:
Great work on a well-tested, cleanly implemented feature! 🎯 --- | Branch: |
…2120) ## Summary A folder delete now writes one `deleted` row per removed Markdown note into the project's change journal. Before this change it wrote none. The wiki log, OKF export history and the `/v2/projects/{id}/changes` feed all missed those deletes and kept treating the notes as present. Each row is written in the delete's own transaction and settled once its file cleanup has run. A row left unsettled would defer every later wiki projection for the project, which is the failure in GitHub #1625. Board ticket: BMEM-117. ## What changed - **Rows written with the delete.** `RepositoryDirectoryDeleteAcceptanceStore.delete_directory_entities` reads each note's `db_version` and `db_checksum` during the lock-check read it already did. It must read them first, because `note_content` cascades away with the entity. The guarded `DELETE … RETURNING` now returns id, external id, permalink, title, file path and content type. The new `record_directory_delete_project_changes` then claims positions and inserts the rows (`src/basic_memory/indexing/directory_delete_runner.py`). - **Row shape.** Positions are consecutive and follow file-path order. Each row has `operation=deleted` and `previous_file_path=NULL`, and all rows in a batch share one `accepted_at`. The source is the new `ACCEPTED_DIRECTORY_DELETE_SOURCE = "delete_directory"`. Actor fields stay NULL, because the folder-delete route carries no actor today. - **What gets no row.** Non-Markdown files get no row, the same as a single non-Markdown delete. Notes the guarded delete leaves in place also get none. A delete that removes no Markdown note claims no position. A Markdown note with no permalink is deleted without a row, with a warning: see below. - **Journal last.** The position claim and insert run after the search-index and vector cleanup. The project-row lock is therefore held only to the end of the transaction, in the same NoteContent → Entity → Project order as the single-note delete. - **Rows carried to cleanup.** The changes travel on `DirectoryEntityDeleteResult` and `DirectoryDeleteAcceptance`, keyed by entity id. `RuntimeDirectoryFileSnapshot.to_pending_note_file_delete` takes a `project_change` argument, so each `RuntimeNoteFileDeleteJobRequest` carries its row. Cloud's existing `delete_note_file` job already settles a request's `project_change`. - **Settling where no job will.** `enqueue_directory_file_delete_jobs` collects the rows of files whose cleanup ran inline (deleted, missing or skipped) or failed to enqueue. They reach `DirectoryDeleteAcceptedResult.project_changes_to_settle`, and `DirectoryDeleteService.delete_directory` settles them in one statement. A queued cleanup (the enqueuer returns `None`, as in Cloud) is left to its job. `run_directory_delete` settles the same way, in its own session. - **Why a failed or skipped cleanup still settles.** The entity delete is final. A file left on disk is re-indexed later as a new note, so waiting on it would stall projection for good. - **Repository.** `ProjectRepository` has three new methods (`src/basic_memory/repository/project_repository.py`): - `advance_partition_position_by(count)` claims N positions in one `UPDATE … RETURNING`. - `record_accepted_note_changes` does one bulk insert. - `mark_accepted_note_changes_materialized` settles a list of positions with the same rule as the single-position settle: each target, plus older unsettled rows of the same note. It works in chunks of 500 positions. The protocol `DirectoryDeleteAcceptanceStore.delete_directory_entities` gains a required keyword, `project_external_id`. Cloud uses core's `RepositoryDirectoryDeleteAcceptanceStore` and `DirectoryDeleteService`, so it needs no code change for the journal rows. It picks this up when its core pin moves. ## Notes with no permalink Databases from before the `disable_permalinks` setting was removed (#313 added it) can still hold Markdown notes with no permalink. No migration backfilled them. A journal row needs a permalink, so no journal row ever named these notes. Raising on them would roll back the whole folder delete, where today it succeeds. CI caught this: `test-int/read_cache/test_runtime_invalidation.py` seeds such notes and failed with `RuntimeError: Accepted note is missing permalink for entity_id=1`. So the folder delete now removes them without a journal row and logs a warning. `test_directory_delete_skips_journal_row_for_note_without_permalink` covers this. The single-note delete still raises, unchanged. ## Verification All commands ran in this branch's worktree on macOS. - SQLite: `BASIC_MEMORY_ENV=test uv run pytest tests/indexing/test_directory_delete_runner.py tests/repository/test_project_partition_repository.py tests/cloud/test_cloud_services.py tests/mcp/test_wiki_after_api_writes.py` → `57 passed`. - Postgres (testcontainers): the same command with `BASIC_MEMORY_TEST_POSTGRES=1`, without the wiki test → `56 passed`. - Lock order: `BASIC_MEMORY_TEST_POSTGRES=1 … pytest test-int/test_relation_generation_concurrency.py` → `4 passed`. It skips on SQLite by design. - Related routes: `pytest tests/api/v2/test_knowledge_router.py tests/api/v2/test_delete_unresolves_inbound_relations.py tests/mcp/test_tool_bm_delete.py tests/services/test_entity_service.py -k "directory or folder"` → `25 passed`. - After the permalink change: `pytest tests/indexing/test_directory_delete_runner.py test-int/read_cache/test_runtime_invalidation.py` → `43 passed` on Postgres, and the directory-delete read-cache tests pass on SQLite. - `ruff check` and `ruff format` are clean. `ty check src tests test-int` reports only the 4 `pymilvus` import errors from my local environment. CI installs the `milvus` extra. New tests: - `test_directory_delete_journals_each_markdown_note_and_carries_rows_to_cleanup`: rows at positions 6 and 7 after head 5, in path order, with their fields and revisions. The PNG gets no row. Each cleanup request carries its row, and queued rows stay unsettled. - `test_directory_delete_journal_rolls_back_with_failed_transaction`: a failure after the entity delete keeps the note, the journal and the head unchanged. - `test_directory_delete_claims_no_position_without_deleted_markdown`: an empty folder, and a folder of only non-Markdown files. - `test_local_directory_delete_settles_every_row_whatever_the_cleanup_outcome`: the real local enqueuer against files on disk, with one file deleted, one missing, one changed on disk (skipped) and one whose delete raises `OSError`. Every row is settled, and `inspect_local_wiki_projection` reports `pending_materialization == ()`. - `test_run_directory_delete_settles_inline_cleanup_rows`. - `test_directory_delete_skips_journal_row_for_note_without_permalink`. - The guarded-delete survivor test and the move-out test now also assert that no position was claimed. - Repository tests cover the bulk claim, the bulk insert and the bulk settle rule. ## Noted, not changed - Under SQLite, `accepted_at` and `materialized_at` come back with their UTC wall-clock time labelled as local time. For example, 20:15 UTC reads back as 20:15 CDT. `AcceptedProjectNoteChange.__getattribute__` → `ensure_timezone_aware` treats naive SQLite values as local time. The single-row ORM insert and the new bulk insert behave identically: I checked both with a throwaway probe. So this PR does not cause it. - In Cloud, each folder-delete row's `delete_note_file` job will schedule a wiki projection once the core pin moves. That is one projection request per note in the folder. Whether those requests coalesce is a question for the Cloud pin bump. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Drew Cain <groksrc@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Closes #307
Summary
Adds a new configuration flag
disable_permalinksthat allows users to disable automatic permalink generation in Basic Memory.Changes
disable_permalinks: boolfield toBasicMemoryConfig(defaults toFalse)sync_service.pyto skip permalink updates when flag is enabledentity_service.pyto skip permalink generation when flag is enabledapp_configtoEntityServiceBehavior
When
disable_permalinks=True:update_permalinks_on_move=TrueTesting
Generated with Claude Code