Skip to content

feat(doctor): detect + repair index-integrity corruption in doctor --fix#64

Merged
tachyon-beep merged 1 commit into
mainfrom
feat/doctor-index-integrity-repair
Jun 22, 2026
Merged

feat(doctor): detect + repair index-integrity corruption in doctor --fix#64
tachyon-beep merged 1 commit into
mainfrom
feat/doctor-index-integrity-repair

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

What

loomweave doctor gains an index.integrity check, and doctor --fix repairs the corruption that aborts analyze at phase3 with LMWV-INFRA-PARENT-CONTAINS-MISMATCH — the recovery surface for clarion-abda98c869.

A file→package refactor (m.pym/__init__.py, same module qualname) leaves a stale file entity + a dangling contains edge in the cumulative index. The SEI orphan pass only retires them after phase3's parent/contains flush, so the run aborts and there was no recovery short of nuking the index.

Detection (read-only)

  • Stale file entities: a core:file:* whose source path is gone from disk.
  • Both directions of the parent/contains invariant (ADR-026 decision 2).

Repair (--fix)

Removes each stale file entity + everything anchored to it (source_file_id); edges/tags/taint/caches cascade. Deletes under defer_foreign_keys = ON and nulls the four NO-ACTION FK columns into entities(id) that do not cascade — entities.parent_id, entities.source_file_id, edges.source_file_id, entity_unresolved_call_sites.source_file_id — so no surviving row dangles at commit. Residual corruption is reported with a analyze --no-incremental rebuild recommendation.

Verified on the live elspeth index

  • Detect: 9 stale file entities + 2 parent/contains mismatches.
  • --fix: removed 9 stale file entities (169 entities total); index is now consistent.
  • analyze then completed (44076 entities, 147044 edges) where it previously aborted at phase3.

The first naive cut hit FOREIGN KEY constraint failed at commit (81 dangling edges.source_file_id between surviving endpoints) — fixed by the null-out pass and pinned by a regression test.

Implementation

  • New loomweave-storage::integrity (check_integrity / repair_integrity) + 4 integration tests (detect, repair+restore, dangling-edge regression, healthy no-op).
  • Wired into doctor's text + JSON paths; gated on a healthy/migrated DB.

Tests

Full floor green: 1854 nextest (+4), clippy -D warnings, doc, fmt; Python 215.

Relates to clarion-abda98c869; implements clarion-ae7e48003a

🤖 Generated with Claude Code

…-fix`

A file→package refactor (e.g. `m.py` → `m/__init__.py`, same module qualname)
leaves a stale file entity and a dangling `contains` edge in the cumulative
index. The SEI orphan pass only retires them *after* phase3's parent/contains
flush, so `analyze` aborts with `LMWV-INFRA-PARENT-CONTAINS-MISMATCH` and there
was no recovery short of nuking the index. (Root-cause writer fix tracked in
clarion-abda98c869; this is the recovery surface.)

`loomweave doctor` now runs an `index.integrity` check:
- detects stale file entities (a `core:file:*` whose path is gone from disk) and
  both directions of the parent/contains invariant (ADR-026 decision 2);
- `--fix` removes each stale file entity and everything anchored to it
  (`source_file_id`); edges/tags/taint/caches cascade. The delete runs under
  `defer_foreign_keys = ON` and nulls the four NO-ACTION FK columns into
  `entities(id)` that do not cascade (`entities.parent_id`/`.source_file_id`,
  `edges.source_file_id`, `entity_unresolved_call_sites.source_file_id`) so a
  surviving row is never left dangling at commit;
- residual violations not attributable to a stale file are reported with a
  `analyze --no-incremental` rebuild recommendation.

New `loomweave-storage::integrity` module (check_integrity / repair_integrity)
with 4 integration tests incl. a regression for the cross-file
`edges.source_file_id` dangling case. Wired into doctor's text + JSON paths,
gated on a healthy/migrated DB.

Verified on the live elspeth index: detected 9 stale file entities + 2
parent/contains mismatches; `--fix` removed them (169 entities total); analyze
then completed (44076 entities, 147044 edges) where it previously aborted.

Relates to clarion-abda98c869; implements clarion-ae7e48003a

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tachyon-beep tachyon-beep merged commit d02a318 into main Jun 22, 2026
4 checks passed
@tachyon-beep tachyon-beep deleted the feat/doctor-index-integrity-repair branch June 22, 2026 22:11
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