Skip to main content

Shepherd Branch Swarms Beat Public-Test Overfitting: 100% vs. 93.3% (N=3)

Updated 7 min readMarkdown

💡 AI Labo Benchmark Series — Experiment E56 (SwarmResearch Shepherd Search Swarm)

Part of our controlled benchmark series testing AI coding agent harnesses inside network-isolated Proxmox VMs (N=3 counterbalanced AB/BA/AB trials, temperature=0.7, 3-UID grading, 90% prefix-cache cost accounting).

A single-threaded coding agent running hill-climbing against a benchmark has a dangerous blind spot: the moment it hits 1000 / 1000 on the public eval suite, it stops—even if its solution silently overfits the public fixture's bounds.

Inspired by SwarmResearch (arXiv:2607.02807), we pitted a Shepherd + Isolated Branch Swarm (Round-1 diverse Explorers ➔ SearchLedger ➔ Round-2 Optimizer with peer-code cross-pollination) against Single-Thread Hill Climbing (with revert_to_best checkpointing) on models/gemini-4-carbon (MEDIUM, N=3).


TL;DR — Key Empirical Findings

  • 1. 100.0% Unseen Generalization (32/32) vs. Public-Test Overfitting (93.3%): Both modes scored 1000.0 / 1000.0 on the public 4-regime specinfer scheduler benchmark across all 3 trials. Yet on 32 unseen grading cases (12 feasibility invariants + 20 continuous optimization tests), Candidate (Shepherd Swarm) scored 32.00 ± 0.00 / 32 (100.0%) with 99.9967 ± 0.0058% unseen optimality (3/3 trials), whereas Baseline (Single-Thread Hill Climbing) dropped to 27/32 (80.0% optimality) in Trial 1—missing a tight-KV eviction check (to_free > len(evictable_blocks))—and averaged 30.33 ± 2.89 / 32 (93.33 ± 11.55% optimality).
  • 2. Zero-Contamination Fault Isolation in Trial 2: In Trial 2 Round 1, Candidate's second Explorer (exp_dp_offline_ils) hit MAX_TOKENS (24,576) three turns in a row and exited with 0.0 score. Because branches run in isolated BranchWorktreeStore copies and fresh contexts, Explorer 1 (exp_portfolio_beam, 1000.0) remained untouched—Shepherd forked it into Round-2 opt_hybrid_polish and hit 32/32 (100.0%).
  • 3. Fresh Branch Conversations Cost +59.54% Under 90% Cache Discount: Candidate cut tool output noise by -62.97% (55,641.7 ➔ 20,601.3 chars), and Shepherd orchestration cost just `$0.1635` (7.1% of total). However, cold-starting 3 separate branches slashed implicit cache hits by -75.88% (159,147 ➔ 38,379 tok) and raised uncached input +169.05%, pushing effective cached cost from `$1.4470` to `$2.3085` (+59.54%)—directly motivating our follow-up cost ablation (E56a).
Metric (N=3 Trials, Mean ± SD) Baseline: Single-Thread Hill Climbing Candidate: Shepherd Branch Swarm Delta / Effect
Public 4-Regime Benchmark 1000.00 ± 0.00 1000.00 ± 0.00 100% tie on public suite
Hidden Grading Suite (32 Cases) 30.33 ± 2.89 ([27–32], 94.79%) 32.00 ± 0.00 ([32–32], 100.0%) +1.67 tests (3/3 wins)
Unseen Continuous Optimality 93.33 ± 11.55% ([80–100%]) 99.9967 ± 0.0058% +6.66 pt (+13.3 pt sched/eng)
Tool Output Volume (chars) 55,641.7 ± 5,328.1 20,601.3 ± 577.2 -62.97% context noise cut
Total LLM Calls (budget 14) 9.33 ± 0.58 14.00 ± 0.00 (4 Shep + 10 Br) +50.0% (uses full 14-call cap)
Cached Input (cached_tokens) 159,147.0 (65.6% hit) 38,379.0 (14.6% hit) -75.88% (fresh branch penalty)
Visible Output (candidates) 26,602.7 57,217.0 +115.08% (3 parallel rewrites)
Standalone Time (elapsed_seconds) 1,337.48s ± 259.87s 1,932.81s ± 505.15s +44.51% (serial branch harness)
Effective Cached Cost (90% OFF) `$1.4470 ± $0.2150` `$2.3085 ± $0.4402` +$0.8615 (+59.54%)
List-Price Upper Bound (No Cache) `$1.7335 ± $0.2364` `$2.3776 ± $0.3862` +37.16% (`+$0.6441`)
Total MAX_TOKENS Truncations 7 across 3 trials 12 across 3 trials Fixed in E56a

1. Experiment Design & Architecture

