# @tanstack/bug-search (private) A benchmark for oracles: which of a library's known bugs does an `@tanstack/oracles` oracle catch? Each bench repo is a library at a cutoff commit, with a private answer key of bugs that were fixed after the cutoff. This package is not published. The answer keys are not in this repository. ## Commands Run from this directory with `node src/bin.ts ` (Node 22.18 or later runs the TypeScript directly), or `pnpm bug-search `. | Command | What it does | | ------------------------------------ | --------------------------------------------------------------------------------------------- | | `snapshot NAME... [--force]` | Clones the manifest URL, archives the cutoff into `snap/`, runs the setup commands, seals it. | | `verify NAME...` | Checks a key: each repro exits 1 on the snapshot and on `^`, and 0 on ``. | | `prefix NAME --oracle DIR [options]` | Which of NAME's known bugs the oracle files under DIR catch (below). | | `help`, `-h`, `--help` | The usage. | Every command takes `--bench DIR` (the manifests; default `bench/`), `--cache DIR` and `--keys DIR`. Each command accepts only its own options; any other option, a missing argument or a bad value names the problem and exits 1 before anything runs. An unknown command, or none, exits 2. `snapshot` prints `: created`, or `: up-to-date` when the snapshot already matches its manifest. A snapshot made from another url, cutoff or setup, or one whose setup never finished, is refused until `--force` rebuilds it. `verify` prints one line per bug, `OK` or `FAIL` with the reason, and exits 1 when any bug fails. With several repos, each repo's lines start with `# `. `prefix` options: | Option | Meaning | | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `--oracle DIR` | The oracle files: every `*.oracle.property.test.{ts,js,mjs,…}` under DIR, outside `node_modules`. | | `--seed N` | The exploration's campaign seed, any safe integer (1). | | `--judge claude\|cache-only\|none` | Who confirms a flip (claude: a low-cost, fast model, `--model haiku`; Haiku, Luna or similar). `cache-only` answers only from earlier verdicts; `none` counts every stable flip. | | `--placebo` | Also apply the rules to each (fix^^, fix^) pair, a pair without the fix. | | `--quiet` | Counts and bug ids only, no key text; refused for a repo outside `train`, before anything runs. | | `--timeout-s S` | Seconds one oracle test may run (60). | Environment: `BUG_SEARCH_CACHE` and `BUG_SEARCH_KEYS` (used when the flag is not given), `BUG_SEARCH_REPRO_PROCS` (a cap on repro processes; no cap when unset) and `AR_JUDGE_PARALLEL` (judge batches at once, 6). ## Repos The repos come from `bench//manifest.json`. Any field not listed here is an error. | Field | Meaning | | ---------------------- | ------------------------------------------------------------------------------------------------------ | | `name` | The directory name. | | `url` | The git URL that `snapshot` clones. | | `cutoff` | The full sha of the snapshot. | | `split` | `train` or `test`. | | `kind`, `area`, `hint` | What the library is, what to search, how to load it. | | `tsx` | Run repros with the snapshot's tsx loader. | | `setup` | Shell commands run inside `snap/` after the archive. | | `weak`, `contaminated` | Optional: bug ids to report apart. | | `treeSetup` | Optional: shell commands run in each fix-commit tree's own folder (`$SNAP` and `$TREE` set). | | `live` | Optional: fixes for bugs still present upstream (`{"base", "fixes"}`; see docs/adding-a-benchmark.md). | | `setupTimeoutSec` | Optional: seconds one `setup` or `treeSetup` command may run (900). | `treeSetup` is for files the repo ignores in git but its code needs, which a `git archive` tree lacks. z-schema's generated metaschemas are one: without `mkdir -p src/schemas && cp -n "$SNAP"/node_modules/.zs-schemas/*.json src/schemas/` repros crash on the fix trees. ## Answer keys A repo's key is `//key/ANSWER-KEY.md`, with its repros at `//key/repro/.mjs`. `` is `--keys`, else `BUG_SEARCH_KEYS`, else `~/.local/share/bug-search/keys`. A bug line starts with its id (a capital letter and digits) and a bar: `B1 | behavior | example | | date`. Its fixes are the 7-to-40 character hex words after the first bar that start a commit of the clone: HEAD's history and the live branch, and, when a key line names none of them, origin's branches after one `git fetch origin` (no fetch otherwise). A line may end with `| weak` or `| contaminated`, bare or with a reason in parentheses. An indented or bulleted line that looks like a bug line is reported, not read. A repeated id is an error. A bug is unusable, and is listed apart and left out of the total, when no fix sha names a commit of the clone, or when its only fix is a root commit. ## Runtime state Everything the runner writes goes under the cache: `--cache`, else `BUG_SEARCH_CACHE`, else `$XDG_CACHE_HOME/bug-search`, else `~/.cache/bug-search`. ``` /repos//full full clone (history for fix commits and HEAD) /repos//snap the cutoff, with setup run, sealed /repos//snap.done.json written only after setup succeeds: the setup inputs and the sealed digest /trees/-/ link to the tree's folder .b-- beside it: git archive of a commit, node_modules from the snapshot (the hash covers the snapshot's path, its seal and treeSetup) /prefix//runs/.json one oracle run's record /prefix/judge// the judge's request files and verdicts /prefix/scratch/ each batch's scratch folders, removed when it ends /tmp/repro/ each repro's TMPDIR ``` ### Sealed snapshots and trees A snapshot is sealed when its setup finishes. The seal (`src/seal.ts`) hashes every file and symlink under `snap/` except `node_modules` directories, records each file's sha256 in `snap.done.json`, and then removes the write bits (execute bits stay). `verify` and `prefix` recompute the digest first; on a mismatch they stop and name the changed, added and removed files. A tree is built only from a finished snapshot. It is a `git archive` of the commit with the snapshot's `node_modules` folders linked in (the root one, and one in any folder the tree has, such as `packages/a/node_modules`), read-only once built. A link of the snapshot's `node_modules` into its own source, such as a workspace package (`node_modules/a -> ../packages/a`), points at the same path in the tree, so code that imports `a` by name runs the tree's `packages/a`. A tree is built in a folder of its own, where its `treeSetup` runs with `$TREE` naming it, and published by a link at ``. ## prefix For each usable bug, `prefix` explores the commit before each of its fixes (fix^) with the oracle files: one campaign at `--seed`, with each oracle's run budget multiplied by 50. Each failure it finds (a law, its shrunk history, the expected and actual values) is replayed exactly, by its property, unit, seed and path, on the snapshot and on the fix. - **Stable flip**: a found failure whose replay fails on the snapshot and passes on the fix, with none of those runs unable to run. - **Caught**: with a judge, the judge confirms one of the bug's stable flips (at most 5, one per law before any law gets a second), shown its law, history, expected and actual values, with the bug's key line as the only candidate. With `--judge none`, any stable flip counts. The report has one line per bug (`CAUGHT` or `missed`, its flips, how many the judge confirmed of those it was shown, failures not on the snapshot and failures that still fail on the fix), then `oracle catches N/M bugs (…)`, `caught `, the placebo line with `--placebo`, and `unusable : `. A request the judge did not answer is counted as unanswered. **Placebo.** With `--placebo` the same rules run on (fix^^, fix^), a pair without the fix. A pair is skipped and counted when its fix^ is a fix the key names (that pair holds a fix), or when fix^ is a root commit (no fix^^). A bug that flips here flips without its fix: noise. **The run cache.** Each oracle run's record is kept under a key of the oracle files and their contents, the runner's settings, the tree as built (its commit and its build's folder, so a changed `treeSetup` runs again) and the run (the exploration seed, or the replayed failure). The same command again runs nothing; a changed oracle file, setting or seed runs again. A run is not kept when it was stopped by a time limit, when its vitest ended without its final report, or when an error outside any test came with it (that error belongs to the whole batch); a snapshot built again runs everything again. The judge keeps its own verdicts, so the same flips are not asked twice. Two `prefix` runs on one repo may run at once: each judge batch names a pair of its own, so neither reads the other's request or replaces its verdicts. **The judge.** Its verdicts are kept per repo in `/prefix/judge//`, as `judge-in-.json` and `judge-out-.json` pairs (the id is the time, the process and a counter). A request is not asked again while what the judge sees is unchanged: the repro's path within the run, its finding line, the first 1,500 code points of its text, and its candidate key lines. A copied run folder still hits these verdicts. `--judge cache-only` never calls a model: it answers only from them, and counts a request they lack as unanswered. The judge is asked in batches, each request at most once per attempt. A batch it does not answer in full is asked again, about its unanswered requests only, and the answers it already gave are kept; a judge call that fails, or answers with no object, gave no answer. A request that no attempt answers is counted as unanswered. **Replays.** A failure is replayed by its seed, path, property and unit, as the framework's Replay line prints them, and by a test pattern of the failing test's own names (its suites, its property, its unit), which selects that one test whatever the names hold. The runner drops the `ORACLE_` variables of its own environment, so a job runs with its own selection only. **Time limits.** One oracle test may run `--timeout-s`. A batch of runs stops only when no test has ended for `--timeout-s` plus 60 seconds, so a long batch that keeps making progress runs to its end; its own workers are then stopped. A job whose oracle files all ended keeps its result even when its batch was stopped (that result is not kept in the cache); a job that had not ended, or whose files failed to load, is reported as unable to run. ## Laws Each module's design is captured as laws, enforced by its oracle files in `tests/oracle/`: the bench inputs (`bench-manifest`, `bench-key`), the snapshot and its trees (`bench-snapshot`, `bench-seal`, `bench-trees`, `bench-live`), processes and repros (`proc`, `repro`, `verify`), the judge (`judge`), the prefix plan, runner and scorer (`prefix-plan`, `prefix-run`, `prefix-runner`, `prefix-score`), and the commands end to end (`cli`, `cli-cache`). Run them with `pnpm test`. The gap check judges whether the laws notice a change to the code they own, with one config per area (`tests/oracle/vitest.*.gaps.config.ts`). From the repository root, after `pnpm --filter @tanstack/oracles build`: ``` node packages/oracles/oracle-gaps/index.mjs --package packages/bug-search \ --source src/cli.ts,src/prefix/command.ts \ --config tests/oracle/vitest.cli.gaps.config.ts --pool forks ``` `--source` takes one comma-separated list. The CLI and prefix-runner oracles change the working directory, so they need `--pool forks`. ## Setup time limits Each `setup` and `treeSetup` command may run for the manifest's `setupTimeoutSec`, else `BUG_SEARCH_SETUP_TIMEOUT_SEC`, else 900 seconds. On a timeout the command's whole process group is killed, and the snapshot or tree fails with a message that names the command and its limit. pnpm sometimes finishes an install and never exits: a `pnpm install` that times out after it wrote `node_modules/.modules.yaml` counts as a success, with a warning that pnpm did not exit.