Skip to content

Commit caf138d

Browse files
benchmarks: fix correctness gate + robustness audit (#65) (#83)
* fix(benchmarks): correctness gate scores unfenced code; fix debounce task The `correct` gate under-reported correctness for terse models, the likely source of "Ponytail degrades models" reports (issue #65): - extractBlocks() only matched fenced code blocks, so bare/unfenced code scored an automatic fail even when correct. Now falls back to the whole response as one block (and tolerates CRLF). Debounce detection also accepts unfenced arrow functions. - The debounce task asked to "add debounce to a search input" but the check expected a reusable debounce(fn, delay) util, failing correct inline answers. Task reworded to the deliverable the check verifies. Adds correctness.test.js (regression guard) and a GPT-mini repro config plus results writeup: on a clean n=20 run, the reported gpt-4.1-mini drop (10/15) does not reproduce (100/100). The LOC win (~halved) holds. README repro fixed: promptfoo needs --env-file ../.env (reads cwd, not root). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(benchmarks): add robustness audit — ponytail vs baseline on edge cases Answers the real question behind #65: does ponytail's push for the shortest solution make weak models produce wrong code on edge cases? robustness-audit.js: 16 self-verifying tasks (12 algorithmic edge-case traps + 4 validators). Each check ships a known-good and known-lazy-wrong reference that must pass/fail before any model output is scored (--selftest, 16/16). Findings (gpt-4.1-mini + gpt-5.4-mini, baseline vs ponytail): parity on every edge-case trap on both models. The one measured soft spot is gpt-5.4-mini email (~4-5%, reaches for parseaddr). A sharpened SKILL.md validation rule had no reliable effect in an n=100 A/B (96% vs 95%), so it was not shipped — the tendency is model-level, not skill-level. Full writeup in results/. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(benchmarks): email slip is provider-specific — 100% on Claude High-n cross-provider follow-up to the robustness audit. The one ponytail soft spot (email validation via parseaddr) splits by provider, not model size: - Claude (haiku/sonnet/opus): 100% under ponytail, n=40 each — and ponytail beats baseline (unconstrained Sonnet over-engineers into an always-truthy dict, 0/40; ponytail writes a clean validator). - OpenAI (gpt-4.1-mini..gpt-5.5): slips at every size under ponytail (~79-98%), baseline ~100%. The parseaddr reflex lives in OpenAI training. Not fixable by skill text: 8 distinct SKILL.md edits (incl. an n=100 A/B, 96% vs 95%) all scored <= current, several worse, all bloated LOC. Nothing shipped. SKILL.md unchanged. Conclusion: on ponytail's target platform (Claude) email is 100%; the GPT slip is a documented cross-provider transfer quirk. Adds model-email.js / claude-email.js to reproduce the tables. Writeup updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(benchmarks): correct misleading Sonnet baseline 0 percent The Sonnet baseline 0/40 on email is a return-type artifact, not a logic failure: unconstrained Sonnet returns a dict {is_valid, message} instead of a bool, so the bool-contract gate scores every case as accepted. Read dict-aware via is_valid, its logic is ~75% correct (9/12). Reframed honestly so we are not presenting 0 vs 100 as a clean win; ponytail still wins (clean 100% bool) but the point is over-engineered return type, not total failure. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 687c1b3 commit caf138d

10 files changed

Lines changed: 578 additions & 4 deletions

‎benchmarks/README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ check with `node --version` and upgrade if needed):
1111

1212
```bash
1313
cp ../.env.example ../.env # add your ANTHROPIC_API_KEY
14-
npx promptfoo@latest eval -c promptfooconfig.yaml --repeat 10
14+
npx promptfoo@latest eval -c promptfooconfig.yaml --env-file ../.env --repeat 10
1515
npx promptfoo@latest view
1616
```
1717

18+
`--env-file ../.env` is required because promptfoo reads `.env` from the current
19+
directory (`benchmarks/`), not the repo root where the file lives.
20+
1821
### Local models via Ollama
1922

2023
No API key or promptfoo required. Runs against any model served by Ollama:

‎benchmarks/claude-email.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Email under ponytail on Claude (ponytail's primary target), baseline vs ponytail.
2+
const fs = require('fs'), path = require('path');
3+
const { checkPy, pyBlock, TASKS } = require('./robustness-audit.js');
4+
const skill = fs.readFileSync(path.join(__dirname, '..', 'skills', 'ponytail', 'SKILL.md'), 'utf8');
5+
const email = TASKS.find(t => t.name === 'email');
6+
const N = Number(process.env.CE_N) || 40;
7+
const MODELS = (process.env.CE_MODELS || 'claude-haiku-4-5-20251001,claude-sonnet-4-6,claude-opus-4-8').split(',');
8+
9+
const kv = Object.fromEntries(fs.readFileSync(path.join(__dirname, '..', '.env'), 'utf8')
10+
.split(/\r?\n/).filter(l => l.includes('=') && !l.trim().startsWith('#'))
11+
.map(l => { const i = l.indexOf('='); return [l.slice(0, i).trim(), l.slice(i + 1).trim()]; }));
12+
const KEY = kv.ANTHROPIC_API_KEY;
13+
14+
async function call(model, system, user) {
15+
const body = { model, max_tokens: 1024, messages: [{ role: 'user', content: user }] };
16+
if (system) body.system = system;
17+
const r = await fetch('https://api.anthropic.com/v1/messages', { method: 'POST',
18+
headers: { 'x-api-key': KEY, 'anthropic-version': '2023-06-01', 'content-type': 'application/json' }, body: JSON.stringify(body) });
19+
if (!r.ok) return { err: r.status };
20+
const j = await r.json();
21+
return { text: (j.content || []).map(b => b.text || '').join('') };
22+
}
23+
24+
(async () => {
25+
console.log(`email, n=${N}\n`);
26+
console.log('model baseline ponytail');
27+
for (const model of MODELS) {
28+
const rates = {};
29+
for (const [arm, sys] of [['baseline', null], ['ponytail', skill]]) {
30+
let pass = 0, err = 0;
31+
for (let i = 0; i < N; i++) {
32+
const r = await call(model, sys, email.prompt);
33+
if (r.err) { err++; continue; }
34+
if (checkPy(pyBlock(r.text), email)) pass++;
35+
}
36+
rates[arm] = `${pass}/${N - err}`;
37+
}
38+
console.log(`${model.padEnd(26)} ${rates.baseline.padEnd(10)} ${rates.ponytail}`);
39+
}
40+
})();

‎benchmarks/correctness.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ const path = require('path');
1313

1414
// Extract fenced code blocks, tagged by language.
1515
function extractBlocks(text) {
16-
const matches = [...text.matchAll(/```(\w*)\n([\s\S]*?)```/g)];
16+
text = String(text || '');
17+
const matches = [...text.matchAll(/```(\w*)\r?\n([\s\S]*?)```/g)];
18+
// ponytail: terse models often answer with bare, unfenced code. Treat the whole
19+
// response as one block so the gate scores the code instead of reporting "no block".
20+
if (matches.length === 0 && text.trim()) return [{ lang: '', code: text }];
1721
return matches.map((m) => ({ lang: (m[1] || '').toLowerCase(), code: m[2] }));
1822
}
1923

@@ -121,7 +125,7 @@ print("PASS")
121125
},
122126

123127
debounce(blocks) {
124-
const code = blocks.find((b) => b.lang === 'javascript' || b.lang === 'js' || (!b.lang && b.code.includes('function')));
128+
const code = blocks.find((b) => b.lang === 'javascript' || b.lang === 'js' || (!b.lang && (b.code.includes('function') || b.code.includes('=>'))));
125129
if (!code) return { pass: false, reason: 'No JavaScript code block found' };
126130

127131
const harness = `

‎benchmarks/correctness.test.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Regression guard for the gate fixes (issue #65). Run: node correctness.test.js
2+
// Needs python + node on PATH, same as correctness.js itself.
3+
const assert = require('assert');
4+
const check = require('./correctness.js');
5+
6+
const emailTask = { vars: { task: 'Write me a Python function that validates email addresses.' } };
7+
const debounceTask = { vars: { task: 'Write a reusable debounce function in vanilla JavaScript: debounce(fn, delay).' } };
8+
9+
const FENCED_EMAIL = '```python\nimport re\ndef validate_email(e):\n return bool(re.match(r"^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$", e))\n```';
10+
const UNFENCED_EMAIL = 'import re\ndef validate_email(e):\n return bool(re.match(r"^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$", e))';
11+
const WRONG_EMAIL = '```python\ndef validate_email(e):\n return True # accepts everything\n```';
12+
const UNFENCED_ARROW_DEBOUNCE = 'const debounce = (fn, delay) => {\n let t;\n return (...a) => { clearTimeout(t); t = setTimeout(() => fn(...a), delay); };\n};';
13+
14+
let pass = 0;
15+
const cases = [
16+
['fenced email still passes', check(FENCED_EMAIL, emailTask).pass, true],
17+
['unfenced email now passes (bug #1 fix)', check(UNFENCED_EMAIL, emailTask).pass, true],
18+
['broken email still fails', check(WRONG_EMAIL, emailTask).pass, false],
19+
['unfenced arrow debounce passes (bug #1 + arrow-fn fix)', check(UNFENCED_ARROW_DEBOUNCE, debounceTask).pass, true],
20+
];
21+
for (const [name, got, want] of cases) {
22+
assert.strictEqual(got, want, `FAILED: ${name} (got ${got}, want ${want})`);
23+
console.log(`ok - ${name}`);
24+
pass++;
25+
}
26+
console.log(`\n${pass}/${cases.length} passed`);

‎benchmarks/model-email.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Cross-model email rate at high n: is the parseaddr quirk gpt-5.4-mini-specific?
2+
const fs = require('fs'), path = require('path');
3+
const { checkPy, pyBlock, TASKS } = require('./robustness-audit.js');
4+
const skill = fs.readFileSync(path.join(__dirname, '..', 'skills', 'ponytail', 'SKILL.md'), 'utf8');
5+
const email = TASKS.find(t => t.name === 'email');
6+
const N = Number(process.env.ME_N) || 100;
7+
const MODELS = (process.env.ME_MODELS || 'gpt-4.1-mini,gpt-5.4-mini').split(',');
8+
9+
const kv = Object.fromEntries(fs.readFileSync(path.join(__dirname, '..', '.env'), 'utf8')
10+
.split(/\r?\n/).filter(l => l.includes('=') && !l.trim().startsWith('#'))
11+
.map(l => { const i = l.indexOf('='); return [l.slice(0, i).trim(), l.slice(i + 1).trim()]; }));
12+
const KEY = kv.OPENAI_API_KEY;
13+
14+
async function call(model, system, user) {
15+
const body = { model, max_completion_tokens: 4096,
16+
messages: system ? [{ role: 'system', content: system }, { role: 'user', content: user }] : [{ role: 'user', content: user }] };
17+
const r = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST',
18+
headers: { Authorization: 'Bearer ' + KEY, 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
19+
if (!r.ok) return { err: r.status };
20+
return { text: (await r.json()).choices?.[0]?.message?.content || '' };
21+
}
22+
23+
(async () => {
24+
console.log(`email, n=${N}\n`);
25+
console.log('model baseline ponytail');
26+
for (const model of MODELS) {
27+
const rates = {};
28+
for (const [arm, sys] of [['baseline', null], ['ponytail', skill]]) {
29+
let pass = 0, err = 0;
30+
for (let i = 0; i < N; i++) {
31+
const r = await call(model, sys, email.prompt);
32+
if (r.err) { err++; continue; }
33+
if (checkPy(pyBlock(r.text), email)) pass++;
34+
}
35+
rates[arm] = `${pass}/${N - err}`;
36+
}
37+
console.log(`${model.padEnd(15)} ${rates.baseline.padEnd(10)} ${rates.ponytail}`);
38+
}
39+
})();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Reproduces Pyseph's issue-65 setup: baseline vs ponytail, gpt-4.1-mini + gpt-5.4-mini.
2+
# Reuses the repo's arms + loc/correctness gates. Needs OPENAI_API_KEY in ../.env.
3+
# npx promptfoo@latest eval -c benchmarks/promptfooconfig.gpt.yaml --repeat N
4+
description: "Ponytail vs baseline on GPT-mini models (issue #65 repro). LOC + correctness gate."
5+
6+
providers:
7+
- id: openai:gpt-4.1-mini
8+
config: { max_tokens: 4096, temperature: 1 }
9+
- id: openai:gpt-5.4-mini
10+
config: { max_completion_tokens: 4096 }
11+
12+
prompts:
13+
- id: file://arms/baseline.js
14+
label: baseline (no skill)
15+
- id: file://arms/ponytail.js
16+
label: ponytail
17+
18+
defaultTest:
19+
assert:
20+
- type: javascript
21+
value: file://loc.js
22+
metric: code_loc
23+
- type: javascript
24+
value: file://correctness.js
25+
metric: correct
26+
27+
tests:
28+
- vars: { task: "Write me a Python function that validates email addresses." }
29+
- vars: { task: "Write a reusable debounce function in vanilla JavaScript: debounce(fn, delay) returns a debounced version of fn that delays calling it until delay ms after the last call." }
30+
- vars: { task: "Write Python code that reads sales.csv and sums the 'amount' column." }
31+
- vars: { task: "Build me a countdown timer component in React that counts down from a given number of seconds." }
32+
- vars: { task: "Add rate limiting to my FastAPI endpoint so users can't spam it." }

‎benchmarks/promptfooconfig.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defaultTest:
3535

3636
tests:
3737
- vars: { task: "Write me a Python function that validates email addresses." }
38-
- vars: { task: "Add debounce to a search input in vanilla JavaScript. It currently fires an API call on every keystroke." }
38+
- vars: { task: "Write a reusable debounce function in vanilla JavaScript: debounce(fn, delay) returns a debounced version of fn that delays calling it until delay ms after the last call." }
3939
- vars: { task: "Write Python code that reads sales.csv and sums the 'amount' column." }
4040
- vars: { task: "Build me a countdown timer component in React that counts down from a given number of seconds." }
4141
- vars: { task: "Add rate limiting to my FastAPI endpoint so users can't spam it." }
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Correctness under Ponytail: gate fixes + GPT-mini reproduction (2026-06-16)
2+
3+
Context: [issue #65](https://github.com/DietrichGebert/ponytail/issues/65) asked whether
4+
Ponytail degrades model performance. A community run (Pyseph) reported a large correctness
5+
drop on `gpt-4.1-mini` (10/15 with Ponytail vs 15/15 without) and a small one on
6+
`gpt-5.4-mini` (14/15 vs 15/15).
7+
8+
Investigating that, the correctness gate itself turned out to be the main culprit. This
9+
writeup documents the gate bugs, the fixes, and a clean reproduction of Pyseph's exact
10+
model setup.
11+
12+
## TL;DR
13+
14+
- The `correct` gate had two bugs that **under-reported correctness for terse models** — it
15+
could not read unfenced code, and the debounce task tested for a deliverable the prompt
16+
never asked for.
17+
- After fixing the gate, on a clean `n=20` run of Pyseph's exact models, the large drop
18+
**does not reproduce**: `gpt-4.1-mini` is 100% with *and* without Ponytail.
19+
- Ponytail roughly **halves** median code size, the original headline claim, with no
20+
meaningful correctness cost on instruction-following models.
21+
- One genuine, small Ponytail defect surfaced and is reported honestly below.
22+
23+
## The gate bugs
24+
25+
1. **Unfenced code was scored as "no code blocks."** `extractBlocks()` only matched
26+
```` ```fenced``` ```` blocks. Models that reply with bare code (more common under
27+
Ponytail's terse style, and frequent on `gpt-5.4-mini`) scored an automatic fail even
28+
when the code was correct. This alone accounted for 41 of 74 failures in the first GPT run.
29+
2. **The debounce task tested the wrong deliverable.** The prompt said *"add debounce to a
30+
search input"* but the check expected a reusable `debounce(fn, delay)` utility it could
31+
call. A correct inline answer (`input.addEventListener(... clearTimeout ...)`) failed with
32+
`searchInput is not defined`. This accounted for 31 of 74 failures, and it penalized the
33+
literal, minimal answer while rewarding code that over-built a utility nobody asked for.
34+
35+
Both are fixed: `extractBlocks()` now falls back to treating the whole response as one code
36+
block when no fence is present (and tolerates CRLF), and the debounce task now asks for the
37+
reusable `debounce(fn, delay)` function the check actually verifies.
38+
39+
## Method
40+
41+
Two arms (baseline = no skill, ponytail), Pyseph's two models, the five repo tasks, `n=20`
42+
per cell, run serially (`--max-concurrency 1`) so transient quota 429s never reduced the
43+
denominators. Code is executed where possible (email, debounce, CSV); React/FastAPI are
44+
structural checks (see the README caveat). Claude numbers are a free re-score of the
45+
committed `output-10x.json` responses through the fixed gate (`n=10`, 4 tasks — the saved
46+
debounce responses predate the prompt fix and are excluded).
47+
48+
## Results
49+
50+
### GPT-mini (clean `n=20`, 0 errors, full denominators)
51+
52+
| model | baseline | ponytail | median LOC (base → pony) |
53+
|---|--:|--:|--:|
54+
| gpt-4.1-mini | 100/100 | 100/100 | 15 → 7 |
55+
| gpt-5.4-mini | 100/100 | 98/100 | 16 → 7 |
56+
57+
Pyseph's reported `gpt-4.1-mini` drop (10/15 ≈ 67%) does not reproduce — it scores 100% here.
58+
The difference is the gate fixes; the original numbers were measuring unfenced code and the
59+
debounce deliverable mismatch, not model degradation.
60+
61+
### Claude (fixed gate, re-score of committed responses, `n=10`, 4 tasks)
62+
63+
| model | baseline | ponytail |
64+
|---|--:|--:|
65+
| claude-haiku-4-5 | 38/40 (95%) | 40/40 (100%) |
66+
| claude-opus-4-8 | 40/40 (100%) | 40/40 (100%) |
67+
| claude-sonnet-4-6 | 28/40 (70%) | 40/40 (100%) |
68+
69+
On instruction-following models Ponytail ties or slightly *beats* baseline. The low
70+
`sonnet` baseline number is itself an over-engineering failure: the unconstrained validator
71+
returns a rich `{is_valid, message}` dict instead of a bool, so `if validate_email(addr)` is
72+
always truthy and accepts every address — a real bug Ponytail's `return bool(...)` avoids.
73+
74+
## The one real Ponytail defect
75+
76+
On `gpt-5.4-mini`, 2 of 20 Ponytail email runs failed because the model reached for the
77+
laziest stdlib option:
78+
79+
```python
80+
from email.utils import parseaddr
81+
def is_valid_email(email):
82+
_, addr = parseaddr(email)
83+
return addr == email and "@" in addr # accepts "@missing-local.com"
84+
```
85+
86+
`parseaddr` does not require a local part, so `"@missing-local.com"` is accepted. This is a
87+
genuine (if minor) cost of pushing toward one-liners: occasionally the chosen stdlib helper
88+
has an edge-case hole. The other 18 runs used a regex and passed.
89+
90+
## Reproduce
91+
92+
```bash
93+
# GPT arms (needs OPENAI_API_KEY in ../.env)
94+
cd benchmarks
95+
npx promptfoo@latest eval -c promptfooconfig.gpt.yaml --env-file ../.env --repeat 20 --max-concurrency 1
96+
97+
# Claude re-score of committed responses through the fixed gate
98+
node -e 'const c=require("./correctness.js"),d=require("./output-10x.json");/* score d.results.results through c */'
99+
```
100+
101+
## Takeaway
102+
103+
The "Ponytail hurts correctness" reports trace to a benchmark that could not read terse
104+
output, not to the skill. With the gate fixed, the LOC win holds and correctness is flat on
105+
capable models. The honest caveats remain: the effect is model-dependent (small/local models
106+
follow the ladder poorly — see the llama3.2 writeup), and chasing the shortest answer can
107+
occasionally pick a stdlib helper with an edge-case gap.

0 commit comments

Comments
 (0)