+-----------------------------------------------------------------------+
| Proxmox VM260 (0 NICs, gemini-4-carbon MEDIUM, temp=0.7, max 14 calls)|
| Task: Speculative Decoding Tree, KV Eviction & Batch Scheduler (32 T) |
|                                                                       |
| Baseline (Single-Thread Hill Climbing + auto revert_to_best):         |
|   1 worktree -> hits 1000/1000 public on T1 -> stops early            |
|   -> Misses tight-KV unseen check (to_free > evictable) -> 27/32      |
|                                                                       |
| Candidate (Shepherd Search Swarm + BranchWorktreeStore):              |
|   R1 Shepherd -> Explorer 1 (Branch A) & Explorer 2 (Branch B)        |
|     -> SearchLedger isolates R1 failures (e.g. T2 Exp2 3x MAX_TOKENS) |
|   R2 Shepherd -> Forks best Explorer into Optimizer (+ peer code)     |
|     -> Hardens edge cases -> checkout_and_submit -> 32/32 (3/3 trials)|
+-----------------------------------------------------------------------+

Because Round 2 Optimizer always ran a structured hardening pass comparing surviving Round-1 branches—even after Explorers hit 1000.0 public—Candidate caught edge-case bounds that Baseline stopped checking once the public score hit 1000.0.


2. Drop-In Implementation Recipe: BranchWorktreeStore + SearchLedger

Isolate exploratory hypotheses on separate filesystem snapshots and pass a byte-identical shared prefix across branches so they do not sacrifice prompt caching:

import shutil
from dataclasses import dataclass, field
from pathlib import Path


@dataclass
class BranchRecord:
    branch_id: str
    parent_id: str
    workdir: Path
    public_score: float = 0.0
    evaluated: bool = False
    error_note: str = ""


@dataclass
class SearchLedger:
    root_dir: Path
    branches: dict[str, BranchRecord] = field(default_factory=dict)

    def fork_branch(self, branch_id: str, parent_dir: Path, parent_id: str = "seed") -> Path:
        dst = self.root_dir / branch_id
        if dst.exists():
            shutil.rmtree(dst)
        shutil.copytree(parent_dir, dst)
        self.branches[branch_id] = BranchRecord(branch_id=branch_id, parent_id=parent_id, workdir=dst)
        return dst

    def record_result(self, branch_id: str, score: float, evaluated: bool, note: str = "") -> None:
        rec = self.branches[branch_id]
        rec.public_score, rec.evaluated, rec.error_note = score, evaluated, note

    def select_best_parent(self) -> BranchRecord:
        valid = [b for b in self.branches.values() if b.evaluated and b.public_score > 0.0]
        if not valid:
            raise RuntimeError("ALL_EXPLORERS_FAILED: no evaluated parent branch to fork")
        return max(valid, key=lambda b: b.public_score)
  • Why this works: Failed branches (evaluated=False, score=0.0) are quarantined in their own directories and cleanly skipped by select_best_parent(), while Round-2 Optimizer forks only the strongest verified snapshot.

3. Threats to Validity & When NOT to Use This

  1. max_output_tokens=24576 Truncation Confounder: Generating 4 full modules in one turn caused 7 MAX_TOKENS hits in Baseline and 12 in Candidate (wasting $6.07 of the $11.27 3-trial suite spend!). See E56a for how fixing the model tier and output-truncation problem slashed suite cost by -94.94%.
  2. Cache Asymmetry & Serial Relay (N=3): Baseline enjoyed 65.6% implicit cache hits by appending to one conversation, while Candidate's fresh branch histories fell to 14.6%. Explicit context caching (cachedContents) and parallel branch dispatch are needed to close the +59.54% gap.
  3. When Baseline Is Enough: For CRUD fixes or tasks with exhaustive local tests where public-test overfitting is unlikely, single-thread hill climbing is 1.6x cheaper.
📋 Experiment Metadata & Reproducibility
  • Experiment ID: E56 (C052 / SwarmResearch arXiv:2607.02807 / Benchmark v2.1)
  • Run ID: e56-20261120-vm260-01 (N=3 trials: AB ➔ BA ➔ AB, temperature=0.7)
  • Sandbox Environment: Proxmox Isolated VM VM260 (0 NICs, PrivateNetwork=yes, 3-UID isolation: labexp56 / labrunner56 / labjudge56)
  • Model & Thinking Level: models/gemini-4-carbon (thinkingLevel="MEDIUM", max_output_tokens=24576, MAX_MODE_CALLS=14)
  • Cost Accounting: Google 90% implicit prefix-cache discount (effective_cached_micro_usd) as primary metric; list-price upper bound reported alongside.

Discussion: When your agent hits 100% on local tests, do you stop immediately—or run a second adversarial/edge-case pass to catch hidden benchmark overfitting?

🔗 Continue Reading the Series

No comments yet. Be the first to comment.