0%

Section 03: Orchestrator Rewrite

Status: Not Started Goal: Make the rewrite a localized SKILL.md edit that swaps Agent dispatch for Bash dispatch, lifts the bounded retry into the orchestrator, and trims the §9 / §11.P prose accordingly. After this section: §5 round-loop logic, §8a scratch-dir setup, §8b prompt composition, §8e shadow-edit absorption, §10 plan-TPR integration, §11 round summary, and the §11.5 autonomous carve-out are all unchanged. The rewrite is purely transport-layer.

Success Criteria: (echoes frontmatter — verifiable from the diff against tpr-review/SKILL.md HEAD)

  • §8c dispatch shape: len(REVIEWERS) foreground Bash tool calls in one assistant message, no Agent({subagent_type:..., model:'sonnet'}) calls
  • §8c.1 (NEW) extraction shape: len(REVIEWERS) Bash extract-report.py + len(REVIEWERS) Read calls, both batches parallel within their respective assistant messages
  • §8c.2 (NEW) retry shape: per-reviewer one-shot retry on tier 4.5/5 first-attempt failures, gated to ≤1 retry per reviewer per round
  • §9 table: 3-status surface preserved; defensive “sub-agent contract violation” row removed; new bash-failure triggers documented
  • §11.P banner: “Sonnet sub-agents” → “Bash dispatches”; wall-clock envelope preserved verbatim
  • Reviewer-set SSOT (I28) preserved by inspection of the dispatch pseudocode

Context: Per §01.2’s resolutions, all four open design questions resolved in favor of the most direct rewrite: harness’s native parallel-tool-call concurrency replaces the Agent transport; orchestrator absorbs the one-retry gate; Skill() callers are unaffected; Monitor was already excised. This section turns that design surface into a concrete edit.

Reference implementations:

  • tpr-review/SKILL.md §8c (current Agent template, lines 624–767) — replaced by the Bash template below
  • tpr-review/SKILL.md §9 (current transport-shape table) — defensive row dropped
  • tp_agent_prompt.md §Step 3.5 — retry logic to lift (deleted in §04 along with the rest of the file)

Depends on: §01 (design resolutions), §02 (baseline measurement).


Intelligence Reconnaissance

Queries run 2026-04-25:

  • scripts/intel-query.sh status — graph available (Neo4j 5.26.24); recorded as proof of protocol.
  • Surface-applicability note: edits are confined to .claude/skills/tpr-review/SKILL.md (markdown). The Ori code-symbol index covers Rust crates only — no graph-resident symbol participates in this rewrite. Recording the unavailability-of-applicability as freeform prose per schema’s Recon-block contract.
  • Surrogate query (grep): grep -n 'subagent_type\|Agent({' .claude/skills/tpr-review/SKILL.md enumerates every Agent dispatch site before editing.

Results summary (≤500 chars) [repo:.claude/skills/tpr-review/SKILL.md]: Edits localized to ~80 lines (§8c rewrite, §9 table trim, §11.P banner one-word swap, §1 description rewrite). Reviewer-set SSOT (I28) drives dispatch-loop shape — rewrite preserves “iterate REVIEWERS, emit len(REVIEWERS) tool calls, PRE-FLIGHT GATE checks count” exactly; only the tool kind switches Agent→Bash. No [ori] graph-resident Rust symbol touches this surface; correctness verified by §04.3 corpus replay [repo:.claude/skills/improve-tooling/tpr-review-design.md].


03.1 Replace §8c Agent dispatch with parallel foreground Bash

File(s): .claude/skills/tpr-review/SKILL.md (§8c body)

