Skip to content

Add latency-tuner example loop and measurement infrastructure#1

Merged
mboss37 merged 7 commits into
mainfrom
claude/self-improving-loops-rating-ufufj5
Jul 1, 2026
Merged

Add latency-tuner example loop and measurement infrastructure#1
mboss37 merged 7 commits into
mainfrom
claude/self-improving-loops-rating-ufufj5

Conversation

@mboss37

@mboss37 mboss37 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds a complete second example of a self-improving loop — the latency tuner — alongside the existing prompt-technique-tournament example. The latency tuner optimizes a running service's retry policy (timeout, retries, backoff) against replayed production traffic, demonstrating the "optimize-a-running-system" flavor of the framework with time-based holdout validation and operational safety floors.

Key Changes

New latency-tuner example (examples/latency-tuner/):

  • Measurement harness (sim/run_eval.py): Deterministic replay of retry policies against fixed traffic traces, scoring effective latency (per-request elapsed time including errors as penalties)
  • Fixed traffic traces (traces/train.jsonl, traces/holdout.jsonl): 600 holdout requests and ~1000 training requests with pre-drawn upstream latencies and failure modes; checksummed to prevent mid-campaign regeneration
  • Test corpus (sim/test_run_eval.py, sim/test_guardrail.py): Proves trace integrity, replay determinism, and the planted reward-hacking trap (timeout-fast-fail-cheap) that the metric must resist
  • Loop agents and commands: Evaluator, proposer, implementer, gate, and meta-improver agents; /iterate command orchestrating the full cycle
  • Safety infrastructure: Guardrail hook blocking destructive operations and trace regeneration; hard error-rate floor (2%) enforced mechanically
  • Methodology documentation (GOAL.md, METHODOLOGY.md, PERSONA.md): Defines the optimization target, window discipline (train/holdout split), and the skeptical reliability engineer persona

Shared tooling (copied to all three locations: template, prompt-technique-tournament, latency-tuner):

  • verdict.py: Mechanical gate for statistical certification — implements screen, reproduce, confirm, compare, floor, and self-test modes; fails closed on undeclared search size
  • metric-contract.sh: Pre-loop validation that the metric is numeric, deterministic, and able to distinguish good from bad
  • metric-contract.env: Configuration for metric contract validation

Template and CI updates:

  • Updated root README.md with ASCII art, clearer positioning, and quick-start instructions
  • Extended template/INSTANTIATE.md with Step 0 (prove your metric) and clarified gate methodology
  • Added sandbox infrastructure (template/sandbox/): Dockerfile, macOS Seatbelt profile, systemd service/timer, and run-sandboxed.sh wrapper for OS-level jailing
  • Updated .github/workflows/ci.yml to run tests for both examples in parallel

Notable Implementation Details

  • Deterministic replay: Same config on the same trace window produces identical scores byte-for-byte, making gate arithmetic trustworthy
  • Planted trap: The metric teaches reward-hacking — timing out fast and failing cheap improves latency percentiles while users see errors; the effective-latency metric (elapsed time with error penalties) resists this
  • Checksum-pinned traces: SHA256 hashes in test assertions prevent accidental or malicious trace regeneration mid-campaign
  • Fail-closed verdict: verdict.py refuses to certify without an explicitly declared search budget (Bonferroni deflation), preventing p-hacking
  • Holdout as out-of-time: Unlike the tournament's out-of-sample holdout, this uses a later time window (degraded upstream) to validate generalization to future conditions
  • Write-tool gating: The guardrail hook blocks edits to protected paths (traces/, guardrail.sh itself) so the loop cannot weaken its own safeguards

The latency tuner runs fully offline and deterministic — no API key, no network — making it ideal for testing the framework's measurement and gating machinery before deploying to a live domain.

https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx

claude added 7 commits July 1, 2026 20:30
A plausible-but-wrong gain fools judgment; it cannot fool an exact sign
test deflated by a search budget the tool refuses to run without.
verdict.py ships the METHODOLOGY rules as executable modes (screen,
reproduce, confirm, compare, floor, self-test), the gate agents treat
its REJECT as binding, and the tournament's trap and final claim are
now certified mechanically in tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx
The loop is only as good as its prove command, and a broken metric
silently certifies bad changes. Step 0 of instantiation is now a
runnable contract — numeric, deterministic, and able to score a
planted-bad control worse than a known-good — re-run at triage
whenever measurement is in doubt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx
A wedged or over-eager unattended iteration needs a mechanical budget
floor exactly like the safety floor: ITER_MAX_TURNS caps agent turns
per tick (default 50, raise deliberately), alongside the existing
wall-clock time-box.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx
The docs have always said the deny-list is a tripwire and the real
boundary is an OS sandbox — now the sandbox ships ready to adapt:
a container image + locked-down runner, a hardened systemd
unit/timer pair, and a macOS Seatbelt profile, each keeping the
floor files read-only even inside the writable area.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx
…xample

The latency tuner exercises everything the tournament cannot: a
time-based out-of-time holdout with a regime shift, a hard error-rate
floor, continuous-metric certification via the paired bootstrap, and
the cheap-error reward-hack encoded into the metric itself. Its
planted trap tops the train leaderboard and runs 4x the error budget
on the holdout window — the gate must kill the best-looking config on
the board, and the tests prove it does.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx
Both examples now run in a CI matrix; the runners, verdict tool, and
metric contract are diffed against the template so instantiated copies
cannot silently drift, and the verdict self-test (the known-nothing
control) runs on every push.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx
Lead with a two-minute path into a working example, show the loop as a
diagram, turn the failure-mode reasoning into a countermeasure table,
give each example a real description with its trap, walk build-your-own
step by step, and answer the questions a first-time user actually has
(cost, API keys, no-holdout domains, why verdict.py fails closed) in an
FAQ. Adds the ASCII masthead and a contributing section geared toward
community example loops.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t5gmHpHh68Jcigy5uPPEx
@mboss37
mboss37 merged commit ebeaa28 into main Jul 1, 2026
4 checks passed
@mboss37
mboss37 deleted the claude/self-improving-loops-rating-ufufj5 branch July 1, 2026 20:36
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.

2 participants