# Agent guide This repo is a public, automatically verified leaderboard for quantum LDPC (qLDPC) codes. **Submitting a code?** Read [`SUBMIT.md`](SUBMIT.md) first — it is the compact, machine-oriented spec (one command, `--json` mode, pre-push checklist, common failure modes). The long-form rules below and in `CONTRIBUTING.md` are the source of truth; `SUBMIT.md` is the short view. The `verify/` stack machine-checks submissions; `research/` is a starter kit for constructing and searching for new codes. ## The motto Any board-advancing code is worth submitting: a code that passes the gate and is not dominated by any entry in its track cell. A code that beats no existing entry is still a frontier extension, so "does not beat the cell leader" is never a reason to discard it. The board ranks by Pareto frontier, not by the kd^2/n leader. A board-advancing code whose only strict gain over an entry is distance (d, with n, k and w no better) needs caution, not rejection. Both distances are upper bounds, so such a gain is where inflated bounds show up. Re-measure the peer and the candidate at matched depth (`research/audits/leader_audit.py pair --json-out `) before submitting it; `./qldpc submit --peer-audit ` and `research/kit/promote.py`'s `evidence.peer_audit` take that record and refuse a d-only gain without it. Dominated codes pass the gate but are not board-advancing. Record them as non-frontier results; do not submit them as frontier codes. `passed: true` certifies a valid code and `gates.novelty.board_advancing` a frontier one, and the gate labels the second without refusing on it, so `./qldpc submit` and `research/kit/promote.py` make the refusal: a dominated candidate is refused with its dominators named unless `--allow-non-frontier` files it as a non-frontier record, which the PR body then says (issue #5700). ## Two tiers of change — decide which one you are in before acting Every change to this repository is one of two tiers. The tiers are not a matter of degree; they are a difference in kind, and an agent must not apply the standards of one to the other. **Tier 0 — Code submission / non-critical change.** The diff touches no verifier-critical path (anything `verify/check_submission_scope.py` flags as critical; see `.github/CODEOWNERS`). The common case is a code submission: the diff touches only the submission surface (`codes/`, `circuits/`, `notes/`, `fieldnotes/`, `repro/`, `certs/`) and adds or edits data, which the base branch's trusted verifier judges. It may also touch non-critical files such as `research/`, `docs/`, `README.md`, or `AGENTS.md`. Agents may assist freely — run searches, stage candidates, prepare PRs. The cost of a mistake is one bad entry, caught by the gate and the board. Mechanical checks (verify passes, format ok) are the bar for the entry; the submission-workflow rules in "Choose the workflow before acting" still govern how it is prepared and submitted. **Tier 1 — Challenge operation.** The diff touches the trusted closure: anything `verify/check_submission_scope.py` flags as critical (its `CRITICAL_PREFIXES` and `CRITICAL_FILES`, mirrored in `.github/CODEOWNERS`). It changes the rules that judge *every* entry, now and in the future. The cost of a mistake is the whole board. Mechanical checks are the *floor*, never the conclusion: they prove internal consistency, not that the change should ship. Run `uv run python verify/check_submission_scope.py --classify --base ` to classify a diff objectively rather than by inspection. If it prints tier 1, switch to the Tier 1 standard and do not proceed autonomously. ### Agent review policy (Tier 1) - An agent must **not** post an "Approve" review on a Tier 1 PR without an explicit human maintainer instruction that names that PR, must **not** rubber-stamp a re-pin of `validator_manifest.json`, and must **not** merge, push, or commit a Tier 1 change without an explicit human maintainer instruction that names that change. - When asked to review a Tier 1 PR without such an instruction, the agent's job is to produce an impact analysis and request human review — not to approve. - An agent in unattended mode (`research/AUTORESEARCH.md`) must not touch Tier 1 files at all, not even to "fix" a failing test or "update" a workflow. A needed Tier 1 change is reported as an item for a human, the same way staged candidates are reported. - If an agent finds itself about to approve a Tier 1 PR without such an instruction, it stops and re-reads this section. ### Prohibited framing (Tier 1) An agent must not say or imply "X is fine because the hash matches / the tests pass / the pin is intact / the manifest only moves one line" for a Tier 1 change. Those are preconditions, not conclusions. A Tier 1 conclusion must address behaviour: what changes for future submissions, which threshold or invariant moves (old → new), what failure mode is weakened or strengthened, and why the change beats the lighter alternative. A review that only cites mechanical checks is not a review of a Tier 1 change. ### Tier 1 impact-analysis template When an agent analyses a Tier 1 change it must produce, in this order, and must not omit any item: 1. **Behaviour change** — one sentence. 2. **Invariant / threshold affected** — named, with old → new value. 3. **Lighter alternative considered and rejected** — named, with why. 4. **Who must approve** — named human maintainer (code owner). ## Choose the workflow before acting There are two supported workflows. The user's publication authorization determines which one applies: ### Contributor-driven submission Use this when the user explicitly asks you to submit a code, prepare a PR, create a branch, commit, push, or open a PR on their behalf. Follow `CONTRIBUTING.md`. After the candidate passes the trusted validation gate, the agent may write the verified submission to `codes/` and use `./qldpc submit ... --open-pr` to create the branch, commit, push, and PR. `research/kit/promote.py` is the alternative when the candidate already carries the witnesses the gate accepted: it assembles `codes/`, the note, the PR body, and the `repro/` manifest when the candidate was staged with a recipe, without re-running the distance search, runs the gate and the prose check in order, and returns what is still outstanding as JSON. It writes files and never runs git or gh, so the branch, push, and PR stay explicit. ### Unattended autoresearch Use this when the task is to explore or search for candidates without human review or explicit publication authorization. Follow `research/AUTORESEARCH.md`. Candidates stay in `research/candidates/`; do not write to `codes/`, commit, or open a PR. Report staged survivors for a human to review and promote. If both documents are read, this section is the precedence rule: an explicit contributor-driven submission request selects the first workflow; otherwise use unattended autoresearch. ## Doing autoresearch (finding new codes) Start from **[`research/QUICKSTART.md`](research/QUICKSTART.md)**: the minimal loop and the rules, on one page. **[`research/AUTORESEARCH.md`](research/AUTORESEARCH.md)** is the detailed manual and the reference for the `research/` kit — load the section you need rather than the whole file. The two rules, here so they are never missed: **Dedup before submitting.** Before opening PRs for a batch of candidates, run `uv run python research/kit/dedup_submissions.py ` and collapse each `(n,k,d,w)` / canonical-form group to one representative. Do not open multiple PRs for the same `(n,k,d,w)`. `./qldpc submit-batch --authors @handle` does the dedup, the gate, and one PR per code in one command (SUBMIT.md, Bulk submission). **No code is a "find" until `verify/validate_candidate.py` returns `passed: true` for it.** Run it as `uv run --extra research python research/kit/coordination.py gate `, which calls the gate unchanged and writes its verdict to `.verdict.json` beside the candidate; the gate script alone prints the verdict and keeps nothing. Never write your own distance/quality check or edit anything under `verify/` (the trusted, CI-hash-pinned stack). In unattended autoresearch, stage candidates for human review; the contributor-driven workflow above is allowed to promote a validated candidate into `codes/` and open a PR when the user explicitly authorized that submission. **A found low-weight logical (witness) is the most expensive data we produce — never lose it.** Persist every candidate through `research/kit/submit.make_submission` and then `submit.save_submission(doc, coordination.unique_path(f"{coordination.staging_dir()}/--.json", doc))`, which embed the witness and stage it under this session's own run directory, under a name no other candidate holds; an ad-hoc `python -c` that calls a distance search and prints the result discards it. If a search finds a valid logical but the save fails, that is a hard error — stop and report it. `save_submission` refuses to write over a candidate that is not the one in hand, because several sessions stage at once and the flat `--.json` name hands two of them the same file; `unique_path` gives the second one its own name, and re-saving the same candidate keeps its name. Pass `spec=` to `save_submission` when the code came from a recipe (a `constructor` under `research/kit` and its `params`), so the reproduction manifest can be emitted when the candidate is promoted (issue #2955). `save_submission` also runs the verifier's structural half on the document first (`research/kit/prescreen.preflight`, which is `qldpc_verify.verify(doc, refute=False)`) and raises `PreflightFailure` instead of staging one the gate's verify step would refuse. Nothing is lost: the document and the failed checks go to `rejected/` beside the path. Read the report before deciding what to do. A `construction` or `weight` failure (a direct sum, a check over the 32-qubit cap) is the code's, and no edit to the document fixes it; `packaging`, `typing`, `witness`, or `layout` is the document's, and the code may be fine. `coordination.py gate` makes the same refusal before spending the gate and writes `.preflight.json` instead of a verdict (issue #3616). ## Writing the submission (the PR body and the note) The board's durable value is the evidence trail, and an evidence trail that cites a file nobody else has is not one. `verify/check_prose.py` enforces this on every changed `notes/`/`fieldnotes/` file and on the PR body, and the weekly `prose-sweep` workflow re-reads every committed note and keeps a tracking issue of what no longer resolves: **Every path you name must resolve in the PR's own tree.** Before writing a path, verify it against the submitted PR tree, not only the base checkout or your local workspace. A path that exists only locally, in ignored staging output, or on the base branch must not be presented as a committed artifact. If the artifact lives elsewhere, name the source and pin it — "taken from github.com/a7b/yarn @ 82fb695, `processor_codes/mitten/[[300,60,14]]/Hx.npy`" — or do not cite it. Never write "available on request", and never point at a private checkout (`~/…`, `/Users/…`) or a machine name. **`research/candidates/` is gitignored working output; it can never be the audit trail.** It is the right place to *stage* a candidate (see above) and the wrong place to *cite*. If a search script matters to the result, either commit it or describe the method in the note so someone can rewrite it. Do not mention the staging directory in submission prose unless you are explicitly explaining that it is forbidden as evidence; describe it as local staging output instead. Two more, same reason: - What you claim in the body must match the file in the diff. A distance is `upper_bound` until a certificate says otherwise — do not call a witnessed bound "certified", and do not put a distance in the filename that the JSON does not support. - Model attribution must be honest. `provenance.model` is `"human"` only when a person, not a model, produced the code. If you do not know the exact model/version, omit the field (or write `"unspecified"`) instead of claiming `"human"`; claiming `"human"` for a model-produced code corrupts the board's model attribution and is treated as a misattribution in review. - Delete the drafting scaffolding before asking for review: HTML comments, unticked checklist boxes, session URLs. If a checklist box is not true, make it true or say why (`qldpc submit` ticks the equivalence box itself when its board dedup finds nothing). The drafted body also carries parenthetical prompts (e.g. "(Name the track and the existing entry this beats…)"): replace each with real content. Then run `uv run python verify/check_prose.py --body-file --files ` locally; it must exit 0 before you request review. **Before pushing: run the worktree gate.** A passing local run of `check_prose.py` is not sufficient — it validates paths against your working tree, where uncommitted files exist. CI validates against the PR tree only, so citations to uncommitted files pass locally and fail remotely. Before every `git push` of a submission branch, run: ``` verify/prepush_prose_check.sh ``` Enable the repository's local hooks once per clone so the validator-integrity check runs on every commit (it fails in under a second if a critical file changed without re-pinning `verify/validator_manifest.json`): `git config core.hooksPath .githooks`. It re-runs the check inside a clean worktree of HEAD (committed content only), which fails exactly when CI would, and it runs the submission scope check first: a submission PR carries the entry, its note, and at most its `repro/.json` manifest, so a stray file under `research/` or a directory of run output under `repro/` is reported here rather than by CI (issue #3810). For the full pre-submission sweep (scope, ruff, family-tag consistency, board-marked tests, and prose) in one command, run `./qldpc preflight` (or `scripts/prepush_check.sh`) before that. It must exit 0 before the push. Treat this as part of pushing, not as an optional review step — the working-tree check proves nothing about what CI sees. **Agent self-check before staging or submitting.** These are the mistakes that have turned green local runs into red CI on submission PRs; verify each one before pushing: - **Family tag.** If `provenance.construction` names a family (pair-partition, bivariate bicycle, generalized bicycle), `family` must carry that tag or a more specific one — never `other`. `verify/test_family_tag_consistency.py` enforces this; the kit now infers it in `submit.make_submission` and refuses a mismatch in `prescreen.preflight`. - **Code artifact shape.** A submission is one file, `codes/.json`. Never a directory named `*.json`, never a nested path. `submit.save_submission` refuses a non-`.json` or directory path. - **One concern per PR.** A code submission carries only `codes/` and `notes/`, plus optionally its own `repro/.json` manifest. Kit modules, workflows, and verifier changes go in their own PR first, so the citation resolves and the scope check stays green. - **Derived provenance after removals.** Deleting or renaming a code leaves `research/provenance/derived.json` stale. Run `uv run python research/derive_provenance.py --top-up` and commit the result in the same PR. The weekly workflow repairs this on Monday, but until then every PR based on that main inherits the red tests. In a fork, `origin` is the fork, and its `origin/main` is whatever the fork last synced, which is not what CI diffs against. The script uses `upstream/main` when an `upstream` remote exists and refuses to default to a fork's `origin/main` otherwise, so add the canonical repository as `upstream` (`git remote add upstream https://github.com/unitaryfoundation/qldpc-challenge.git && git fetch upstream`) or pass `BASE=/main`. A note named `--.md` must state its own `[[n,k,d]]` first. Follow `notes/TEMPLATE.md`; its sections are what a later searcher reads. **Attribution is checked, not assumed.** A fieldnote ADDED by a PR must credit the PR author's own GitHub handle in its frontmatter `author:` line — CI passes `--pr-author` to `check_prose.py` and fails on a missing or mismatched handle. Locally, reproduce it with `PR_AUTHOR= verify/prepush_prose_check.sh `. Modifying someone else's existing note is exempt. ## Worktrees A full checkout of this repository is about 8 GB, and 7.6 GB of it is `circuits/`. Worktrees share the object store but not the checkout, so every `git worktree add` copies that tree, and a machine that makes one worktree per PR fills up (issue #6515). Make worktrees sparse, and remove them once the branch is pushed. Create one with cone-mode sparse checkout. It holds the top-level files and the directories a submission, a kit change, or a site change reads, about 225 MB, and takes seconds: ``` git worktree add --no-checkout --detach origin/main git -C sparse-checkout set --cone codes notes fieldnotes repro certs research verify schema cli site receipts decode git -C checkout -b origin/main git -C sparse-checkout add circuits/ # only for a circuit-tier PR, about 2 MB per entry cp verify/gf2_fast.cpython-*.so /verify/ # the built accelerator is ignored by git ``` The last line matters: without the accelerator the circuit gate and the RIS screen fall back to a handful of trials, which is how #5094 came to be refuted in CI. `docs/` is generated output and is never needed in a worktree; add `.github` only for a workflow change. Keep `codes/` in the set even on a certificate-only branch: `verify/check_certs.py` binds every partial and formal certificate to its entry in `codes/`, and in a checkout without that directory it refuses to run and says what to add, rather than reporting every certificate as missing from the board (issue #7405). Remove a worktree as soon as its branch is pushed, with `git worktree remove `. It refuses a worktree with modified or untracked files, but it deletes ignored files without asking, and `research/candidates/` is ignored: move staged candidates or audit logs you still need out of the worktree first. A detached worktree whose commits are not pushed needs a branch before removal (`git branch keep/`), or the commits become unreachable. Run `git worktree prune` at the start of a session and `git worktree list` to see what is still registered. ## Working on the repo itself This is a Tier 1 activity: see "Two tiers of change" above. An agent does not start it without an explicit human instruction naming the change, and never approves or merges autonomously. Re-pinning (step 3) is the instructed step that produces the reviewable manifest diff; it is not an approval. - `verify/` is the trust anchor and is hash-pinned in CI (`verify/check_validator_integrity.py`). Changing it is deliberate. The checklist, in order (issue #4030): 1. `uv run --extra certify python verify/validation_gate.py` must exit 0: the solved cases (Steane, Shor, [[4,2,2]], a direct sum, a local-Clifford image) verify and certify at their known parameters, each deliberately broken artifact is rejected for its own reason (construction, weight, packaging, typing, witness, layout, benchmark, architecture), and the seeded baselines and the mitten and ZSZ lifted-product entries reproduce their committed verdicts byte for byte. 2. If a verdict changed by design, re-record it with `--update-golden` and say so in the PR; that diff is part of the review. 3. Re-pin with `python verify/check_validator_integrity.py --update`, which runs the gate first and refuses otherwise, and get the manifest diff reviewed. - Submissions live in `codes/` (schema: `schema/code.schema.json`); the board/site is generated from them by `site/build.py`. See `CONTRIBUTING.md` and `TRACKS.md`.