The dispatch message shape is preserved bit-for-bit; only the tool kind changes. The PRE-FLIGHT GATE language stays — the gate now counts Bash calls instead of Agent calls.

  • Edit §8c step 8c — Replace the canonical template. Replace today’s three Agent({subagent_type:..., model:'sonnet', description:..., prompt: <tp_agent_prompt.md...>}) blocks with three Bash({command:'bash invoke-{R}.sh "$scratch"', timeout: 2700000}) blocks. Use a for R in REVIEWERS loop in the pseudocode rather than three named blocks — preserves I28.

    Target shape (paste into SKILL.md):

    <assistant message begin>
      <§11.P status text — ≤2 lines, mandatory>
      Bash({ command: 'bash .claude/skills/tpr-review/invoke-${REVIEWERS[0]}.sh "$scratch"',  timeout: 2700000 })
      Bash({ command: 'bash .claude/skills/tpr-review/invoke-${REVIEWERS[1]}.sh "$scratch"',  timeout: 2700000 })
      Bash({ command: 'bash .claude/skills/tpr-review/invoke-${REVIEWERS[N-1]}.sh "$scratch"', timeout: 2700000 })
    <assistant message end>
  • Edit §8c PRE-FLIGHT GATE — Update tool-name and count rule. Today reads “ALL Agent() calls for this round are in the SAME assistant message”; update to “ALL Bash() dispatch calls for this round are in the SAME assistant message” + “Required Bash count in the dispatch message: EXACTLY len(REVIEWERS) Bash() calls”. Keep the dispatch-shape diagram, dispatch_violation reporting, and the survivor-mode-retry exception clause — they are tool-kind-agnostic.

  • Strip sub-agent prose from §8c. Today’s §8c says “Sub-agents are thin CLI transports with split concerns” + describes how the sub-agent runs bash invoke-{REVIEWER}.sh + describes Tier 0 / 1 / 2 / 3 / 4 / 4.5 / 5 extraction inside the sub-agent + describes I22 banned final-message shapes. Replace with a single concrete paragraph: “The orchestrator dispatches len(REVIEWERS) foreground Bash calls in one assistant message; each call invokes the per-reviewer wrapper invoke-{R}.sh which runs the CLI and tees stdout to $scratch/{R}-stdout.txt. Wall-clock per round is max({R0}, {R1}, {RN-1}) — the harness runs parallel tool calls concurrently. After all Bash calls return, see step 8c.1 for extraction.”

  • Subsection close-out (03.1) — MANDATORY before starting 03.2:

    • §8c body edited with Bash-template + updated PRE-FLIGHT GATE + sub-agent prose stripped
    • Update this subsection’s status in section frontmatter to complete
    • Repo hygiene checkcompiler_repo/diagnostics/repo-hygiene.sh --check clean

03.2 Insert post-dispatch extract-report.py + Read sequence

File(s): .claude/skills/tpr-review/SKILL.md (NEW §8c.1 inserted between §8c and §8d)

The extraction step lives entirely in the orchestrator now.

  • Insert §8c.1 — Extract per-reviewer reports. After the dispatch message returns (all Bash calls terminated with exit codes), the orchestrator emits ONE assistant message with len(REVIEWERS) parallel Bash calls invoking extract-report.py:

    <assistant message begin>
      Bash({ command: 'python3 .claude/skills/tpr-review/extract-report.py "$scratch" --reviewer ${REVIEWERS[0]}'  })
      Bash({ command: 'python3 .claude/skills/tpr-review/extract-report.py "$scratch" --reviewer ${REVIEWERS[1]}'  })
      Bash({ command: 'python3 .claude/skills/tpr-review/extract-report.py "$scratch" --reviewer ${REVIEWERS[N-1]}' })
    <assistant message end>

    Each call’s stdout is one JSON line: {"reviewer": …, "tier": …, "status": …, "report_bytes": …, …}. Capture and parse per reviewer.

  • Insert §8c.1 — Read per-reviewer reports. After the extract-report.py batch returns, ONE assistant message with len(REVIEWERS) parallel Read calls:

    <assistant message begin>
      Read({ file_path: '$scratch/${REVIEWERS[0]}-report.txt'  })
      Read({ file_path: '$scratch/${REVIEWERS[1]}-report.txt'  })
      Read({ file_path: '$scratch/${REVIEWERS[N-1]}-report.txt' })
    <assistant message end>

    Each report is bounded at 16 KB by extract-report.py’s _enforce_report_cap. Reports map directly into the existing parse_tpr_report() consumers in §5 round-loop pseudocode.

  • Update §5 round-loop pseudocode. The line [codex_out, gemini_out, opencode_out] = dispatch_parallel_thin_transports($scratch) (lines ~278 + ~169 in current SKILL.md) is replaced with a 3-step inline expansion: dispatch_parallel_bash($scratch)extract_per_reviewer($scratch)read_per_reviewer_report($scratch). Each step corresponds to one assistant-message round-trip per the §8c / §8c.1 templates above.

  • Subsection close-out (03.2) — MANDATORY before starting 03.3:

    • §8c.1 inserted with both extraction and read templates, parameterized by REVIEWERS
    • §5 round-loop pseudocode updated to call the three new helpers
    • Update this subsection’s status in section frontmatter to complete
    • Repo hygiene check — clean

