Redesign bm doctor: report on real projects and suggest fixes · Issue #1798 · basicmachines-co/basic-memory · GitHub
Skip to content

Redesign bm doctor: report on real projects and suggest fixes #1798

Open

Description

@phernandez

Problem

People want a doctor command. They run it when something looks wrong and expect it to tell them what is wrong with their project and what to do about it. bm doctor does neither.

Today it is a smoke test. It registers a throwaway project in the user's real config and database, writes a note through the API and one through the filesystem, indexes them, searches, checks status, then deletes the project. It passes on an install whose real projects have duplicate search rows, orphaned rows or unindexed files (#1773), because it never looks at them.

The throwaway project is also why doctor keeps breaking. It is a real project, so it runs into every policy a real project is subject to, and each one has produced a bug and a special case:

Issue What broke Special case we added
#665, #1323 project_root policy rejected the temp directory a dedicated create_doctor_project endpoint
#1315, #1317, #1666 writes are accepted before the file is materialized drain_pending_materializations() before reading
#1666 the run mutated config.json; the doctor project became the default and the API refused to delete it a local delete path that bypasses the API guard
#1027, #1058 event-loop and blank-message failures error-message fallbacks

The next policy change will produce the next doctor bug.

Goal

bm doctor produces a report on the user's actual projects and, for each problem it finds, suggests an action the user or their agent can take to fix it.

Proposed design

1. Inspect real projects (read-only)

Doctor checks the projects that exist and never writes to them. Each check produces findings, and each finding carries a suggested action. A first set of checks:

Check Example finding Suggested action
Search index integrity (#1773, PR #1792) duplicate search_index rows; rows whose entity, observation or relation is gone bm reindex --search --project X
File vs index files on disk not indexed; entities whose file is missing bm reindex --project X, or restore or delete the file
Materialization notes stuck pending, or with a sync_error the specific repair, or the failing path and error
Semantic vectors entities with deferred or missing embeddings; embedding model changed bm reindex --embeddings --project X
Wiki projection last run conflicted, or scope collisions (#1787) rename the listed folders, or resolve the reserved-path conflict
Config project path missing or not absolute; config and database disagree on a path bm project ... commands that fix it
Frontmatter and parse errors notes that failed to parse the file and line to fix

Two rules:

  • Severity follows the consistency model in AGENTS.md. Derived state (search rows, vectors, materialization status, Wiki output) is eventually consistent. A lag while indexing is running is reported as info, not as a failure. A finding is an error only when nothing will repair it without action: a real duplicate, a missing file, a parse error, a conflict.
  • Actions are concrete commands or edits, not "wait and rerun". If doctor cannot name an action, the finding says so and shows the evidence.

2. Pipeline self-test, sandboxed

Keep the write, index, search and status round trip. It catches broken installs, missing dependencies and migration failures. But run it in-process against a temporary home, config, SQLite database and project directory, the way just doctor already does, and never register anything in the user's real config or database. That removes the project-root, default-project, config-mutation and cleanup bugs as a class. It needs ConfigManager to be injectable at the composition root (the open half of #1109).

3. Output for people and agents

  • Human output: a short summary per project, then findings grouped by severity, each with its action.
  • --json: a stable, typed report (checks, findings, severity, evidence, suggested action) that an agent can act on without parsing prose.
  • Exit codes: 0 when there are no errors; nonzero when there is at least one error. Info and warnings never fail the run.
  • Scoping: --project X, with every project by default.

Doctor reports and suggests. It does not repair. A separate --fix that runs the suggested safe actions could come later; it is out of scope here.

Open questions

Relationship to existing work

Acceptance

  • bm doctor never creates, modifies or deletes anything in the user's real config or database.
  • On a project with a duplicate search row, a missing file and an unindexed file, doctor reports three findings, each with an action, and exits nonzero.
  • On a healthy project with indexing in progress, doctor exits 0 and reports the lag as info.
  • bm doctor --json output is a typed schema covered by tests.
  • The sandboxed self-test passes with project_root configured, with no default project, and with a fresh config.

Activity

  1. claude commented on Oct 20, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 28s —— View job


    Triage

    Related issues (not duplicates)

    Suggestions

    • Split this into an umbrella issue with three sub-issues: the finding/report schema with the integrity check, the sandboxed self-test, and the --json output with exit codes. Each can ship alone.
    • Fix the report schema first. Checks, MCP exposure and a later --fix all build on it.
    • The open questions (--cloud behavior, an MCP tool or memory://doctor resource, a bm status summary line) can wait until the local read-only path ships. I'd suggest --cloud run inspection only, with no self-test, as the issue proposes.

    This was triage only, so I made no code changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions