Back to Ruflo

ADR-340: Retrospective Harness Optimization (RHO) for SONA Intelligence Loop

v3/docs/adr/ADR-340-retrospective-harness-optimization.md

3.34.04.5 KB
Original Source

ADR-340: Retrospective Harness Optimization (RHO) for SONA Intelligence Loop

Status: Proposed
Authors: claude (dream-cycle agent, 2026-06-07)
Dream Cycle Issue: Dream Cycle 2026-06-07, intelligence surface
Source: arXiv:2606.05922 — "Retrospective Harness Optimization: Improving LLM Agents via Self-Preference over Trajectory Rollouts"


Context

RHO (arXiv:2606.05922, Grade A, code available: github.com/wbopan/retro-harness) demonstrates that a single self-supervised optimization cycle raises SWE-Bench Pro pass rate from 59% to 78% (+19pp) without any external grading signal. The method:

  1. Selects a diverse coreset of challenging tasks from historical trajectories (stored in ReasoningBank)
  2. Re-executes them in parallel with harness variation candidates
  3. Uses the agent's own pairwise preference comparisons to identify the best harness update
  4. Applies the winning update to the live harness without human validation

Ruflo's current SONA intelligence loop collects trajectory data via hooks post-task --train-patterns and stores it in ReasoningBank, but has no mechanism to retrospectively compare trajectory outcomes and propose harness improvements. The 4-step RETRIEVE → JUDGE → DISTILL → CONSOLIDATE pipeline distills patterns but does not produce harness diffs.

No existing ADR in the 085–130 range covers self-supervised harness optimization. ADR-076 (structured distillation) and ADR-078 (hybrid retrieval and outcome signal) address pattern extraction but not harness self-modification.


Decision

Add a retrospective-optimize subcommand to @claude-flow/hooks that:

  1. Coreset selection — queries ReasoningBank for the N most challenging recent tasks (verdict=failure or low-confidence success, N=20 default), sampled across diverse agent types
  2. Parallel rollout — re-executes the coreset against K harness candidates (K=5 default) generated by sampling MoE expert perturbations of the current harness config
  3. Preference scoring — uses the SONA judge (already wired in post-task) to score each rollout pair; selects the Condorcet winner
  4. Harness update — writes the winning harness delta to ~/.claude-flow/harness.json with a rollback checkpoint; logs the update to the intelligence hook trajectory

The command is designed to run as a nightly background worker (hooks worker dispatch --trigger retrospective-optimize) and does not block interactive sessions.


Consequences

Positive:

  • Expected +15–20pp task success improvement (consistent with Grade A benchmark, same methodology)
  • Self-supervised: no labeled data or human grading required
  • Integrates cleanly with existing ReasoningBank + SONA + MoE infrastructure
  • Rollback checkpoint prevents irreversible harness corruption

Negative / Risks:

  • Parallel rollout of K=5 candidates × N=20 tasks = 100 re-executions per cycle; compute cost must be budgeted (estimate: ~$0.10–0.50 per nightly cycle at Haiku pricing)
  • Self-preference scoring introduces Goodhart's law risk: the agent may optimize for metrics it finds easy to self-evaluate rather than genuine task success
  • Requires SWE-Bench Pro baseline measurement before claiming benchmark parity with arXiv results

Mitigation:

  • Cap nightly budget via --max-budget-usd flag (default 0.25)
  • Require human-in-the-loop approval for harness updates that change >3 parameters (configurable threshold)
  • Instrument baseline before enabling: claude-flow performance benchmark --suite swe-bench-pro

Scope

FileChange
v3/@claude-flow/hooks/src/commands/retrospective-optimize.tsNew command (~200 LOC)
v3/@claude-flow/hooks/src/workers/retrospective-worker.tsBackground worker registration (~80 LOC)
v3/@claude-flow/hooks/src/index.tsExport new command
v3/@claude-flow/memory/src/reasoning-bank.tsAdd getCoreset(n, filter) method (~40 LOC)

Total estimated: ~320 LOC. No breaking API changes.


Alternatives Considered

  • No-op (skip): Accept the 19pp gap vs RHO. Rejected — this is the most significant intelligence SOTA gap identified in the 2026-06-07 cycle and is directly addressable.
  • Full MLEvolve port (arXiv:2606.06473): Evolutionary search over agent configurations. Larger scope (~2000 LOC), higher risk. Deferred to a future ADR after RHO baseline is established.
  • MAGE execution-state memory (arXiv:2606.06090): Orthogonal improvement (token reduction + task success). Recommended as a separate implementation without an ADR (implementation-level change to AgentDB schema).