Section 04: Reviewer Wiring + Mechanical Enforcement
Status: Complete
Goal: Close the “training-only enforcement” gap Opencode flagged during /tp-help. Reviewers recognize the new PLAN_ROUTING_DRIFT category by virtue of the grounding preamble reading impl-hygiene.md (§02’s work) — but training-only failed to prevent 22 re-route plans accumulating. Mechanical gate at plan_corpus check --strict-recon time catches drift before reviewers do.
Success Criteria:
-
tp_agent_prompt.mdcarries a PLAN_ROUTING_DRIFT sample finding in its return-schema examples (connects to mission criterion: “Reviewers flag new peer plans without Fallback-R justification as CRITICAL”) -
plan_corpus check --strict-reconfires an ERROR (exit 1) forplans/<name>/index.mdwithreroute: trueAND missingrouting_justification: - Synthetic sibling
/tmp/test-sibling/withreroute: truebut no justification triggers PLAN_ROUTING_DRIFT -
/review-planrole: hybrid — no--called-by-orchestratorbranch needed (the finding category is constant)
Context: All three reviewers during /tp-help agreed: finding categories are schema-definition-time, not invocation-time. Severity is set in impl-hygiene.md (landed in §02); reviewers pick it up from grounding. The gap is mechanical enforcement — the 2026-04-24 sibling-fix-BUG ban relied on reviewer training only, and 22 re-route plans accumulated anyway. This section adds the belt-and-suspenders plan_corpus validator gate.
Reference implementations:
tp_agent_prompt.mdexistingrule_violated:examples — format to mirror for the new category.scripts/plan_corpus/schemas.pyTprInfo validator — precedent for “field X is required when field Y is true” conditional validation.- Sibling fix-BUG ban (2026-04-24) — precedent for how training-only enforcement fails at scale; motivation for the mechanical gate.
Depends on: Section 02 (PLAN_ROUTING_DRIFT category must exist in impl-hygiene.md before reviewer example can reference it), Section 03 (plan_routing.py must exist to verify the synthetic sibling case in 04.3).
Intelligence Reconnaissance
Queries run 2026-04-24:
grep -c "rule_violated:" .claude/skills/tpr-review/tp_agent_prompt.md— counts existing category examples.grep -n "TprInfo\|@dataclass" scripts/plan_corpus/schemas.py— locates validator pattern precedent.scripts/intel-query.sh --human callers "classify_bug_exclusion" --repo ori— confirms bug_markers.py is imported by two scanners, validating the SSOT pattern we’re mirroring.
Results summary (≤500 chars) [ori]: tp_agent_prompt.md return-schema already has rule_violated: example lines for existing categories (INVERTED-TDD, LEAK, DRIFT); adding PLAN_ROUTING_DRIFT is a one-line addition. scripts/plan_corpus/schemas.py uses @dataclass(frozen=True) validators (e.g., TprInfo for third_party_review: nested block validation) — same pattern applies for routing_justification: conditional-required validation.
See .claude/skills/query-intel/compose-intel-summary.md for the full query protocol.
04.1 Add PLAN_ROUTING_DRIFT example to tp_agent_prompt.md
File(s): .claude/skills/tpr-review/tp_agent_prompt.md
Locate the return-schema / rule_violated: example block and add a new example finding.
-
grep -n "rule_violated:" .claude/skills/tpr-review/tp_agent_prompt.md→ identify insertion point -
Add a sample finding example near existing category examples:
- id: "EXAMPLE-1" severity: "critical" path: "plans/new-cross-cutting-work/index.md" line: 2 title: "Sibling plan created without routing_justification — PLAN_ROUTING_DRIFT" evidence: "plans/new-cross-cutting-work/index.md has reroute: true but no routing_justification: field; scope touches ori_arc + ori_llvm with primary-by-count mapping to section-21A-llvm (should have been a subsection, not a peer directory)" rule_violated: ".claude/rules/impl-hygiene.md §Finding Categories — PLAN_ROUTING_DRIFT (Critical)" recommended_fix: "Run `python3 scripts/plan_routing.py --scope ori_arc,ori_llvm` to get the mechanical routing decision; either (a) migrate the plan's content into a subsection of section-21A-llvm per the helper's output, or (b) add routing_justification: explaining why the plan cannot live as a subsection (e.g., if primary-by-count returns a tie)." -
Run prose-lint:
python3 scripts/prose-lint.py .claude/skills/tpr-review/tp_agent_prompt.mdexits 0 -
Verify grep:
grep -c "PLAN_ROUTING_DRIFT" .claude/skills/tpr-review/tp_agent_prompt.mdreturns at least 1 -
Subsection close-out (04.1) — MANDATORY before starting 04.2:
- Example added and grep-verified; prose-lint green
- Update this subsection’s
statustocomplete - Repo hygiene check —
compiler_repo/diagnostics/repo-hygiene.sh --check
04.2 Add mechanical plan_corpus check —strict-recon rule
File(s): scripts/plan_corpus/schemas.py (validator addition), scripts/plan_corpus/bug_validators.py or new scripts/plan_corpus/plan_validators.py
Conditional-required validation: routing_justification: str must be present when reroute: true; must be absent when reroute: false or reroute is None.
-
Decide placement: extend existing
bug_validators.py(if generic enough) OR createscripts/plan_corpus/plan_validators.pyfor plan-level checks; prefer the latter for SRP -
Implement validation function:
def validate_reroute_routing_consistency(plan_index_path: Path, fm: dict) -> list[str]: """Returns list of diagnostic strings; empty = clean.""" diagnostics = [] reroute = fm.get("reroute") justification = fm.get("routing_justification") if reroute is True and not justification: diagnostics.append( f"{plan_index_path}: reroute: true requires routing_justification: (see CLAUDE.md §Plan Routing — Mechanical)" ) if reroute is not True and justification: diagnostics.append( f"{plan_index_path}: routing_justification: is only permitted when reroute: true (currently reroute={reroute})" ) return diagnostics -
Wire the validator into
plan_corpus check --strict-recondispatch so findings surface as ERRORs (exit 1), not WARNINGs -
Verify by running
python -m scripts.plan_corpus check --strict-recon plans/on the current tree — should emit findings for any existing re-route plan lackingrouting_justification:. If findings fire on current state, that’s expected — §05 migration clears them. For now, document which plans trip the gate in this section’s Manifest Appendix -
Add unit test: fixture plan with
reroute: true+ missingrouting_justification:→ validator returns 1 diagnostic; fixture with both present → 0 diagnostics; fixture withrouting_justification:butreroute: false→ 1 diagnostic (forbidden) -
Subsection close-out (04.2) — MANDATORY before starting 04.3:
- Validator added + unit-tested
-
plan_corpus check --strict-reconsurfaces PLAN_ROUTING_DRIFT ERRORs on bad fixtures and current non-compliant plans - Update this subsection’s
statustocomplete - Repo hygiene check —
compiler_repo/diagnostics/repo-hygiene.sh --check
04.3 Dry-run verification on synthetic sibling plan
File(s): /tmp/test-sibling-plan/ (scratch only — not committed)
End-to-end verification: the full reviewer chain catches the drift mechanically.
-
Create synthetic fixture:
mkdir -p /tmp/test-sibling-plan cat > /tmp/test-sibling-plan/index.md <<'EOF' --- name: "Test Sibling" full_name: "Test Sibling Plan (Should Fire Drift)" status: queued reroute: true # routing_justification: INTENTIONALLY OMITTED to trigger drift --- # Test Sibling Plan EOF cat > /tmp/test-sibling-plan/00-overview.md <<'EOF' --- plan: "test-sibling" title: "Test Sibling" status: not-started --- # Test Sibling ## Mission This is a test fixture that should trigger PLAN_ROUTING_DRIFT. EOF -
Run
python -m scripts.plan_corpus check --strict-recon /tmp/test-sibling-plan/→ expect exit 1 with PLAN_ROUTING_DRIFT message namingrouting_justificationrequirement -
Run
/tpr-review --help-mode --max-rounds=1 --prompt-file=<objective citing /tmp/test-sibling-plan/ as the review target>— expect at least one reviewer to flag PLAN_ROUTING_DRIFT Critical (this is the dry-run verification per /create-plan Phase 5 cohesion pattern) -
Cleanup:
rm -rf /tmp/test-sibling-plan/ -
Record dry-run outcome in this section’s Manifest Appendix Part E (add below at end of section): which reviewer(s) fired the finding, at which severity
-
Subsection close-out (04.3) — MANDATORY before starting 04.N:
- Dry-run confirms both mechanical gate AND reviewer-training gate fire on the synthetic case
- Update this subsection’s
statustocomplete - Repo hygiene check —
compiler_repo/diagnostics/repo-hygiene.sh --check
04.N Completion Checklist
- All implementation subsections (04.1–04.3) are
[x]and statuscomplete - All section success criteria have corresponding
[x]checkboxes -
grep -c "PLAN_ROUTING_DRIFT" .claude/skills/tpr-review/tp_agent_prompt.mdreturns ≥1 -
python -m scripts.plan_corpus check --strict-reconon synthetic bad fixture exits 1 with PLAN_ROUTING_DRIFT diagnostic -
pytest compiler_repo/tests/plan-routing/(extended with validator tests from 04.2) exits 0 -
./test-all.shgreen — regression canary - Plan sync:
- This section’s frontmatter
status→complete, subsection statuses →complete -
00-overview.mdQuick Reference: Section 04 status →Complete -
00-overview.mdmission success criteria: check off reviewer-wiring completion -
index.mdSection 04 status →Complete
- This section’s frontmatter
- Repo hygiene check —
compiler_repo/diagnostics/repo-hygiene.sh --check
Exit Criteria: Reviewer example published; mechanical gate rejects malformed siblings at plan_corpus check --strict-recon; synthetic fixture dry-run fires PLAN_ROUTING_DRIFT Critical from both enforcement paths.