# Adding a benchmark repo A benchmark repo is a snapshot of a library's code from before a set of real, historical bug fixes, plus an answer key of those fixes. Workers search the snapshot. The scorer then checks their findings against the key automatically. A repro matches key class K when it reports the bug on the parent of one of K's fix commits and does not report it on the fix commit itself. The key must be exact. Every class you list must have a repro that fails before the maintainer's fix and passes after it, under the scorer's exact conditions. This page describes how to build a key. The process is adapted from the builder instructions the first 26 keys were made with. ## What you produce In this repository: ``` bench// manifest.json how to rebuild the snapshot, and what workers are told NOTES.md anything a later reader must know, with nothing about the bugs (optional) ``` In the private keys folder (`--keys`, `BUG_SEARCH_KEYS`, or `~/.local/share/bug-search/keys`), never in this repository: ``` // key/ANSWER-KEY.md one line per class key/CUTOFF the cutoff sha key/SKIPPED.md fixes you could not reproduce, and why (optional) key/repro/.mjs one repro per class ``` `` is the directory name. It must be equal to the manifest's `name`. ## Safety rules - Never push, never open issues, PRs or comments upstream, and never commit to the upstream repo. - Never stop processes by name (no `pkill` or `killall`). Stop only a PID you recorded. - Do not use `rm -rf` with variable paths. Use `mktemp -d` for scratch work. - Run every repro under a time limit, so that a hang ends on its own. Use `perl -e 'alarm 20; exec @ARGV' node ...` or a child-process timeout. The scorer kills a repro after 20 seconds. ## 1. Clone and choose the cutoff 1. Make a full clone (with history) of the upstream repo. 2. List the commits since the model cutoff in force (now 2026-07-01). Find the **behavioral** bug fixes. A behavioral fix changes what a caller of the public API observes: a wrong value, a wrong order, a missing or extra event or call, a throw that should not happen, a missing throw, a leak or a hang. - Ignore docs, types-only, build, CI, test-only, dependency bumps, refactors, perf changes without a behavior change, and dev tooling. - Read the diff of each candidate, not only its subject. Many real fixes have subjects like `feat:` or `chore:`, and many `fix:` commits are not behavioral. 3. Choose a cutoff commit that comes before as many behavioral fixes as possible. Usually this is the parent of the first good fix. Prefer a cutoff that leaves at least 8 fixes after it. If the repo cannot give 5 reproducible classes, stop and write `UNSUITABLE.md` with the reason and the fix list. 4. In a monorepo, you can restrict the benchmark to one or a few packages (the ones that have the fixes): name them in `area`. ### The author-date rule Use only fixes whose **author date** (`git log -1 --format=%ad `) is on or after the model cutoff in force. This is a hard rule: code from before the cutoff can be in the model's training data, and then a worker can "find" a bug from memory. The cutoff commit itself must also be dated on or after the model cutoff. The committer date is not sufficient. A rebase or a squash merge can give an old fix a new committer date. ## 2. Build the snapshot 1. Extract the cutoff without `.git`: ```sh mkdir snap && git -C repo archive | tar -x -C snap ``` 2. Install the dependencies so that all of them, including `tsx`, resolve from **one root `node_modules`**. The scorer builds every other tree (each fix commit and its parent) as a `git archive` of that commit, with a symlink `node_modules -> /node_modules`. A package that is installed only under `packages/*/node_modules` is not visible in those trees. - pnpm: `pnpm install --frozen-lockfile --config.node-linker=hoisted --ignore-scripts`. If `tsx` is missing, add it with `npm pkg set devDependencies.tsx=` and then `pnpm install --no-frozen-lockfile --config.node-linker=hoisted --ignore-scripts`. (`pnpm add -w -D tsx` gives the same lockfile, but in some environments it does not exit after it finishes.) - npm with a lockfile: `npm ci --ignore-scripts`, then `npm install -D tsx@ --ignore-scripts` if `tsx` is missing. - npm without a lockfile: add `--before=`, so that a later rebuild resolves the same versions. Use the time of your install, unless npm resolved from a metadata cache that was older; then use a time that gives the same versions, and check it with a rebuild. - Pin `tsx` to an exact version. 3. If a package imports a sibling workspace package, make sure the import resolves from source or from a build that is in the snapshot. Prefer repros that import the package source directly. 4. For DOM-dependent code, use `happy-dom` or `jsdom` only if it is in the root `node_modules`. Set it up inside the repro. 5. If the code needs generated files that are not in git (for example, z-schema's metaschema JSON), generate them in the setup. Then stage a copy under `node_modules/` (for example `node_modules/.zs-schemas/`), so the repros can copy the files into the other trees, which share only `node_modules`. Record every command you ran, in order, in the manifest's `setup`. A rebuild must be able to reproduce your snapshot from a fresh `git archive` extraction with only these commands. Do not change the snapshot by hand. ## 3. Reproduce each fix For each behavioral fix after the cutoff, write `key/repro/.mjs`. An ID is one capital letter chosen for this repo plus a number, for example `V1` or `V2`. - **Invocation:** `node [--import /node_modules/tsx/dist/esm/index.mjs] --expose-gc .mjs `. The working directory is `key/repro/`, and `` (`process.argv[2]`) is the tree under test. Import the code under test from `/...` with absolute paths (`pathToFileURL`). Never import from the key directory or from a fixed tree. - **Exit codes:** exit **1** when the bug is present (print `BUG: ...` on stdout), **0** when it is absent (print `OK: ...`), and **2** on a setup error (catch import or API errors and exit 2). The scorer reads an exit 1 with empty stdout and `Error` on stderr as a crash (2), so always print the verdict on stdout. - **Time:** the scorer kills a repro after 20 seconds. Keep each repro under 10 seconds. - **Determinism:** no wall-clock verdicts. Use fake timers or a controlled clock. Use real waits only for a microtask or a settle of 50 ms or less. - **Public API:** test through the public API, as a caller observes it. - **Classes:** merge fixes that repair the same caller-visible behavior into one class, and list all of their shas. Split one commit into several classes when it fixes distinct behaviors. - **Skips:** some fixes cannot be made to fail before and pass after. Examples are environment-only bugs, browser-only behavior that you cannot emulate, and code that was added after the cutoff (that is not a bug in the snapshot). Write each one in `key/SKIPPED.md` with the reason. ## 4. Write the key `key/ANSWER-KEY.md` has a short header, then one line per class: ``` | | obs ..., expected ...> | | family: ``` - The scorer finds the fix shas on the line by matching every 7-to-40-character hex word against the repo's history. Do not put other hex strings of 7 or more characters on the line. - `family` is your guess at the bug family: boundary, shapes, obligations, views, invalidation, crosscheck, shadow, hostile-deps, schedules, generations or other. - Append ` | weak` when the snapshot fails the repro for a different reason than the one the fix addresses, or when the repro checks configuration rather than behavior. - Append ` | contaminated ()` to a class that breaks the author-date rule, for example a class kept from an older key whose fix was authored before the model cutoff. New keys should not have contaminated classes. - Copy every `weak` and `contaminated` ID into the manifest, so that reports can show the scores with and without them. `key/CUTOFF` holds the cutoff sha. ## 5. Verify under the scorer Verification builds the trees exactly the way the scorer does. For every class: 1. Run the repro on the snapshot. It must exit 1. 2. For each fix sha on the line, build two trees, `^` and ``: a `git archive` of the commit with `node_modules` symlinked from the snapshot. The repro must exit 1 on `^` and 0 on `` for at least one of the fixes. A class that does not pass this check does not stay in the key. Fix the repro or drop the class (and record the drop in `SKIPPED.md`). The scorer-identical check matters because a repro that passes in your scratch setup can fail in the scorer's trees. Common causes: - an import that resolves only in the snapshot (for example from a package's own `node_modules`, or from a build output); - a generated file that is in the snapshot but not in the git trees; - a dependency that a later commit added, so the fix tree needs a package the snapshot does not have; - a verdict that depends on load or timing, which the 20-second limit and parallel runs expose. Then do a clean rebuild. Clone the URL into a new directory, extract the cutoff, run the manifest's `setup`, and verify again against the rebuilt snapshot. This proves that the manifest alone reproduces the benchmark. ## The manifest `manifest.json` is a JSON object with these fields: | Field | Type | Meaning | | -------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | string | The repo's benchmark name. It must be equal to the directory name. | | `url` | string | The upstream git URL to clone. | | `cutoff` | string | The full 40-character sha of the cutoff commit. | | `split` | `"train"` or `"test"` | The split. Keep the test split out of any tuning. | | `kind` | string | One or two words for the kind of library, for example `parser` or `scheduler`. | | `area` | string | The public API surface in scope, by package, module and function names. This text goes into the worker briefs, so describe the code, never the bugs. | | `hint` | string | How to run code against ``, for example the tsx loader and the entry file. This text also goes into the worker briefs. | | `tsx` | boolean | `true` if the repros and the workers run with `--import /node_modules/tsx/dist/esm/index.mjs`. | | `setup` | array of strings | The shell commands that reproduce the snapshot's dependency state. They run in order, each with `sh -c` in the root of a fresh `git archive ` extraction. Stop at the first command that fails. An empty array means that the snapshot needs nothing (and has no `node_modules`). | | `weak` | array of IDs | The classes marked `\| weak` in the key. | | `contaminated` | array of IDs | The classes marked `\| contaminated` in the key. | | `live` | object, optional | Fixes for bugs that are still present upstream (see [Live fixes](#live-fixes)): `{"base": "", "fixes": ["", ...]}`. Leave this field out when every class has an upstream fix. | Example (shortened): ```json { "name": "virtual", "url": "https://github.com/TanStack/virtual.git", "cutoff": "f592b0951d6bf7be12d37c602922eec48efc4686", "split": "train", "kind": "scroll-virtualizer", "area": "the `Virtualizer` class and helpers in `packages/virtual-core/src/index.ts` ...", "hint": " (the source is TypeScript: run scripts with `node --import /node_modules/tsx/dist/esm/index.mjs`, ...)", "tsx": true, "setup": [ "pnpm install --frozen-lockfile --config.node-linker=hoisted --ignore-scripts", "npm pkg set devDependencies.tsx=4.23.15", "pnpm install --no-frozen-lockfile --config.node-linker=hoisted --ignore-scripts" ], "weak": [], "contaminated": [] } ``` Write the setup commands so that they use no machine-specific paths and write only inside the extraction (or under `mktemp -d`). The environment that runs them supplies the registry and the package-manager caches. ## Live fixes A bug that is still present upstream has no maintainer fix commit, so the scorer cannot check a repro against it. To make such a bug a key class, write the fix yourself and let the snapshot step turn it into a commit. 1. Confirm the bug: the documented contract must promise the behavior the repro checks. Drop a behavior that is a design question. 2. Check out the base (usually the upstream HEAD) in a scratch clone. Write the smallest fix that makes the repro pass. Run the library's own tests with its own runner, under a time limit. If a fix breaks a test that asserts the current behavior, the bug is a design question: do not keep it. 3. Write each fix as a patch, `bench//live/.patch`, a `git diff` with `a/` and `b/` prefixes. The patches form a chain: the first applies on the base, and each later one applies on the result of the one before. Keep the fixes independent, so that every repro still fails on its fix's parent. 4. List them in the manifest's `live` field, in order: `"live": {"base": "", "fixes": ["N14", "N15"]}`. 5. Run `bug-search snapshot `. It fetches the base when the clone lacks it, applies the patches as commits on the local branch `live` of the full clone, and prints the sha of each one (`: live `). It does this on every run, also when the snapshot is up to date, so an existing cache gets the branch too. 6. Write a key line for each class with its live sha, as for any fix. The scorer lists the `live` branch with HEAD, and builds the trees of a live commit and its parent like any others. Every live commit has the same author, committer and date (`bug-search `, 2026-11-14T00:00:00Z) and the message `live fix `, and no user or system git configuration takes part. A sha therefore depends only on the base, the patches and their order, and it is the same on every machine. A change to any patch changes its sha and the shas of all the patches after it: run `snapshot` again and update those key lines. `verify` reports a key line whose sha the clone does not have as `no fix sha found in the key line`. ## Keys are public The answer keys in this repo are public. A model trained after a key was published can know its bugs. See [the contamination policy](./benchmark.md#contamination-policy): every new model generation needs fresh keys, built with this process from fixes authored after that model's cutoff.