Measure: eval golden, retrieval, replay
This page documents the safran eval commands: every flag, real output, the --json shape, exit codes and the mistakes people make. safran eval golden turns your merged pull requests into questions with known answers, safran eval retrieval measures code search against them, and safran eval replay runs agent commands on finished tickets and scores the files they touch. The commands are thin shells over @safran/eval; the evaluation guide explains how to read the numbers.
From nothing to a number
The golden set is built from the local link store and measured against the local code index, so both must exist first (see CLI: maintain):
safran sync # clone or fetch the repos and index them
safran links refresh # pull merged pull requests into the link store
safran eval golden # question → files, written to <data dir>/eval/golden.json
safran eval retrieval # run every question through code searchThe examples on this page were run on a small acme profile: one repo (payments-api) with three merged pull requests, two of them linked to the tickets PAY-1423 and PAY-1500, and a test embedder (fake:hash-256) in place of a real model. The numbers show the format; they say nothing about retrieval quality. The profile is named with --profile safran.yaml, which is why the hints Safran prints carry the same flag. Global options (--profile, --data-dir, --json, …) are described in the CLI overview.
safran eval golden
safran eval golden [options]Builds a golden set: one item per (ticket, repo), where the question is the ticket title and the answer is the files the ticket's pull requests changed.
What it touches. It reads the local link store and the local working trees (an answer file that no longer exists is dropped). It calls the code hosts to list repositories and the tracker once per distinct ticket, to read its title. It writes one JSON file and creates its directory. It does not fetch pull requests: that is safran links refresh.
| Flag | Value | Default | Meaning |
|---|---|---|---|
--out | file | <data dir>/eval/golden.json | Where to write the golden set. A relative path is resolved against the directory you are in. |
--since | date | none | Only pull requests merged on or after this date (2026-01-31 or a full ISO timestamp). |
--until | date | none | Only pull requests merged before this date. With --since this is the time split: tune on one period, report on another. |
--include-unlinked | – | off | Also use pull requests without a ticket; the question is then the cleaned pull request title. |
The filters and their thresholds (at most 20 answer files, at least 2 words in the title, at most 3 tickets per pull request, source files only) are the defaults of buildGoldenSet; to change them, call it from the SDK.
$ safran eval golden --profile safran.yaml
pull requests 3
items kept 2
dropped no ticket 1
ticket titles 2 read
languages tr 2
✔ Wrote 2 items to data/eval/golden.json
→ Measure with `safran eval retrieval --profile safran.yaml`.The dropped line lists only the reasons that occurred: no ticket, too many tickets, plumbing title (merges, reverts, branch syncs), noise query, title too short, no answer file left, too many files, duplicate. Here the third pull request ("bump dependencies") has no ticket. With --include-unlinked it becomes a candidate and is dropped for another reason: the only file it changed is package.json, which is configuration, not code.
$ safran eval golden --profile safran.yaml --since 2026-11-01 --include-unlinked --out eval/november.json
pull requests 3
items kept 2
dropped no answer file left 1
ticket titles 2 read
languages tr 2
✔ Wrote 2 items to eval/november.json
→ Measure with `safran eval retrieval --profile safran.yaml`.When a ticket cannot be read, the cleaned pull request title is used instead and the ticket titles line says how many (… unreadable (PR title used)). An empty set is still written, with a warning and the reason:
$ safran eval golden --profile safran.yaml --since 2026-01-01 --until 2026-11-01 --out eval/held-out.json
pull requests 0
items kept 0
dropped none
ticket titles 0 read
languages –
! The golden set is empty: nothing to measure with.
→ The link store has no pull requests in this window. Run `safran links refresh --profile safran.yaml` first.
✔ Wrote 0 items to eval/held-out.jsonJSON output
--json prints the file path, the item count and every counter of the build. Keys are snake_case, except the language tags under languages, which are data.
$ safran eval golden --profile safran.yaml --json
{
"golden_file": "/work/acme/data/eval/golden.json",
"items": 2,
"built_at": "2026-11-23T11:40:20.537Z",
"window": {},
"stats": {
"prs": 3,
"unlinked": 1,
"multi_ticket": 0,
"noise": 0,
"candidates": 2,
"noise_query": 0,
"short_title": 0,
"no_files": 0,
"too_wide": 0,
"dedup": 0,
"kept": 2,
"tickets": {
"requested": 2,
"read": 2,
"unreadable": 0
},
"query_source": {
"ticket_title": 2,
"pr_title": 0
},
"files": {
"kept": 3,
"existence_unchecked": 0,
"non_code": 0,
"lockfile": 0,
"generated": 0,
"vendored": 0,
"asset": 0,
"invalid": 0,
"missing": 0
},
"languages": {
"tr": 2
},
"truncated": false
}
}The golden-set file itself is the GoldenSet object of the SDK, written as it is (camelCase keys). One item of the file above:
{
"id": "payments-api#PAY-1423",
"repo": "payments-api",
"host": "azure",
"groups": [
"backend"
],
"ticketKeys": [
"PAY-1423"
],
"query": "Kısmi iade işlemi İstanbul şubesinde başarısız oluyor",
"querySource": "ticket_title",
"language": "tr",
"files": [
"src/refund/policy.ts",
"src/refund/service.ts"
],
"prs": [
{
"id": "101",
"title": "PAY-1423 fix partial refund rounding",
"mergedAt": "2026-11-03T11:26:05.389Z",
"mergeCommit": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
],
"mergedAt": "2026-11-03T11:26:05.389Z"
}Exit codes and mistakes
| Exit | When |
|---|---|
| 0 | The file was written, even when the set is empty. |
| 1 | The profile could not be opened, or the build failed. |
| 2 | Usage: an unknown flag, or --since / --until is not a date (✘ --since is not a date: "yesterday"). |
| 130 | Interrupted with Ctrl-C. |
- An empty set.
pull requests 0means the link store has nothing in the window: runsafran links refresh. Pull requests present but all dropped means the filters removed them; thedroppedline says which. - Building once and measuring forever. The set is a snapshot. Rebuild it after a
safran links refreshthat brought new history, and keep the file next to the numbers it produced. - Tuning and reporting on the same period. Use
--untilfor the set you tune on and--sincewith the same date for the one you report.
safran eval retrieval
safran eval retrieval [options]Runs every question of the golden set through code search and reports where the answer files land: hit@1/5/10, recall@k, MRR, nDCG@10 and latency, overall and per repo group and query language, each with its sample size. Run it before and after any change to retrieval (the glossary, the embedder, search settings).
What it touches. It reads the golden-set file and searches the local code index; a search embeds the query, so the embedder must be reachable. It contacts no tracker and no code host. It always writes the full result as a JSON file (by default under <data dir>/eval/, where the dashboard finds it), and an HTML report when you ask for one with --report.
| Flag | Value | Default | Meaning |
|---|---|---|---|
--golden | file | <data dir>/eval/golden.json | The golden set to measure against. |
--config | name=mode[,noglossary] | one configuration named default with Safran's defaults | A search configuration to measure. Repeat the flag to compare several. |
--k | n | 10 | Cut-off for recall@k and MRR. A whole number of at least 1. |
--report | file.html | none | Also write a self-contained HTML report (no script, no external request). |
--out | file.json | <data dir>/eval/retrieval-<time>.json | Where to write the full result, with one row per query, as JSON. The default name carries the time the run finished. |
A --config value is name=mode, optionally followed by comma-separated options. mode is one of auto, hybrid, dense, lexical. The options are noglossary (search with the query as written, no glossary expansion) and repo (search only the item's own repo, as an agent that already knows the repo would). The help text mentions only noglossary; repo is accepted by the parser as well. Names must be unique.
$ safran eval retrieval --profile safran.yaml
2 items from data/eval/golden.json · index fake:hash-256, 4 chunks · 6 ms
Retrieval evaluation: 2 golden items, 1 configuration, k = 10
config slice n err hit@1 hit@5 hit@10 recall@10 MRR nDCG@10 p50 ms p95 ms
------- -------------- - --- ----- ----- ------ --------- ----- ------- ------ ------
default overall 2 0 0.500 1.000 1.000 1.000 0.750 0.847 0.2 0.3
default group: backend 2 0 0.500 1.000 1.000 1.000 0.750 0.847 0.2 0.3
n = queries scored; err = failed searches, excluded from the means.
✔ Result: data/eval/retrieval-20261123114020.jsonn is the number of queries behind every number in its row. err counts searches that failed (an unreachable embedder, for example): they are left out of the means and are never counted as misses.
With two or more configurations the summary compares the first with each of the others, using a paired bootstrap on per-query reciprocal rank. A difference is claimed only when its 95 % interval excludes zero, and never with fewer than 10 paired queries:
$ safran eval retrieval --profile safran.yaml --config hybrid=hybrid --config lexical=lexical --config plain=hybrid,noglossary --k 5 --report eval/retrieval.html --out eval/retrieval.json
2 items from data/eval/golden.json · index fake:hash-256, 4 chunks · 10 ms
Retrieval evaluation: 2 golden items, 3 configurations, k = 5
config slice n err hit@1 hit@5 hit@10 recall@5 MRR nDCG@10 p50 ms p95 ms
------- -------------- - --- ----- ----- ------ -------- ----- ------- ------ ------
hybrid overall 2 0 0.500 1.000 1.000 1.000 0.750 0.847 0.2 0.2
hybrid group: backend 2 0 0.500 1.000 1.000 1.000 0.750 0.847 0.2 0.2
lexical overall 2 0 1.000 1.000 1.000 1.000 1.000 1.000 0.1 0.1
lexical group: backend 2 0 1.000 1.000 1.000 1.000 1.000 1.000 0.1 0.1
plain overall 2 0 0.500 1.000 1.000 1.000 0.750 0.847 0.1 0.1
plain group: backend 2 0 0.500 1.000 1.000 1.000 0.750 0.847 0.1 0.1
Too few paired queries to compare "hybrid" and "lexical" (n = 2, at least 10 needed). No difference is claimed.
Too few paired queries to compare "hybrid" and "plain" (n = 2, at least 10 needed). No difference is claimed.
n = queries scored; err = failed searches, excluded from the means.
✔ Report: eval/retrieval.html
✔ Result: eval/retrieval.jsonThe result file (the ✔ Result: line; --out chooses its path) is the RetrievalReport object of the SDK as it is (camelCase keys), including one row per query with the paths that were returned, so misses can be inspected without re-running.
JSON output
--json prints the summary per configuration: the effective configuration, the number of skipped items, the overall metrics and every slice. It does not include the per-query rows; those are in the result file named by result_file. A metric is null when its n is 0.
$ safran eval retrieval --profile safran.yaml --json
{
"golden_file": "/work/acme/data/eval/golden.json",
"golden": {
"built_at": "2026-11-23T11:40:20.537Z",
"items": 2,
"window": {}
},
"k": 10,
"duration_ms": 6,
"index": {
"embedder": "fake:hash-256",
"chunks": 4,
"repos": 1
},
"configs": [
{
"config": {
"name": "default",
"limit": 10
},
"skipped": 0,
"overall": {
"n": 2,
"errors": 0,
"hit_at1": 0.5,
"hit_at5": 1,
"hit_at10": 1,
"recall_at_k": 1,
"mrr": 0.75,
"ndcg_at10": 0.8467132018086354,
"latency": {
"n": 2,
"mean_ms": 0.24047900000000055,
"p50_ms": 0.24047900000000055,
"p95_ms": 0.25658540000000085
}
},
"slices": [
{
"kind": "group",
"name": "backend",
"metrics": {
"n": 2,
"errors": 0,
"hit_at1": 0.5,
"hit_at5": 1,
"hit_at10": 1,
"recall_at_k": 1,
"mrr": 0.75,
"ndcg_at10": 0.8467132018086354,
"latency": {
"n": 2,
"mean_ms": 0.24047900000000055,
"p50_ms": 0.24047900000000055,
"p95_ms": 0.25658540000000085
}
}
}
]
}
],
"report_file": null,
"result_file": "/work/acme/data/eval/retrieval-20261123114020.json"
}The output above is shortened in one place: slices also begins with a slice of kind overall that repeats the overall object; it was removed here. report_file is null unless --report was given.
Exit codes and mistakes
| Exit | When |
|---|---|
| 0 | The run finished and at least one query was scored (or none failed). |
| 1 | No golden set at the path, the golden set has no items, the profile could not be opened, or searches failed and no configuration scored a single query. |
| 2 | Usage: a malformed --config, an unknown mode, a name used twice, --k below 1. |
| 130 | Interrupted with Ctrl-C. |
$ safran eval retrieval --profile safran.yaml --golden nope.json
✘ No golden set at /work/acme/nope.json
→ Build one with `safran eval golden --profile safran.yaml`, or point at a file with --golden.
$ safran eval retrieval --profile safran.yaml --config fast=bm25
✘ --config fast: unknown mode "bm25"
→ Modes: auto, hybrid, dense, lexical.- Reading a delta as a result. The table shows means; only the comparison sentence below it says whether a difference is real. "No significant difference" and "Too few paired queries" are results.
- A large
errcolumn. The embedder was not reachable for those queries. Fix that first (safran doctor, see CLI: set up); the remaining numbers rest on fewer queries than you think. - Comparing runs on different golden sets. The header line names the file and its item count; compare only runs over the same file.
- Measuring a stale index. Search runs on what
safran synclast indexed. Sync first if the code moved.
safran eval replay
safran eval replay --arms <file.json> [options]Replays finished tickets. For each task it checks the repo out at the commit before the real change, runs every arm (a command of yours, typically an agent with and without Safran) in that checkout with the ticket as the task, and compares the files the arm touched with the files the real change touched. The real diff is reported next to the arms as the oracle.
What it touches. It reads the golden set and the tracker (ticket title and description for the prompt). In each source clone it may run a depth-limited git fetch of the one commit it needs, and it adds and removes a temporary git worktree; the arms work in a temporary directory, which is removed afterwards. It always writes the full result to <data dir>/eval/replay-<time>.json (there is no flag for that path, and the file is not named in the output); the HTML report and the log directory are written only when asked.
| Flag | Value | Default | Meaning |
|---|---|---|---|
--arms | file.json | required | The commands to compare. |
--golden | file | <data dir>/eval/golden.json | The golden set the tasks come from. |
--max-tasks | n | all tasks | Stop after this many tasks. |
--runs | n | runs of the arms file, else 1 | Repeats per task and arm. Agents are not deterministic; one run is an anecdote. |
--report | file.html | none | Also write a self-contained HTML report. |
--log-dir | dir | discarded | Keep each run's stdout and stderr here. |
Only golden items backed by exactly one pull request with a recorded merge commit can be replayed; the others are counted and left out.
The arms file
A JSON array of arms, or an object with the arms and a few run settings:
{
"arms": [
{
"name": "bare",
"command": ["acme-agent", "--prompt-file", "{prompt_file}"],
"timeout_ms": 1200000
},
{
"name": "with-safran",
"command": ["acme-agent", "--prompt-file", "{prompt_file}", "--mcp-config", "/work/acme/safran.mcp.json"],
"env": { "ACME_AGENT_RESULT": "{result_file}" },
"timeout_ms": 1200000
}
],
"runs": 3,
"test_command": { "payments-api": ["bun", "test"] },
"max_wall_ms": 14400000,
"max_cost_usd": 40
}acme-agent is a placeholder for the agent command line you use; Safran knows nothing about the agent behind an arm.
| Key | Required | Meaning |
|---|---|---|
arms[].name | yes | Unique name shown in every table. oracle is reserved for the real diff. |
arms[].command | yes | A list of strings: argv, run without a shell, with the checkout as its working directory. |
arms[].env | no | Extra environment variables, name to string. Values take placeholders too. |
arms[].timeout_ms | no | Timeout of one run in milliseconds. Default: 30 minutes. |
runs | no | Repeats per task and arm. --runs overrides it. |
test_command | no | Repo name to a test command (list of strings), run in the checkout after the arm and on the real change. Exit 0 = pass. |
max_wall_ms | no | Stop starting new runs after this much wall time. |
max_cost_usd | no | Stop once the cost the arms reported reaches this. An arm that reports no cost is never stopped by it. |
Placeholders, replaced in command and in env values (anything else in braces is left alone):
| Placeholder | Value |
|---|---|
{workdir} | The checkout the arm works in. |
{prompt} | The prompt text: repository, ticket key, title and description. |
{prompt_file} | A file holding the same prompt. |
{result_file} | A path where the arm may write { "cost_usd": 0.42, "tokens": 51000 }. Cost is read from there and never estimated. |
{ticket_key} | The ticket key, or empty. |
{task_id} | The task id, for example payments-api#PAY-1423. |
{repo} | The repo name. |
{title} | The ticket title. |
{arm} | The arm name. |
{run} | The repeat number, starting at 1. |
Keep everything except Safran identical between the arms (model, prompt, permissions, timeout), or the comparison measures those differences.
Output
No agent was run to write this page. To show the shape of the output, the command below was run with an arms file whose single arm is the no-op command true ([{ "name": "noop", "command": ["true"], "timeout_ms": 5000 }]), on the example profile, whose repo is a plain directory with no git history. The task therefore cannot be prepared, which is reported and kept out of every average:
$ safran eval replay --profile safran.yaml --arms arms.json --max-tasks 1
Ticket replay: 0 of 2 tasks ran, 1 arm, 1 run per task and arm, 29 ms
arm tasks scored/runs precision recall F1 right files no change tests cost median time
------------------ ----- ------------- --------- ------ ---- ----------- --------- ------- ------- -----------
noop 0 0/0 n/a n/a n/a 0/0 0/0 not run unknown n/a
real diff (oracle) 0 by definition 1.00 1.00 1.00 0/0 0/0 not run n/a n/a
Stopped early because the maxTasks budget was reached: 0 of 1 planned runs executed, 1 task not run.
1 task could not be prepared (commit missing or checkout failed) and is in no average.
tasks = tasks with a scored run (the n of precision, recall and F1); right files = runs with recall of at least 50%, out of scored runs; cost is what the arm reported, never estimated.In a real run each arm row carries its precision, recall and F1 over the files touched, how many runs found the right files, how many changed nothing, the test results, and the cost the arm reported. With two arms the summary adds a comparison sentence from a paired bootstrap on per-task F1; with fewer than 10 tasks it says so on stderr and claims no difference.
JSON output
--json prints one summary per arm, the oracle, and the budget. The same run:
$ safran eval replay --profile safran.yaml --arms arms.json --max-tasks 1 --json
{
"golden_file": "/work/acme/data/eval/golden.json",
"excluded": 0,
"duration_ms": 28,
"runs_per_task": 1,
"summary": [
{
"arm": "noop",
"tasks": 0,
"runs": 0,
"scored_runs": 0,
"statuses": {
"ok": 0,
"nonzero_exit": 0,
"timeout": 0,
"spawn_error": 0,
"aborted": 0,
"scoring_failed": 0
},
"precision": null,
"recall": null,
"f1": null,
"f1_run_sd": null,
"f1_run_sd_tasks": 0,
"f1_min": null,
"f1_max": null,
"found_right_files": {
"count": 0,
"of": 0
},
"changed_nothing": {
"count": 0,
"of": 0
},
"oversized_diffs": 0,
"tests": {
"passed": 0,
"of": 0
},
"cost": {
"reported_runs": 0,
"total_usd": null,
"median_usd": null,
"total_tokens": null
},
"wall": {
"n": 0,
"median_ms": null,
"mean_ms": null
},
"containment_flags": 0
}
],
"oracle": {
"tasks": 0,
"precision": 1,
"recall": 1,
"f1": 1,
"by_construction": true,
"tests": {
"passed": 0,
"of": 0
}
},
"budget": {
"max_tasks": 1,
"stopped_by": "maxTasks",
"runs_planned": 1,
"runs_executed": 0,
"tasks_not_run": 1,
"tasks_skipped": 1,
"reported_cost_usd": 0
},
"aborted": false,
"cleanup_errors": [],
"report_file": null
}The JSON does not include the per-task results; the result file under <data dir>/eval/ and the HTML report (--report) do.
Exit codes and mistakes
| Exit | When |
|---|---|
| 0 | The run finished, including when a budget stopped it early or tasks were skipped. |
| 1 | No arms file or an invalid one, no golden set, or no item of the golden set can be replayed. |
| 2 | Usage: --arms is missing, or --max-tasks / --runs is not a whole number of at least 1. |
| 130 | Interrupted with Ctrl-C. The summary of what finished is still printed, because those runs cost money. |
- Starting with the whole golden set. Every task runs every arm
runstimes. Start with--max-tasks 3and read one run's logs (--log-dir) before starting a batch. - Writing
commandas one string. It is argv, run without a shell:["acme-agent", "-p", "{prompt}"], not"acme-agent -p {prompt}". Pipes and redirections need a wrapper script. - Expecting a cost. Cost is "unknown" unless the arm writes
{result_file}. Wrap the agent in a small script that writes it from the agent's usage output. - Tasks skipped as "commit missing". The clone does not have the commit before the change and it could not be fetched (a token that expired, a rebased history). Nothing is substituted; the task is counted and left out.
- Reading F1 as correctness. It is file overlap with one accepted solution. A different correct solution scores low, the right files with wrong code score high. A
test_commandis the stronger judge where it exists. - A killed process. If the replay is killed outright, a worktree may stay registered in a source clone;
git worktree prunein that clone removes it.