Skip to content

feat(farm): best-of-N sampling + iterative retries + sampling params (first-time-go, Slice 1)#137

Merged
SUaDtL merged 3 commits into
mainfrom
feat/farm-best-of-n
Jun 26, 2026
Merged

feat(farm): best-of-N sampling + iterative retries + sampling params (first-time-go, Slice 1)#137
SUaDtL merged 3 commits into
mainfrom
feat/farm-best-of-n

Conversation

@SUaDtL

@SUaDtL SUaDtL commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

What

Slice 1 of the docs/reports/2026-06-26-farm/ deep review — opt-in levers to raise the --farm worker's first-time-go acceptance, spending only the cheap worker-token axis. --farm stays a Feature Forge preview (off by default); FARM_SAMPLES=1 + default knobs are behaviorally unchanged (pinned by a regression test).

F1 — best-of-N against the gate (FARM_SAMPLES, default 1)

The gate is a deterministic pass/fail oracle and each task runs in an isolated worktree, so N candidates are drawn in parallel (each in its own scratch worktree cut from the task's frozen baseline) and the first to pass the gate wins; the winner's files are taken into the task worktree and merged, losers discarded. A shared limiter caps total in-flight worker calls at FARM_CONCURRENCY — sampling shares the budget, never multiplies it. farm-report.json records both the summed sample-token spend and the accepted candidate's own tokens, so the N×-tokens trade-off is visible.

F4 — sampling params (FARM_TEMPERATURE, FARM_MAX_TOKENS)

The chat body now carries temperature (default 0; auto-bumped to 0.7 when FARM_SAMPLES>1 and temperature is unset, so samples diversify) and an optional max_tokens cap.

F2 — iterative retries

On a retry (failed gate, or a sampling round with no green) the worker is shown its own prior in-scope output, not just the gate-failure tail, so it refines rather than restarts blind — through the same FARM_ENRICH_MAX_BYTES cap + secret-redaction + secret-filename-denylist chokepoint as all injected context. Out-of-scope drift is never carried forward.

Scope decisions (at the sprint gate)

  • F8 (worker sandboxing) → descoped to an ADR. ca-sandbox is a Docker/clone-into-container model that doesn't fit the farm's host-worktree architecture, and there's no agentic worker yet to protect; it'll be designed against the real consumer when Track 2 is scoped (ties to CONFIRM-05).
  • F3 (auto-context enrichment) → Slice 2 (planned after this merges; that's where the trust-boundary gate fires).

Verification

  • 169 vitest green (typecheck clean), incl. a real-worktree best-of-N smoke test (3 samples, winner merged to integration, scratch cleaned) and an N=1 regression pin.
  • farm.js rebuilt and in sync; version bumped 2.5.2 → 2.6.0 (badge + CHANGELOG).

Independent two-pass review (pre-PR)

  • Security: PASS — 0 CRIT/HIGH/MED. F2 re-injection preserves the redaction/cap/denylist invariants; bearer token + assertSecureBaseUrl intact, no new egress.
  • Correctness/spec-compliance: SHIP — 0 BLOCK/HIGH. AC-F1.1/F1.4 verified sound.
  • Two MEDIUM (worktree-leak-on-throw, sample-baseline skew) + three LOW were all applied in the fix commit (see .codearbiter/sprint-log.md).

Generated autonomously via /ca:sprint; full decision log in .codearbiter/sprint-log.md.

https://claude.ai/code/session_011nnQYBPd5Dt1rmtf9CHNfU

SUaDtL added 3 commits June 26, 2026 00:48
Slice 1 of the 2026-06-26-farm deep-review. Opt-in worker-quality levers that
spend the cheap worker-token axis; FARM_SAMPLES=1 is behaviorally unchanged.

- F1 best-of-N (FARM_SAMPLES): N candidates drawn in parallel in isolated
  scratch worktrees, the first to pass the deterministic gate wins; a shared
  FARM_CONCURRENCY limiter caps TOTAL in-flight worker calls (never N x it).
  Token spend summed across samples + the accepted candidate's own tokens
  surfaced in farm-report.json.
- F4 sampling params: temperature (auto-bumped off 0 when N>1 so samples
  diversify) and an optional max_tokens cap on the worker call.
- F2 iterative retries: the worker is shown its own prior in-scope output
  (through the existing byte-cap + secret-redaction chokepoint), not just the
  gate-failure tail, so it refines rather than restarts.

167 tests green (incl. a real-worktree best-of-N smoke test + an N=1 regression
pin); typecheck clean; farm.js rebuilt. F8 (worker sandbox) descoped to an ADR;
F3 (auto-context) is Slice 2.

Claude-Session: https://claude.ai/code/session_011nnQYBPd5Dt1rmtf9CHNfU
…review report

Governance trail for the best-of-N sprint: the approved Slice-1 spec and plan,
the append-only SMARTS decision log, and the docs/reports/2026-06-26-farm
deep-review report that seeded the scope (F1/F2/F4 in; F8 -> ADR; F3 = Slice 2).

Claude-Session: https://claude.ai/code/session_011nnQYBPd5Dt1rmtf9CHNfU
…line, input guards

Independent review (security PASS, correctness SHIP; no BLOCK/HIGH) surfaced two
MEDIUM + LOW items, all applied:

- M1: a best-of-N sample that THROWS now resolves to a failure outcome (per-sample
  try/catch), so Promise.all never rejects and the scratch-worktree cleanup loop
  always runs — no worktree leak on the exception path.
- M2: samples are cut from the TASK branch (a frozen integration-at-task-start
  snapshot), not the live farm/integration ref, so every sample shares the exact
  baseline the task worktree re-gates and merges against (AC-F1.2) — removes a
  false-escalation window when a sibling task merges mid-flight.
- L1: non-numeric FARM_SAMPLES falls back to 1 instead of NaN (which would empty
  every sample batch and silently mass-escalate the run).
- L2: an explicitly-set FARM_TEMPERATURE=0 is no longer auto-bumped to 0.7.
- L3: prior-attempt context is shown only when the prior worker actually wrote
  files (no mislabeling inherited baseline as "your previous attempt").
- security LOW: worker-error and setup notes are wrapped in redactSecrets for
  parity with the gate/merge notes.

169 vitest green (+2: throwing-sample, non-numeric-samples); typecheck clean;
farm.js rebuilt.

Claude-Session: https://claude.ai/code/session_011nnQYBPd5Dt1rmtf9CHNfU
@SUaDtL
SUaDtL merged commit 572c744 into main Jun 26, 2026
20 checks passed
@SUaDtL
SUaDtL deleted the feat/farm-best-of-n branch June 26, 2026 12:49
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