feat(doctor): add operational diagnostics and repair#287
Merged
Alan-TheGentleman merged 2 commits intomainfrom Apr 30, 2026
Merged
feat(doctor): add operational diagnostics and repair#287Alan-TheGentleman merged 2 commits intomainfrom
Alan-TheGentleman merged 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new operational “doctor” surface to Engram for read-only diagnostics (CLI + MCP parity), plus a narrowly-scoped, backup-gated doctor repair flow to reclassify project-contaminated session data.
Changes:
- Introduces
internal/diagnosticrunner/registry + MVP checks and wires them intoengram doctorand MCPmem_doctor. - Adds
engram doctor repairplan/dry-run/apply workflow with a diagnostic-based planner and store-owned backup + session-scoped project reclassification. - Adds documentation and OpenSpec artifacts (design/spec/tasks/verification/manual verification) for diagnostics and repair.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
cmd/engram/main.go |
Wires doctor into CLI dispatch and adds a shared runDiagnostics adapter. |
cmd/engram/doctor.go |
Implements engram doctor (text/JSON) and engram doctor repair (plan/dry-run/apply) CLI flows. |
cmd/engram/doctor_test.go |
Adds CLI tests for diagnostics, MCP parity, and repair validation/JSON/apply behavior. |
internal/diagnostic/diagnostic.go |
Adds core diagnostic types, report envelope, runner, and error report helper. |
internal/diagnostic/registry.go |
Adds deterministic check registry + invalid-check error handling. |
internal/diagnostic/checks.go |
Implements MVP checks (directory mismatch, manual session mismatch, mutation required fields, SQLite lock contention). |
internal/diagnostic/diagnostic_test.go |
Adds unit tests for runner/registry and check branches (incl. deterministic lock contention seam). |
internal/diagnostic/repair.go |
Adds repair planning for supported mismatch checks into deterministic action lists. |
internal/diagnostic/repair_test.go |
Adds unit tests for repair planning rules (trusted evidence, manual naming constraints, skip reasons). |
internal/store/diagnostic.go |
Adds store read helpers for diagnostics plus backup + apply/estimate APIs for session-scoped reclassification. |
internal/store/diagnostic_repair_test.go |
Adds store tests for estimate non-mutation and apply safety boundaries (backup + allowed tables only). |
internal/store/store_test.go |
Adds tests for new diagnostic read helpers and lock snapshot non-mutation. |
internal/mcp/mcp.go |
Registers mem_doctor tool (agent profile) and handler using the shared diagnostic runner. |
internal/mcp/mcp_test.go |
Updates tool allowlists/count expectations and adds mem_doctor contract tests (auto-detect, unknown project, envelope shape). |
docs/DOCTOR.md |
Documents doctor/repair CLI forms, MCP contract, check catalog, safety boundaries, and clone-safe workflow. |
openspec/changes/doctor-diagnostic/spec.md |
Points root spec note to canonical spec deltas to avoid conflicting requirements. |
openspec/changes/doctor-diagnostic/proposal.md |
Captures intent/scope/approach/risks for the diagnostic feature. |
openspec/changes/doctor-diagnostic/design.md |
Documents architecture decisions and contracts for diagnostic runner/CLI/MCP. |
openspec/changes/doctor-diagnostic/exploration.md |
Records exploration context and rationale for the approach. |
openspec/changes/doctor-diagnostic/tasks.md |
Tracks implementation tasks/phases for diagnostics. |
openspec/changes/doctor-diagnostic/manual-verification.md |
Adds manual verification matrix + clone walkthrough evidence. |
openspec/changes/doctor-diagnostic/apply-progress.md |
Records apply progress and verification gap fixes for diagnostics. |
openspec/changes/doctor-diagnostic/verify-report.md |
Adds verification report for diagnostics (tests, docs alignment, evidence mapping). |
openspec/changes/doctor-diagnostic/specs/operational-diagnostics/spec.md |
Defines canonical diagnostic requirements and scenarios. |
openspec/changes/doctor-diagnostic/specs/mcp-project-resolution/spec.md |
Extends MCP read-tool optional project requirement to include mem_doctor. |
openspec/changes/doctor-repair-reclassify-project/proposal.md |
Captures intent/scope/approach/risks for repair MVP. |
openspec/changes/doctor-repair-reclassify-project/design.md |
Documents repair architecture, interfaces, and testing strategy. |
openspec/changes/doctor-repair-reclassify-project/exploration.md |
Records exploration context and repair design implications. |
openspec/changes/doctor-repair-reclassify-project/tasks.md |
Tracks implementation tasks/phases for repair. |
openspec/changes/doctor-repair-reclassify-project/manual-verification.md |
Documents clone-safe manual verification commands and observed outputs. |
openspec/changes/doctor-repair-reclassify-project/apply-progress.md |
Records apply progress and verification notes for repair MVP. |
openspec/changes/doctor-repair-reclassify-project/verify-report.md |
Adds verification report for repair MVP (requirements mapping + evidence). |
openspec/changes/doctor-repair-reclassify-project/specs/operational-diagnostics/spec.md |
Defines repair-related requirement deltas and scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+62
to
+66
| if err != nil { | ||
| report = diagnostic.ErrorReport(project, err) | ||
| if jsonOut { | ||
| writeDoctorJSON(report) | ||
| } else { |
Comment on lines
+100
to
+104
| } | ||
| nameProject := normalizeProjectName(strings.TrimPrefix(session.Name, "manual-save-")) | ||
| sessionProject := normalizeProjectName(session.Project) | ||
| if nameProject == "" || sessionProject == "" || nameProject == sessionProject || !knownProjects[nameProject] { | ||
| continue |
Comment on lines
+83
to
+86
| ### Requirement: REQ-OD-005 MVP Non-Repair Constraint | ||
|
|
||
| The doctor MVP MUST NOT perform repair, apply, or write transactions. `requires_confirmation` MUST be false for all MVP checks because no apply path exists. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked Issue
Closes #286
🏷️ PR Type
type:bug— Bug fixtype:feature— New featuretype:docs— Documentation onlytype:refactor— Code refactoring (no behavior change)type:chore— Maintenance, dependencies, toolingtype:breaking-change— Breaking change📝 Summary
engram doctorread-only operational diagnostics with CLI JSON/text output and MCPmem_doctorparity.engram doctor repairplan/dry-run/apply flows for session-scoped project reclassification with backup-before-apply safety.sias-appcontamination shape.📂 Changes
cmd/engram/doctor.gointernal/diagnostic/internal/store/diagnostic.gointernal/mcp/mcp.gomem_doctoras a read-only agent tool.docs/DOCTOR.mdopenspec/changes/doctor-*🧪 Test Plan
go test ./...go test -tags e2e ./internal/server/...Manual testing:
.backupclones only; production~/.engram/engram.dbwas not mutated.--planand--dry-runare non-mutating.--applycreates a backup and updates onlysessions.project,observations.project, anduser_prompts.project.engram doctor --json --project sias-appreturned OK in the repaired clone.🤖 Automated Checks
Closes #N/Fixes #N/Resolves #Nstatus:approvedlabeltype:*labelgo test ./...passesgo test -tags e2e ./internal/server/...passes✅ Contributor Checklist
Closes #N)type:*label to this PRgo test ./...go test -tags e2e ./internal/server/...Co-Authored-Bytrailers in commits💬 Notes for Reviewers
This is a stacked PR based on
feat/memory-conflict-surfacing-cloud-syncso the review diff stays scoped to the doctor work instead of reintroducing the prior memory-conflict/cloud-sync branch history.