03.3 Lift Tier 4.5/5 retry into the orchestrator

File(s): .claude/skills/tpr-review/SKILL.md (NEW §8c.2 inserted between §8c.1 and §8d)

Per §01.2 Q1 resolution: keep one bounded retry, lifted from sub-agent into orchestrator.

  • Insert §8c.2 — Bounded one-retry on Tier 4.5/5. After §8c.1’s extract step has produced JSON-line outputs for each reviewer, inspect the tier field. For each reviewer where tier ∈ {4.5, 5} on first attempt:

    • Preserve the first attempt: cp $scratch/{R}-stdout.txt $scratch/{R}-stdout-attempt1.txt; cp $scratch/{R}-report.txt $scratch/{R}-report-attempt1.txt
    • Re-invoke the wrapper (single foreground Bash, timeout: 2700000): bash invoke-{R}.sh "$scratch"
    • Re-run extract-report.py "$scratch" --reviewer {R} against the fresh stdout
    • Re-Read $scratch/{R}-report.txt

    Selection rule (matches tp_agent_prompt.md §Step 3.5 selection logic verbatim):

    1. If either attempt produced tier 1–4 (status: ok), use that attempt’s report. Both → use second.
    2. Else if either attempt produced tier 4.5 (status: partial), use that attempt; both partial → merge per current rules (use attempt with more progress_notes: content; set summary: to “2 attempts, neither reached report emission”).
    3. Else (both tier 5), emit status: failed with summary “2 attempts produced no extractable content”.
  • Pin the retry-budget invariant. Add a one-line invariant beneath the retry block: “MAX 1 retry per reviewer per round. Per-reviewer retries dispatch independently — a tier-4.5 retry on codex does NOT trigger re-dispatch of gemini/opencode.” This preserves the current sub-agent-internal retry semantics.

  • Document the retry as orchestrator-side in §8c.2 and remove the §Step 3.5 reference from §8c. Today §8c references “the sub-agent’s bounded internal retry per tp_agent_prompt.md §Step 3.5”; replace with “the orchestrator’s bounded one-retry gate per §8c.2”.

  • Subsection close-out (03.3) — MANDATORY before starting 03.4:

    • §8c.2 inserted with retry trigger + selection rule + retry-budget invariant
    • §8c sub-agent-Step-3.5 reference rewritten to point at §8c.2
    • Update this subsection’s status in section frontmatter to complete
    • Repo hygiene check — clean

03.4 Adapt §9 transport-shape table and §11.P pre-dispatch banner

