Skip to content

feat(curator): generalise integrity-repair escalation to all invariant kinds#13

Merged
nickroci merged 1 commit into
mainfrom
feat/generalize-invariant-repair
May 28, 2026
Merged

feat(curator): generalise integrity-repair escalation to all invariant kinds#13
nickroci merged 1 commit into
mainfrom
feat/generalize-invariant-repair

Conversation

@nickroci

Copy link
Copy Markdown
Owner

Summary

Generalises the just-merged broken-wikilink repair escalation so ALL three check_invariants kinds flow through the SAME enqueue -> Librarian-proposes -> Scholar-executes pipeline and the SAME in-flight concurrency guard, kind-dispatched (one mechanism, not three copy-pasted paths).

  • overcap_dir — a flat dir over MAX_FLAT_DIR_ENTRIES enqueues a repair task; the Librarian proposes a split_folder / move_entry rebalance.
  • bad_frontmatter — a missing / unparseable / incomplete frontmatter block enqueues a task; the Librarian proposes an update_entry that re-serialises valid frontmatter.
  • Scholar-prompt audit — repair-originated proposals (packets carrying repair_fingerprints) are now explicitly verify-and-execute, not judged for novelty/dedupe, so the APPROVE-OR-VETO + salience-novelty framing can no longer wrongly veto a fix as "not novel"/"duplicate".

How it works

  • scholar_prompt.check_invariants_detailed() returns structured InvariantViolations carrying (repair_kind, file, target, context); check_invariants() is now a thin string-list projection over it (public contract preserved).
  • Over-cap and bad-frontmatter violations carry the fields to build a repair_queue.RepairTask. The Scholar's post-write _check_invariants_safe escalates each via _escalate_invariant_violation, reusing RepairQueue.enqueue + the in-flight fingerprint guard. Wikilinks (display-only here) still escalate via the dedicated deterministic repair pass; READMEs stay display-only (reconciler fixes them).
  • The violation is left on disk, so it re-detects and re-escalates until fixed — no max-attempts, no give-up. The incoming packet's marker clears in review()'s finally, exactly as for wikilinks.
  • The Librarian prompt's INTEGRITY-REPAIR section now dispatches on kind with per-kind repair recipes.

Test plan

  • uv run --frozen ruff check . && uv run --frozen ruff format --check .
  • uv run --frozen pyright (0 errors)
  • uv run --frozen pytest — 583 passed, 90.45% coverage (>=90%)
  • duplicate-code pylint gate — no findings (10.00/10)
  • New tests: over-cap producer enqueues + in-flight guard; bad-frontmatter producer enqueues + guard; marker-release-then-reescalate; Librarian prompt handles the new kinds; Scholar-prompt repair-exemption framing; structured check_invariants_detailed projection + escalatable/display-only kinds.

🤖 Generated with Claude Code

…t kinds

Today only broken wikilinks escalate into the Librarian->Scholar pipeline.
Extend the SAME mechanism (enqueue -> Librarian researches+proposes ->
Scholar executes) and the SAME in-flight concurrency guard to the other
two check_invariants kinds, kind-dispatched rather than copy-pasted:

  - overcap_dir: a flat dir over MAX_FLAT_DIR_ENTRIES enqueues a repair
    task; the Librarian proposes a split_folder / move_entry rebalance.
  - bad_frontmatter: a missing/unparseable/incomplete frontmatter block
    enqueues a task; the Librarian proposes an update_entry that
    re-serialises valid frontmatter.

check_invariants now projects over a new structured check_invariants_detailed
that carries the (kind, file, target, context) needed to build a RepairTask.
The Scholar's post-write check escalates each over-cap / bad-frontmatter
violation through the existing repair_queue + in-flight guard
(_escalate_invariant_violation), leaving the violation on disk so it
re-detects and re-escalates until fixed (no max-attempts, no give-up).
The Librarian prompt's INTEGRITY-REPAIR section now dispatches on `kind`.

Also audit the Scholar prompt: the APPROVE-OR-VETO + salience-novelty
framing could wrongly veto a repair proposal as "not novel" / "duplicate".
Add an INTEGRITY-REPAIR PROPOSALS section that marks repair-originated
proposals (packets carrying repair_fingerprints) as verify-and-execute, not
novelty-judged, and have the salience filter skip them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nickroci nickroci merged commit 238e7a0 into main May 28, 2026
4 checks passed
@nickroci nickroci deleted the feat/generalize-invariant-repair branch May 28, 2026 18:30
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