File(s): .claude/skills/tpr-review/SKILL.md (§9 table; §11.P banner)

  • Edit §9 transport-shape table. Three preserved rows:

    • okextract-report.py returned tier 1–4; $scratch/{R}-report.txt carries findings:
    • partial — tier 4.5 after retry; report carries progress_notes: only
    • failed — tier 5 after retry; nothing recovered

    ONE row removed:

    • “Sub-agent contract violation (defensive default)” — banned-prose-emission, Agent crash, malformed YAML — these triggers no longer apply. Replacement triggers documented in a new short paragraph above the table:

    Bash-layer transport failures. A reviewer’s foreground Bash call (§8c) may exit non-zero (CLI auth failure, wrapper exit ≠ 0 with empty stdout) or extract-report.py may exit 2 (invocation error). Both are surfaced as status: failed for that reviewer; the survivor matrix below applies unchanged.

  • Preserve the survivor matrix. The 3 / 2 / 1 / 0 survivor matrix is tool-kind-agnostic and unchanged.

  • Edit §11.P pre-dispatch banner. Two surgical edits:

    • “main chat stays quiet until Agents return” → “main chat stays quiet until Bash dispatches return”
    • The wall-clock envelope sentence (“~20–45 min wall-clock, worst-case ~45 min with gemini 429 retries”) is preserved verbatim — wrappers are unchanged
  • Edit the §1 frontmatter description and skill body. Replace “Dispatches the codex, gemini, and opencode CLIs as parallel sub-agents per round” with “Dispatches the codex, gemini, and opencode CLIs as parallel foreground Bash calls per round, with extract-report.py extracting reports inline.” Update the second paragraph mentioning “Sub-agents (Sonnet) are thin CLI transports” — strip and replace with the orchestrator-side description from §03.1.

  • Edit allowed-tools frontmatter list if Agent is no longer used. Today the YAML lists Read, Write, Edit, Bash, Glob, Grep, Agent, Skill. With Agent removed from the dispatch path, audit whether ANY remaining use of Agent exists in /tpr-review (e.g. in §5.5 tie-breaker /independent-review invocation). If not, drop Agent from the allowed-tools list. If yes, keep it but note the surviving call site in a comment.

  • Subsection close-out (03.4) — MANDATORY before starting 03.N:

    • §9 table trimmed (defensive row removed, bash-failure paragraph added)
    • §11.P banner one-word swap landed
    • §1 frontmatter description rewritten; sub-agent body paragraph replaced
    • allowed-tools audited and adjusted
    • Update this subsection’s status in section frontmatter to complete
    • Repo hygiene check — clean

03.N Completion Checklist

  • §8c emits len(REVIEWERS) foreground Bash calls; no Agent({subagent_type:..., model:'sonnet'}) remains in the dispatch path
  • §8c.1 + §8c.2 inserted: extract-report.py batch + Read batch + bounded retry
  • §9 transport-shape table preserves {ok, partial, failed}; defensive row removed; bash-failure triggers documented
  • §11.P banner swap + §1 description rewrite landed
  • Reviewer-set SSOT (I28) preserved — orchestrator iterates REVIEWERS; PRE-FLIGHT GATE counts len(REVIEWERS) Bash calls
  • All four subsections marked status: complete
  • python -m scripts.plan_corpus check plans/inline-tpr-transport/section-03-orchestrator-rewrite.md returns exit 0
  • ./test-all.sh green — regression canary (no compiler code touched)
  • Plan sync — update plan metadata:
    • This section’s frontmatter statuscomplete, all subsection statuses → complete
    • 00-overview.md Quick Reference: §03 status → Complete
    • 00-overview.md mission success criteria: check off any newly satisfied criteria
    • index.md §03 status → Complete
  • Repo hygiene check — clean

Exit Criteria: grep -c 'Agent({.*sonnet' .claude/skills/tpr-review/SKILL.md returns 0 (or only matches a §5.5 /independent-review carve-out that explicitly survives); grep -n 'Bash({.*invoke-' .claude/skills/tpr-review/SKILL.md shows the per-reviewer dispatch sites; python -m scripts.plan_corpus check plans/inline-tpr-transport/section-03-orchestrator-rewrite.md exits 0.