# OpenGWASDB Store Format Specification

Status: draft  
Format version written: `0.3.0`, `0.2.3`'s features with the variable-length ALID sidecar, the position sidecar and the `source_alid` sidecar, and without `variant_offsets.npy` (§4, ADR 0105), what only the validator read (§1.1, ADR 0102, #471) or a Hybrid Dense Component's own copy of the shared variants and Analyses (§16, ADR 0102 §4, #472), which every build and completion writes and `ogdb rewrite-release` derives from a `0.2.3` release (§21.4)  
Also readable: `0.2.3`, `0.2.2`, `0.2.1` and `0.2.0` (Zarr v3 with sharding, §10a; the fixed-width ALID index; indels spelt reference first from `0.2.2`, sorted before it), and `0.1.0` (Zarr v2); nothing else (§21). Sections below that name no version describe `0.2.2` and every later one.

This document defines the contract for valid OpenGWASDB Store Releases. Every
builder and completion of this package writes `format_version` **0.3.0**: 0.2.3's features with the variable-length ALID sidecar
in place of the fixed-width ALID index (§4, ADR 0105), and without `index.sqlite`'s
`metadata` and `variant_aliases` or the Top-Hit tiers' `abs_z` and `p_value`, so an
Observed-Only release carries no `index.sqlite` (§1, §18; ADR 0102, #471), and with a
Hybrid's Dense Component reading the shared variants and Analyses (§16, #472). It also describes **0.2.3**, which every builder wrote from #338 to #467
(0.2.2 and the count of associations left out for an SE above 65,504, §7a); **0.2.2**,
what every builder wrote from #381 to #338: Zarr v3 with the sharding codec (§10a),
an indel's ALID spelt reference first (§4, ADR 0079), and a Ragged release's optional
`regions.tsv` (§1, §17);
**0.2.1**, which package 0.9.0 stamps a Ragged release carrying `regions.tsv`, its
indels sorted (issue #430); **0.2.0**, the same layout with neither, which every
builder wrote from #247 and the converter still writes; and **0.1.0** (Zarr v2),
which a reader still reads and a builder no longer writes. The four 0.2 releases
are "the 0.2 series" below wherever the layout is meant; 0.3.0 has the same layout.
Everything below that is not about the physical layout, the ALID index, the indel
ALID or the region table holds for all of them: statistic planes carry a
declared encoding (§6a), `z` is `int16` fixed point rather than `float16`, `eaf`
is a per-variant baseline plus a per-cell `int8` logit residual rather than a
`float32` plane, and `se` is either `float16` or — when the build measures the
fit and the saving — an `int8` residual from its EAF-predicted value.

**`0.1.0` is a reset, not a fifth version** (ADR 0041, issue #143). The format
carried `0.1`, then `1.0`, `2.0` and `3.0` through a single pre-release cycle,
and no store in any of them was published outside the core team. All four are
now refused rather than decoded, with a message that says rebuild; the shape
change from `MAJOR.MINOR` to `MAJOR.MINOR.PATCH` is what makes that refusal
reliable, since no reader — including one written before the reset — can read
`0.1.0` as `0.1`. The bytes are unchanged from `3.0`, which is why a `3.0`
release may be restamped rather than rebuilt (§21.4); every earlier version is a
different encoding and is rebuilt.

Sections that say "v0.1" below describe vocabularies and column contracts
settled early and unchanged since; they are not statements about
`format_version` `0.1`, which is a pre-reset format this build does not read.

Normative language:

- **MUST** indicates a requirement for a valid store.
- **SHOULD** indicates a recommended default that implementations may override with documented reason.
- **MAY** indicates an optional feature.

## 1. Store release envelope

A Store Release is a self-contained directory.

```text
manifest.json
index.sqlite               (0.2; from 0.3.0 only beside completion_quality, below)
analyses.tsv
overview.html
data.zarr/
variants.tsv.gz
variants.tsv.gz.tbi
variant_offsets.npy        (0.2 and 0.1 only)
variant_alid_utf8.npy      (0.3.0: the ALID sidecar, §4)
variant_alid_offsets.npy   (0.3.0)
variant_alid_keys.npy      (0.3.0)
variant_alid_order.npy     (0.3.0)
variant_position.npy                     (0.3.0: the position sidecar, §4)
variant_position_chromosomes.npy         (0.3.0)
variant_position_chromosome_offsets.npy  (0.3.0)
variant_source_alid_state.npy            (0.3.0: the source_alid sidecar, §4)
variant_source_alid_utf8.npy             (0.3.0)
variant_source_alid_offsets.npy          (0.3.0)
variant_alid_bytes.npy     (0.2 and 0.1 only)
variant_alid_rows.npy      (0.2 and 0.1 only)
variant_rsid_bytes.npy
variant_rsid_rows.npy
regions.tsv            (Ragged only, optional)
```

`manifest.json` identifies the release and declares how to interpret it.
`index.sqlite` stores large fine-grained tables that are not practical as flat
text: Reference Completion Quality (§12). From format 0.3.0 that table is all it
holds, so it ships only in a Reference-Completed release, a Hybrid's in its Dense
Component, and the Store Reader never opens it (ADR 0102, #471). A 0.2 release
carries one in every release, with a `metadata` key/value table and a
`variant_aliases` alias map beside any `completion_quality`. `analyses.tsv` is the
sole source of truth for Analytical Metadata (§7a) — one row per Analysis;
`index.sqlite` MUST NOT also contain an `analyses` table. `overview.html` is a
generated, store-wide human-browsable rendering of `analyses.tsv`; it MAY be
regenerated from `analyses.tsv` and MUST NOT be treated as a second source of
truth — Ragged releases do not carry one (§11). `data.zarr/` stores compressed
numerical association arrays and layout-specific numerical indexes. Every
layout stores its high-cardinality variant axis in `variants.tsv.gz`, indexed
by `variants.tsv.gz.tbi`, and the sidecars beside it: in the 0.2 and 0.1 series
`variant_offsets.npy` mapping Store-local Variant Indices to BGZF row offsets,
which 0.3.0 does not carry (§4, #469); the ALID sidecar (from 0.3.0; §4) or, in
the 0.2 and 0.1 series, `variant_alid_bytes.npy`/`variant_alid_rows.npy`
supporting ALID lookup, the position sidecar (from 0.3.0; §4) answering a
genomic range, which the 0.2 and 0.1 series answer through the tabix index, the
`source_alid` sidecar (from 0.3.0; §4) naming each row's pre-liftover ALID, which
the 0.2 and 0.1 series hold in the table's `source_alid` column alone, and
`variant_rsid_bytes.npy`/`variant_rsid_rows.npy` supporting rsid lookup
(issue #109). The rsid pair is written by every layout and MAY be empty — a
source that names no variants indexes none — but a release whose
`variants.tsv.gz` carries rsids and whose index does not is invalid (§20):
every rsid lookup against such a release returns an empty result
indistinguishable from a real absence.

`index.sqlite` MUST NOT contain a `variants` table. The variant axis is
`variants.tsv.gz` plus the offset and search sidecars above; a relational copy
duplicated every column of the table it shadowed, was read by nothing, and
carried a `rsid` column that no builder populated — a fourth copy of the axis
that disagreed with the other three (issue #128).

The rsid index, and the 0.2 series' ALID index, are fixed-width arrays, because
that is what allows a binary search over them without parsing. An identifier too
wide for its slot MUST be left out of the index and the omission counted — never
cast into it.
Casting truncates, and two variants whose identifiers agree over the slot width
then share one key, so a lookup by either returns whichever row sorts first: one
variant answering to another's name, with nothing to show it (issue #127). An
ALID omitted this way stays reachable, resolved by exact scan over its position;
an rsid omitted this way is not resolvable by name, which is why the widths are
chosen from measured data and the omission is reported at build time. From 0.3.0
the ALID index is the variable-length sidecar (§4), which indexes every ALID,
however long, and omits none.

A Ragged release MAY carry `regions.tsv`, the region table its build recorded:
one row per region it kept rows for, of four kinds, of which only `cis` and
`significant_trans` rows are the regions Reference Completion fills (§17, issue
#430). It is a tab-separated text table beside `analyses.tsv`, written by the
same writer, and declared by the manifest's `regions` entry (§2), through which
a reader finds it; a release that carries it is stamped `format_version` 0.2.1 by
package 0.9.0 and 0.2.2 by every build since #381, whose indels are spelt reference
first (§21.3), and a release whose Association Coverage is not `cis` cannot be
completed without it.

This is the complete envelope for a standalone Dense or Ragged Store Release.
A Hybrid release additionally nests a `dense/` Dense Component directory
holding a Dense Store Release of its own, with `dense_to_shared.npy` mapping its
rows into the Hybrid release's shared variant table — see §16. From format 0.3.0
that component carries only `manifest.json`, `data.zarr/`, `dense_to_shared.npy`
and, when Reference-Completed, `index.sqlite`: no `analyses.tsv`, `overview.html`,
Variant Table, `.tbi` or variant sidecar, as it reads the Hybrid release's through
the map (#472). Before 0.3.0 it carried the envelope above as well. §20 requires every Store Release's
directory to be closed: no file or directory beyond what its `primary_layout`
legitimately produces per this section and §10/§11/§16/§17.

Build and query commands operate on an explicit Store Release path. Directory naming, multi-store catalogues, default release selection, and remote API deployment are outside the store-format contract.

### 1.1 What each component is for

Every component a Store Release ships is in one of three classes
([ADR 0102](../adr/0102-what-a-store-release-ships.md)). A component is a file or directory in
the envelope, a Zarr array, a SQLite table, or an `index.sqlite` metadata key.

- **read**: the Store Reader reads it to answer a query. An *accelerator* is a read component
  that can be recomputed from the primary data and exists for speed.
- **provenance**: the Store Reader does not read it. It records how the release was made, and it
  cannot be recomputed from the release's other components.
- **convenience**: the Store Reader does not read it, and it can be recomputed. It is there for a
  person, or for a tool outside OpenGWASDB, to use directly, and no other component that such a
  tool can use presents the same facts. A convenience that restates shipped data
  (`variants.tsv.gz`, `variants.tsv.gz.tbi`) is checked against it by the `variant_table.*` rules
  (§20.0). A rendered report (`overview.html`) is regenerated, never read by any code, and never
  validated.

A component in none of the three classes is **dropped**: if it can be recomputed, whatever needs it
recomputes it. What only the validator reads is never, by that alone, a reason to ship it. ADR 0102
§2 states the rule as the steps a reviewer applies to a new component.

The table gives each component's class from format **0.3.0**, the version that applies these
decisions (epic #450). The ticket that moved a component to its class is in the last column;
0.2.x releases keep their envelope.

| Component | Where | Read today by | From 0.3.0 | Ticket |
|---|---|---|---|---|
| `manifest.json` | every release | Store Reader | read | — |
| `analyses.tsv` | every release | Store Reader; validator | read | — |
| `data.zarr` planes: `z`, `se`, `eaf`, `eaf_baseline`, `se_coefficients`, the exception and overflow tables; group metadata | every release | Store Reader | read | — |
| `data.zarr` `imputed`, `eaf_reference` | Reference-Completed | Store Reader (the presence mask; reference EAF on imputed cells) | read | — |
| `data.zarr` `ragged/` cell arrays | Ragged; Hybrid Overflow | Store Reader | read | — |
| `data.zarr` `ragged/by_variant/` (By-Variant Index) | Ragged; Hybrid Overflow | Store Reader | read (accelerator, ADR 0060) | — |
| `data.zarr` `top_hits/<tier>/` `variant_index`, `analysis_index`, `analysis_offsets`, `z`, `se`, `eaf`, `imputed` (Top-Hit Index) | every release | Store Reader | read (accelerator) | — |
| `data.zarr` `indexed_subsets/<name>/` | Dense, optional | Store Reader | read (accelerator, optional; §10b) | — |
| `data.zarr` `rho/` | Dense, optional; a Hybrid's Dense Component, optional (`dense/data.zarr/rho`, with `overflow_only`); no release carries one | Store Reader | read, optional: ships only once the Store Reader reads it | #496 |
| `data.zarr` `top_hits/p_5e_08/clumps/default/` `lead`, `r` (the Clumps, §18.1) | every layout, optional, from 0.3.0; no release carries them yet | validation, through the Store Reader's `TopHitTier.clumps` (#418); no query yet: the Top-Hit Query from #419 | read (accelerator, optional, with the LD Store it needs recorded; ADR 0106 §11): ships only once a query reads it (#419) | #418, #419, #420 |
| `data.zarr` `on_panel` (Reference Panel Membership) | Dense Reference-Completed | validator only | provenance | — |
| `data.zarr` `top_hits/<tier>/abs_z`, `p_value` | every 0.2 release; none from 0.3.0 | validator only (0.2: `top_hits.abs_z` holds them to what `z` implies) | dropped: the validator recomputes them from `z` | #471 |
| `variant_rsid_bytes.npy`, `variant_rsid_rows.npy` | every release | Store Reader (rsID lookup; from 0.3.0, inverted, a row's rsID) | read (and inverted, for the rsID of a row) | #469 |
| `variant_alid_bytes.npy`, `variant_alid_rows.npy` | every 0.2 release; none from 0.3.0 | Store Reader (0.2.x); validator | dropped: replaced by the variable-length ALID sidecar, which is read | #467 |
| `variant_alid_utf8.npy`, `variant_alid_offsets.npy`, `variant_alid_keys.npy`, `variant_alid_order.npy` (the variable-length ALID sidecar, §4) | every release from 0.3.0 | Store Reader (`by_alid`, `lookup`, `identity_by_indices`); validator | read | #467 |
| `variant_position.npy`, `variant_position_chromosomes.npy`, `variant_position_chromosome_offsets.npy` (the position sidecar, §4) | every release from 0.3.0 | Store Reader (`range_phewas`, `range`); validator | read | #468 |
| `variant_source_alid_state.npy`, `variant_source_alid_utf8.npy`, `variant_source_alid_offsets.npy` (the `source_alid` sidecar, §4) | every release from 0.3.0 | Store Reader (`variants_table()`, the `source_alid` of a resolved row and of a record); completion; the validator's source-fidelity join; validator | read | #470 |
| `variants.tsv.gz` | every release | Store Reader on 0.2.x (`variants_table()`, the rsID and `source_alid` of a resolved row); from 0.3.0 no query (#469) and no completion (#470); validator | convenience: derived from the sidecars, for tabix, bedtools and R | #465, #469, #470 |
| `variants.tsv.gz.tbi` | every release | Store Reader (`range_phewas` on 0.2.x, through tabix; 0.3.0 asks the position sidecar); validator | convenience: rebuilt with `tabix -s1 -b2 -e2 -c'#' variants.tsv.gz`, or `Rsamtools::indexTabix()` | #468, #469 |
| `variant_offsets.npy` | every 0.2 release; none from 0.3.0 | Store Reader on 0.2.x (the variant count; `by_index`); validator | dropped: the ALID sidecar counts the variants, and nothing seeks a row of the table | #469 |
| `overview.html` | Dense; Hybrid | nothing | convenience: derived from `analyses.tsv` and `manifest.json`, rewritten by `ogdb regenerate-overview` | — |
| `regions.tsv` | Ragged, optional | completion; validator; `ogdb info` | provenance: the build's region boundaries and leads (§17) | — |
| `index.sqlite` | every 0.2 release; from 0.3.0 a Reference-Completed one (not a Hybrid's outer release) | nothing from 0.3.0; on 0.2, the Dense and Hybrid query facades (the `variant_aliases` fallback) | provenance: present only to hold `completion_quality`, so only in a Reference-Completed release; the Store Reader never opens it | #465, #471 |
| `index.sqlite` table `completion_quality` | Reference-Completed | completion (the `analyses.tsv` roll-up); `check-observed-view` | provenance: Reference Completion Quality (§12), which needs the LD Reference Panel to recompute | — |
| `index.sqlite` table `metadata`: keys `dense`, `n_variants`, `n_analyses`, `schema_version` | Dense; Hybrid; 0.2 only | validator (`dense`, 0.2); nothing (the other three) | dropped: `manifest.json` and the arrays carry the same facts | #471 |
| `index.sqlite` table `variant_aliases` | Dense; Hybrid; 0.2 only | Store Reader (0.2: fallback after an rsID index miss); validator (0.2) | dropped: empty in every release measured, and the rsID sidecar covers it; from 0.3.0 an rsID the rsID index lacks is a miss | #471 |
| `dense` (the Dense Component), with its `manifest.json` and `data.zarr` | Hybrid | Store Reader | read | — |
| `dense_to_shared.npy` (in `dense`) | Hybrid | Store Reader (every variant question about the Dense Component, from 0.3.0); validator | read | #472 |
| `dense/variants.tsv.gz` and its `.tbi`, `dense/variant_offsets.npy`, `dense/variant_alid_*.npy`, `dense/variant_position*.npy`, `dense/variant_rsid_*.npy` | Hybrid, 0.2 only | nothing from 0.3.0, which does not ship them; on 0.2, the validator, completion and the Indexed Variant Subset builder (the Hybrid query reads the shared axis on every format) | dropped: the shared sidecars through `dense_to_shared.npy` replace them | #472 |
| `dense/analyses.tsv` | Hybrid, 0.2 only | nothing from 0.3.0; on 0.2, completion (its `n_missing_se_out_of_range`) and the validator | dropped: it repeats the root `analyses.tsv`, undercounts Top-Hit Counts (issue #107), and its one fact the root lacks, the Dense Component's own `n_missing_se_out_of_range`, no reader needs (§16) | #472 |
| `dense/overview.html` | Hybrid, 0.2 only | nothing | dropped: the root `overview.html` presents the same Analyses | #472 |
| `dense/index.sqlite` | Hybrid: every 0.2 release; from 0.3.0 a Reference-Completed one | nothing from 0.3.0; on 0.2, the nested query facade | provenance, as `index.sqlite` above (Reference-Completed only) | #471, #472 |

## 2. Manifest contract

Every Store Release MUST contain `manifest.json`.

Required fields:

| Field | Meaning |
|---|---|
| `store_id` | Stable identity of the logical Store |
| `release_id` | Identity of this immutable release |
| `format_version` | Store format version |
| `primary_layout` | `dense`, `ragged`, or `hybrid` |
| `association_coverage` | What the release retains of each source Analysis's associations: `gwas`, `cis`, `cis_and_signals` or `signals_only` (§2a) |
| `completion_state` | `observed_only` or `reference_completed` |
| `reference_assembly` | One genome assembly for all coordinates in the release |
| `created_at` | Release creation timestamp |
| `provenance` | Source and build provenance object |
| `encoding` | How the statistic planes are encoded (§6a). Required in every readable release; the pre-reset formats that omitted it are refused (ADR 0041) |

A Ragged release that carries `regions.tsv` (§1, §17) MUST also declare it, and a
release that carries none MUST NOT have the field:

| Field | Meaning |
|---|---|
| `regions` | The region table: `{"path": "regions.tsv", "sha256": <hex SHA-256 of the file's bytes>}`. A Reference-Completed release declares its source's entry unchanged, since it carries the file byte for byte |

A 0.3.0 release that carries the Clumps of its 5e-8 tier (§18.1, ADR 0106) MUST also
declare them, and a release that carries none MUST NOT have the field. No earlier format
carries them. A Hybrid release declares them in both manifests, its root's and its Dense
Component's:

| Field | Meaning |
|---|---|
| `clumps` | `{"tier": "p_5e_08", "configuration": "default"}`: the tier clumped and the one stored Clumping Configuration. The provenance is the group's `clumps` attribute (§18.1). Written last by the step that writes the component, so a release whose step was interrupted carries a group it does not declare, which `validate` fails |

Reference-Completed releases MUST additionally declare:

| Field | Meaning |
|---|---|
| `ld_reference_panel` | The panel defining the Reference Variant Set and LD resources |
| `reference_completion_method` | Algorithm, software, version, and parameters used for imputation |

Observed-Only and Reference-Completed releases for the same source collection SHOULD share `store_id` and use different `release_id` values.

A release derived from another one — by migration or reference completion — is a new immutable release with its own identity: it MUST NOT reuse the source's `release_id`, and MUST record a fresh `created_at`. The restamp migration additionally records the source `release_id` in its provenance (§21.4).

Published releases are immutable, but for the in-place cases §21.4 lists. Enhancing an Observed-Only release to Reference-Completed produces a new release.

### 2a. Association Coverage

`association_coverage` states **what the release retains**, independently of its
Primary Storage Layout and Completion State (ADR 0009, ADR 0064):

| value | the release retains |
|---|---|
| `gwas` | every association the source reports, genome-wide |
| `cis` | a cis window around each Analysis's target, and nothing else |
| `cis_and_signals` | a cis window plus significant signals elsewhere |
| `signals_only` | significant signals and their flanks, with no cis window |

`full` is the pre-#298 spelling of `gwas`. A reader MUST accept it and report
`gwas`; a build MUST NOT write it, and neither MUST a derivation — a converted,
restamped or amended release states the vocabulary the deriving package writes,
not the spelling it read (§21.0).

A `dense` or `hybrid` release has a cell for every (variant, Analysis), and a
missing cell there means the source did not report the association — which is
what Reference Completion imputes. So a `dense` or `hybrid` release MUST
declare `gwas`, and a release declaring anything else is invalid. A `ragged`
release is the list of associations kept, so absence states itself and it MAY
declare any of the four. Validators reject a release outside this rule (ADR
0064).

## 3. Identity and terminology

An **Analysis** is one statistical analysis of one Trait. An Analysis produces associations between that Trait and variants.

A **Trait** is a measured or derived outcome. `phenotype` is treated as a synonym in user-facing descriptions, but the canonical term is Trait.

A Store Release contains one or more Analyses. Analysis metadata MUST be sufficient to interpret stored effect scales, sample-size semantics, and source provenance.

## 4. Variant identity and variant table

Each Store Release MUST contain a Store Variant Table.

The canonical within-Store variant key is ALID:

```text
chr:pos:A1:A2
```

where:

- coordinates are on the release's declared Reference Assembly;
- chromosome labels use canonical `X`, `Y`, and `MT`; source labels `23`, `24`,
  and `25`/`26`/`M` respectively MUST be normalised to those labels before
  identity assignment (ADR 0052);
- alleles are upper-cased, trimmed and left-aligned before identity
  assignment. VCF and GWAS-SSF bases are case-insensitive, so a lower-case
  base is the same base: a source spelling `a`/`g` and one spelling `A`/`G`
  name one variant, on every build path and in extraction (issue #360);
- where the two alleles are one length — an SNV, or a substitution of several
  bases — `A1` is alphabetically first and `A2` the other allele;
- where their lengths differ — an indel — `A1` is the **reference allele** and
  `A2` the alternate (format `0.2.2`, issue #381, ADR 0079).

An indel is written reference first because a sorted ALID cannot tell an
insertion from the deletion of the same sequence. At a repeat both are real:
FinnGen R13 BMI_IRN reports `1:827587` `G>GGGGCC` (alt frequency 0.83%) and
`GGGGCC>G` (0.05%), which a sorted ALID spelt both `1:827587:G:GGGGCC`; they
are `1:827587:G:GGGGCC` and `1:827587:GGGGCC:G`. An insertion's ALID is
unchanged, since an anchored indel's shorter allele sorts first; a deletion's
is reversed. The reference allele is the one the source declares: GWAS-VCF's
`REF`, FinnGen's `ref`, a `ref_alt_effect_is_alt` Column Map's `ref`. After a
lift it is the release assembly's: the source's declared reference projected
onto that assembly, complemented on a reverse-strand chain block, so a lift
never re-orients an indel. A genome reference sequence would not settle it:
where the genome reads `GGGGCC`, both readings fit it.

A signed statistic is oriented on the same upper-cased alleles: it is stored
for `A1`, so a source allele pair `a`/`G` whose effect allele is `G` is
negated, as `A`/`G` would be, and an indel's statistic is signed for its
reference allele: FinnGen's deletion `GGGGCC>G`, whose beta is for `G`, is
stored negated at `1:827587:GGGGCC:G`. A source's own spelling survives only as
provenance — a Variant Reference's source keys — and in the rsid harvest
below, which compares the names a site's spellings carry.

A source row whose chromosome is missing (an empty cell, `.`, `NA`) or whose
allele, upper-cased, holds a character other than A, C, G or T names no ALID,
and neither does an indel whose source declares no reference allele. Every
builder drops such a row, and logs it in the build's Admission record as
`chromosome_missing`, `allele_invalid` or `indel_reference_undeclared` (issues
#365 and #381, ADR 0072). A source declares no reference when it names an
effect and an other allele: a BESD `.esi`, a `build-dense` association TSV,
and an `effect_and_other` or `ref_alt_and_effect_allele` Column Map. Its SNVs
and substitutions are stored as before.

GWAS-SSF declares the reference row by row, by its layout, which the reader
tells from the header (ADR 0079):
- where the harmonised alleles are the main columns, beside `hm_code`, a row
  whose code is 10 or 11 declares its `other_allele` the reference, and an
  indel on a row of any other code is dropped as `indel_ssf_hm_code`;
- where the study's alleles are the main columns and the harmonised ones are
  `hm_other_allele`/`hm_effect_allele`, every indel is dropped as
  `indel_ssf_hm_columns`;
- where the file carries no harmoniser column, every indel is dropped as
  `indel_ssf_unharmonised`;
- a file with any other mix of harmoniser columns is refused.

The Admission record counts, per Analysis, the indel rows a harmoniser code kept
(`indel_rows_kept_by_hm_code`, rows read before duplicates are resolved) beside
each reason's drops. An LD Reference Panel
places its indels by a `REF` column, or by an indel-reference table settled by
GRCh38 evidence, and places none where it has neither (§13). An alt, random or
unplaced contig is a chromosome, in a source already on the release's assembly.
A lift onto one is not (below).

A Store Release of `format_version` `0.2.0` or `0.1.0` sorts an indel's two
alleles too, and is read as it was written: nothing rewrites its ALIDs. In such
a Store a deletion is spelt like the insertion of the same sequence, and its
statistic is signed for the alphabetically first allele. A source-fidelity
check (`validate --source`) spells the source's indels the same way when it
reads one.

A Store holds the primary assembly's contigs: `1`–`22`, `X`, `Y` and `MT` (their
numeric aliases and a `chr` prefix are the same contigs). A lift that places a
source variant on any other contig, an alt, random or unplaced one such as
`11_KI270927v1_alt`, does not place it: every builder drops the variant's rows
from the Analyses that declare it, and logs and counts them in the Admission
record, per Analysis, as `lift_off_primary` (#376, ADR 0072). A source already on
the release's assembly is unchanged: its alt contig is a chromosome. A Variant
Reference's extraction drops such a site too, so the reference holds no ALID that
only a lift reaches, and logs how many. A build routed by a reference lifts the rows
the reference does not hold, as the Hybrid fold lifts its off-reference keys, and
counts those the chain places off the primary assembly as `lift_off_primary` and
not `off_axis`; a reference extracted before #376 may still route a lifted row
onto an alt contig, and the build drops that row and its ALID, and counts the row
the same way. The release records the lift by `source_alid`, which `validate`
judges (`variant_table.lifted_contig`, §20.0): it names the contig a lifted
variant came from, and a row whose `source_alid` was blanked by a collision is not
judged, so a release can be checked for the drop only where that column survives. A
plain ALID list, or another Store's variant table, used as a Variant Reference
records no source keys: the build keeps an alt-contig ALID it holds, as a GRCh38
source's variant, and its row stays empty in the release, which
`variant_table.lifted_contig` passes because the row's `source_alid` is the ALID itself.
A release rebuilt from a published axis therefore holds the axis's alt-contig
variants, with no associations, until the axis is rebuilt from the sources.

A build that lifts a source variant from another Reference Assembly MUST project
the variant onto the release's assembly using the chain block's orientation: on a
reverse-strand block the alleles are complemented before the ALID is formed, so
the stored ALID names the variant the release's assembly carries rather than the
source's allele string at a moved coordinate. Signed statistics follow the
projected alleles, so a lift that swaps which allele is `A1` flips them
(§5).

A Variant Reference containing any indel MUST start with the physical line
`#opengwasdb-variant-reference<TAB>1` followed by a newline, where `<TAB>` is one
tab character. Version `1` declares that every indel is written reference first;
it is an input-format declaration, independent of a Store's `format_version`.
The next line is the existing column header or the first ALID of a plain list.
Identity table headers retain the resolver's case-insensitive `alid`,
`variant_id` and `id` aliases, splitting generic whitespace, including mixed
spaces/tabs and independent leading/repeated padding in headers and rows.
Unheaded lists retain their first ALID. Routed artifact headers and rows remain
tab-precise TSV so empty routing cells survive.
The declaration applies equally to plain text and gzip inputs,
is allowed only once at the start, and an unsupported version is refused.
SNV-only and equal-length-substitution inputs remain usable without it.

Every reader MUST refuse the first indel in an unmarked input, naming its row
and ALID and requiring regeneration with reference-first indels (owner, 16 Nov
2026, issue #381, ADR 0079). Both lexical orders are refused: a sorted legacy
deletion has the same bytes as a valid reference-first insertion, and an
unsorted row elsewhere proves nothing about that row. No reader guesses from
allele order, a filename, a genome match or a content fraction, or swaps alleles.
A detached Store Variant Table follows this rule even beside a manifest: these
readers do not open and verify the release envelope. Regenerate a separate
declared reference rather than prepend a marker to legacy or published bytes.

`variants.reference` owns the declaration and refusal for both its full routing
reader and its streaming ALID iterator. The Dense and Hybrid single-pass
builders, Hybrid's legacy reference-panel reader, the resolver's Variant
Reference loader and BESD's streamed lift check all use it. Streaming consumers
exhaust the input before using their result, even when no positions are wanted;
an unrequested indel cannot bypass the rule. Their retained memory remains
bounded by the ALID set or requested intersection, not by the routing table.

A Variant Reference artifact (`*.variant-ref.tsv.gz`, which
`extract-variant-reference` writes) records such a lift, so that a single-pass
build routed by it stores what the two-pass build stores. Its columns are
`alid`, `chromosome`, `position`, `a1`, `a2`, `rsid`, `routed_source_keys` and
`reoriented_keys`, after the declaration above. Both artifact writers, including
streaming extraction's first gzip member, always emit that declaration. A row's
ALID is formed from the projected alleles;
`routed_source_keys` lists, `;`-separated, the source keys
(`chrom:pos:ref:alt`, as each source spells them) that route to it; and
`reoriented_keys` lists those of them whose lift makes the other allele `A1`,
whose statistics a build routed by the artifact re-orients (§5). A
reverse-strand key whose `A1` does not change, such as an indel the complement
leaves in order, is in `routed_source_keys` alone, under its projected ALID.
An empty cell lists no keys. A list with an empty element or a key named twice
is refused, naming the row, and so is a re-oriented key its row does not route.

Every extraction before issue #354 named the routing column `source_keys` and
recorded no re-orientation. Such an artifact cannot say which keys were
re-oriented, and may name a reverse-strand key's ALID on the source's strand,
so every reader of a Variant Reference MUST refuse one whose header names
`source_keys`, rather than read it as re-orienting nothing or check a lift
against its ALIDs: the single-pass builds, `build-ragged-besd`'s lift check
and `resolve-analyses --variant-reference` all do. It is extracted again. The
column was renamed for the converse: an engine before issue #354 requires
`source_keys`, so it refuses a new artifact rather than route it without its
re-orientation. A plain ALID list and a Store Variant Table name no such column;
they still need the declaration above if they contain indels. The tab-separated
declaration also makes the previous full Variant Reference reader refuse an
unknown header rather than accidentally read a new artifact as a plain list
and discard its routing. Older independent consumers have no such guarantee;
use an upgraded engine for declared references. This changes no Store Release
format, array or existing Store-reading behavior.

The BESD builder (`build-ragged-besd`) checks its lift, and records that it
did. Given `--variant-reference`, a reverse-strand lifted variant whose alleles
the reference spells on the other strand fails the build naming the variant; a
variant the reference names with a *different* allele pair, or does not name at
all, is counted rather than failed — a Variant Reference is a variant list, not
a genome, and cannot say that a variant it omits does not exist. A lift with no
reference warns and is recorded as unchecked rather than passing as verified.
That release's `manifest.json` `provenance.lift` records the source Reference
Assembly, the chain, the reference (or `null` when none was supplied) and the
verified / other-variant / absent counts (issue #284, ADR 0062), `n_lifted`
(the sites the chain mapped, those it placed off the primary assembly included) and
`n_off_primary` (those sites, which §4 leaves out and the Admission record counts as
`lift_off_primary`).

A lift that lands two ESI entries on one canonical variant is ambiguous, and
MUST be dropped, not resolved: a source of 9,000,000 rows cannot fail the way
one Analysis can, and nothing in the file set says which of the two entries a
probe's association belongs to. Every entry in such a group is dropped, with
its associations — never one of them kept, chosen by position, allele order or
row order — so no Analysis holds one `variant_index` twice (§11). The same
refusal applies to a source that lists one variant under two entries without a
lift, because it is the store's invariant that is at stake rather than the
chain's. `build-ragged-besd` reports the drop on stdout and in
`provenance.lift` as `n_collisions` (entries dropped) and `n_collision_groups`
(contested variants), beside `n_lifted`; a same-assembly build has no lift
record to hold them, and carries the same two fields in the provenance's root
(issue #304).

The Dense and Hybrid builders lift through the same projection and re-orient
their statistics from it, but they do not perform this allele check and record
no `provenance.lift`; nothing in this section requires them to until one is
added deliberately.

`build-ragged-ssf` lifts too (issue #386). A Ragged SSF Store is one build,
GRCh38, and every manifest row declares its source's build: a row that declares
none is refused. A source on hg19 (GRCh37) is read oriented in its own build,
lifted by `--chain-file`, which any such row requires and which is refused before
any source is read when it is missing, and re-oriented by the rule above. Its
sites are placed together, through the placement Variant Routing uses
(`place_sites`), once every Analysis's rows have been admitted: the failure rate
`--liftover-failure-threshold` bounds (default 0.01) is the lifted group's, as in
the Dense and Hybrid builds. Three drops are counted in the Admission record, per
Analysis, as `lift_unmapped` (the chain places the site nowhere),
`lift_off_primary` (it places it on an alt, random or unplaced contig) and
`lift_ambiguous` (a Routing Key that a lifted source and a source already on
GRCh38 both declare: two loci that share a string, dropped from the Analyses of
both, as Pass 1's union drops it). Two source sites that lift onto one variant
are one Analysis's duplicate rows, and the duplicate rule resolves them. A
lifted Store records `provenance.lift` as `build-ragged-besd` does, with
`n_unmapped`, `n_off_primary` (sites lifted onto an alt, random or unplaced
contig, counted as `lift_off_primary` and left out) and `n_ambiguous` (Routing
Keys) beside `n_lifted` (the sites the chain mapped, those off the primary assembly
and the ambiguous ones included), and `reference: null`: the lift is not checked against a Variant Reference. A Store
whose sources are all on GRCh38 records no `provenance.lift`. A build with any
non-GRCh38 source holds every Analysis's admitted rows in memory until the lift
has placed them; a GRCh38-only build reads one Analysis at a time. A lift that
leaves no variant refuses the build, naming each Analysis's `lift_unmapped`,
`lift_ambiguous` and `lift_off_primary` counts, after the Admission record is finished.

Cross-Store identity is:

```text
reference_assembly + ALID
```

`rsid` is an alias, not primary identity.

One rsid MAY name several Store-local Variant Indices — a multi-allelic site,
or one position stored under both allele orders — so an rsid is not a key.
Resolution therefore has two contracts (issue #109): an API returning a *set*
of variants MUST return every row the rsid names, and an API whose contract is
a single variant MUST resolve to the lowest Store-local Variant Index among
them. Neither may silently pick an arbitrary one.

Where a build obtains the `rsid` column, and what wins when inputs disagree,
is part of the contract (issue #255):

- A build that reads its sources (a two-pass build, or a single-pass build
  whose reference names no variants) takes the **first non-empty** rsid a
  source names for a variant, in `(rank, site)` order — Pass 1's manifest-order
  reduction, so the first Analysis listed that names the variant. A later
  source's different name for the same variant does not replace it, and a `.`
  or empty cell names nothing and never clears an earlier name. Several source
  coordinates that canonicalise to one ALID therefore take the answer of the
  one that sorts first, not of the one that appears first in a file. The one
  exception is a routing key that its sources name differently, below.
- A GWAS-SSF source, read directly or through a Column Map, names a variant by
  the first of its `rsid` and `variant_id` cells that names an rs identifier,
  normalised before any name is compared (issue #306): a `;`-separated list
  names its first item that begins `rs`, and an rs identifier ends at its first
  `:`, so the compound `rsN:pos:a:b` names `rsN`. A cell with no such item names
  nothing. Harmonised GWAS Catalog files write one name both ways —
  `rs199633771:13122834:C:T` in one Analysis and `rs199633771` in another for
  the same variant — and the normalisation makes them one name. The GWAS-VCF
  reader's `ID` and the FinnGen reader's first comma-separated `rsids` item are
  read as before.
- A routing key spells a coordinate's alleles upper-cased, as identity does
  (above), so source coordinates spelt in different case are one stored
  variant on every build. Every build that harvests — a two-pass build, or a
  single-pass build whose reference names no variants — compares the names
  those spellings carry, by one rule, and so does Variant Reference extraction
  (issue #379), and so do `build-ragged-ssf` and `build-dense` over the rows
  they admit: when
  their sources name it with different (normalised) rsids, nothing in the
  sources says which is right, and `build-hybrid --on-rsid-conflict` decides
  (issue #306); `build-dense`, `build-dense-vcf`, `build-ragged-ssf` and
  `extract-variant-reference` have no such option and always refuse. Which
  source is listed first therefore never decides such a name. Under
  `build-hybrid`, `refuse`, the
  default, fails the build and names the routing key and both names. `drop` gives **no
  rsid** to every stored variant such a key routes to, over the build's final
  combined routing — even when a second routing key reaches the same variant
  with a name of its own (the same site reported in the other allele order),
  because the variant's sources still disagree on its name. (A variant whose
  routing keys are each named consistently, but differently from each other, is
  reached by no disputed key and keeps the first name, by the rule above.) The
  variant is
  written with `rsid` `.` and left out of the rsid search index, exactly as a
  variant no source names: a lookup by any of its names finds nothing, and
  lookups by ALID and position find the variant and all of its associations.
  Either way the build's JSON summary carries `rsid_conflicts`: the `policy`;
  `n_keys`, the number of such routing keys among the harvested sites, stored or
  not; `n_variants`, the number of stored variants they reach, which `drop`
  leaves unnamed; and `sample`, the first 20 keys in genomic order, each with
  its distinct names in `(rank, site)` order. A build that compared names and
  found none disputed — even one whose sources name nothing — reports `0` and
  `0`. `n_keys` and `n_variants` are `null`, never `0`, for a build that
  compared no names across sources: one whose reference names its variants. A
  checkpointed build records the policy and the counts, and resuming it under
  the other policy is refused. A resume past the fold does not harvest again, so
  one whose recorded counts are missing is refused too, unless its checkpoint
  predates the option (records no `on_rsid_conflict`); its counts are then
  `null`.
- `build-ragged-ssf` harvests only the rows it admits, in Manifest Row order
  and file order, and gives a variant the first non-empty rsid among them, by
  the rule above (issue #400). A row that names nothing gives way to a later
  row that names the variant, whichever spelling either row uses.
- `build-dense` harvests only the rows Association Admission keeps, in
  manifest row order and file order, and gives a variant the first non-empty
  rsid among them, by the rule above (issue #379). It compares the spellings
  each row's `ReaderBatch` carries, and refuses a disputed name as
  `build-dense-vcf` does.
- A `build-ragged-besd` file set lists a variant once, and two of its rows
  that canonicalise to one variant are both dropped, with their associations,
  so no two names ever meet there.
- A single-pass build given `--variant-reference` MUST NOT write a `rsid`
  column blank simply because the reference it was given is a plain ALID list.
  When the reference names none of its variants, the build runs the same Pass 1
  harvest the two-pass build runs for its candidates and their `(rank, site)`
  order, keys those candidates with **exactly the key normalisation the build's
  own association routing uses** (alleles upper-cased, allele order kept),
  and then rekeys
  them **once** over **one combined site → ALID routing** — the reference's own
  source keys, plus a Hybrid build's fold for off-reference rows — so a name
  always lands on the ALID its association lands on and the global first
  candidate in `(rank, site)` order wins, whichever partition routed it. Where
  Pass 1's own liftover would have chosen a different ALID, the reference wins
  and the disagreement is logged. When the reference carries its own rsids (a
  full `*.variant-ref.tsv.gz` artifact or a Store Variant Table), it is the axis
  authority and its names are used as given; a variant the reference does not
  name is then written with no rsid, even when a source names it, and the build
  warns with counts of the rows it leaves blank (the reference's own unnamed
  rows and the fold-discovered Overflow rows separately). A reference that
  already names rsids therefore predates this contract, and no rule below is
  claimed for that path — an artifact extracted from the same sources names
  every one of them, which is the supported way to keep a reference-named
  axis and the sources' identifiers together.
- For a store whose reference names no rsids, the resulting names are identical
  to the two-pass build's **for every variant both axes carry**. The axes
  themselves need not be identical, and one difference is expected: the
  single-pass axis is the reference plus the off-reference variants its sources
  actually observe, while a two-pass `--reference-panel` axis also keeps a
  source variant that has no usable association anywhere. Such a variant is
  absent from the single-pass release rather than present under a wrong name,
  and both releases answer alike every query the two axes share.
- A build that harvests (that is, a build whose reference names none of its
  variants, or a two-pass build) MUST fail rather than publish a variant table
  that disagrees with the rsids the sources named. Two checks run before
  publication: the resolved ALID → rsid map is compared exactly with an
  independently computed expectation — the raw harvest candidates walked
  through the build's own key function over the *same final combined* routing,
  first non-empty per ALID, and under `--on-rsid-conflict drop` with every ALID
  that a routing key it finds named differently reaches expecting no name — so a
  wrong value, a missing entry, a key-normalisation collapse that keeps the wrong
  name, a disputed variant left named, or an extra entry fails;
  and the written table is read back row for row against that map, so a stale
  map or a table lost in the write fails too. Neither check runs on the
  reference-named path above. A release whose sources genuinely name no variants
  is valid, and builds normally — neither check can fire for it.

Every Store Release assigns compact Store-local Variant Indices. Variant Indices MUST NOT be assumed stable across releases or stores.

Dense Observed-Only releases use a tabix-backed Store Variant Table:

```text
variants.tsv.gz
variants.tsv.gz.tbi
variant_offsets.npy         (0.2 and 0.1)
variant_alid_utf8.npy       (from 0.3.0)
variant_alid_offsets.npy    (from 0.3.0)
variant_alid_keys.npy       (from 0.3.0)
variant_alid_order.npy      (from 0.3.0)
variant_position.npy                     (from 0.3.0)
variant_position_chromosomes.npy         (from 0.3.0)
variant_position_chromosome_offsets.npy  (from 0.3.0)
variant_source_alid_state.npy            (from 0.3.0)
variant_source_alid_utf8.npy             (from 0.3.0)
variant_source_alid_offsets.npy          (from 0.3.0)
variant_alid_bytes.npy      (0.2 and 0.1)
variant_alid_rows.npy       (0.2 and 0.1)
variant_rsid_bytes.npy
variant_rsid_rows.npy
```

The `variants.tsv.gz` table MUST contain one row per Store-local Variant Index,
sorted by chromosome, position, effect allele, other allele, and variant index.
The v0.1 dense column contract is:

```text
chromosome
position
variant_index
effect_allele
other_allele
alid
rsid
```

`variants.tsv.gz.tbi` MUST index chromosome and position for genomic range and
single-position lookup. In the 0.2 and 0.1 series `variant_offsets.npy` MUST
contain one fixed-width integer offset per variant row so row-index
materialisation does not require a large SQL variant table; a 0.3.0 release MUST
NOT carry it.

**From 0.3.0 the Variant Table is a convenience** (issue #469, ADR 0102, ADR 0105
§7). No query reads `variants.tsv.gz` or its `.tbi`, and none loads pysam: a row's
ALID is the ALID sidecar's, its chromosome, position and alleles are its ALID's,
its rsID is the rsID index's, its `source_alid` the `source_alid` sidecar's (#470),
and the variant count is the ALID sidecar's rows.
`variants_table()` and resolved rows with variant info are answered so, and give
what the 0.2 series gives from the table, column by column: a row the table gives no
rsID (`.`) has none (`None` in `variants_table()`, `.` in a resolved row), and a
cell naming several (`rs1;rs2`) is that cell, as the table spells it, because the
rsID index holds each row's cell whole. To name a row's rsID the reader inverts the
rsID index: it scans the index's rows for up to 32 rows asked, and otherwise inverts
it once, one `int32` per row. Since the reader takes a row's rsID from the index
alone, the index MUST name every row by the rsID the table gives it and no other,
which `variant_table.rsid_rows` (§20.0) holds a release to; a writer refuses an rsID
wider than the index's 24-byte slot (`UnindexableRsidError`) rather than leave it in
the table and out of every answer. A reader refuses a 0.3.0 release without the
rsID index (`MissingRsidIndex`), rather than read every row as naming none.

The table and its `.tbi` still ship, written with htslib, for tabix, bedtools and R.
A lost or stale `.tbi` is rebuilt from the table, with either of:

```text
tabix -s1 -b2 -e2 -c'#' variants.tsv.gz
Rsamtools::indexTabix("variants.tsv.gz", seq = 1, start = 2, end = 2, comment = "#")
```

Both were run on OGS-00007's table (tabix from htslib, Rsamtools 2.28.0). Each index
decompresses to the bytes of the shipped one, and answers all 170,943 positions alike.

**The ALID sidecar** (format 0.3.0, issue #467, ADR 0105). Four plain `.npy`
files, each memory-mappable and read with numpy alone, name every row's ALID and
find every ALID's row:

| file | dtype | length | holds |
|---|---|---|---|
| `variant_alid_utf8.npy` | `uint8` | total ALID bytes | every row's ALID, UTF-8, concatenated in row order |
| `variant_alid_offsets.npy` | `<u8` | rows + 1 | row `i`'s ALID is `utf8[offsets[i]:offsets[i+1]]`; `offsets[0]` is 0, each later one is greater than the one before (no ALID is empty), and the last is the byte array's length |
| `variant_alid_keys.npy` | `\|S24` | rows | each ALID's first 24 bytes (all of it when shorter), in the order of the full ALID bytes |
| `variant_alid_order.npy` | `<i4` | rows | the row each key belongs to: a permutation of `0..rows-1` |

A row's ALID is two reads; nothing inverts an index to name a row. An ALID's row is
a binary search of the keys for its first 24 bytes. An ALID shorter than 24 bytes
is its key, and the one stored ALID with that key is its match; a longer one is
compared on its full bytes with each stored ALID that shares the key, which run in
full-byte order. Every ALID is indexed, however long, and no ALID names two rows.
`variant_table.alid_sidecar` (§20.0) holds a release to this. The 0.2 series'
`variant_alid_bytes.npy`/`variant_alid_rows.npy` (`|S32`, sorted, leaving out every
ALID wider than 32 bytes) are not written from 0.3.0, and a 0.3.0 release that
carries them fails its closed envelope; a 0.2 release keeps them, and a reader
reads them there. A reader opens the index a release's `format_version` carries and no
other, whatever other files lie beside it, and refuses a release missing it (ADR 0105 §5).

**The position sidecar** (format 0.3.0, issue #468, ADR 0105 §6). Three plain
`.npy` files, each memory-mappable and read with numpy alone, give every row's
position and each chromosome's rows:

| file | dtype | length | holds |
|---|---|---|---|
| `variant_position.npy` | `<u4` | rows | every row's position, in row order; each is at least 1 |
| `variant_position_chromosomes.npy` | `\|S<n>` | chromosomes | each chromosome the release holds, once, as the table spells it, in the order its rows come |
| `variant_position_chromosome_offsets.npy` | `<u8` | chromosomes + 1 | chromosome `k`'s rows are `offsets[k]:offsets[k+1]`; `offsets[0]` is 0, each later one is greater than the one before (no chromosome is empty), and the last is the row count |

The rows are the table's, in its order, so the chromosomes run in the canonical
chromosome order (`1`-`22`, `X`, `Y`, `MT`, then any other label by its text) and
within one chromosome the positions never fall. A writer refuses rows that are not
so, and `variant_table.position_sidecar` (§20.0) holds a release to it: the sidecar
places each row at the chromosome and position the table gives it.

**How a range is answered.** A genomic range is a chromosome and an inclusive
`[start, end]`, and its answer is every row on that chromosome at a position in
it, ascending. The chromosome is normalised as an ALID's is (`chr1` is `1`, `23`
is `X`). From 0.3.0 the reader finds the chromosome's slice of the position sidecar
and binary-searches it twice: the first position at or after `start`, and the
first after `end`. The rows between are the answer, read without the Variant Table,
its tabix index or pysam. A chromosome the release lacks, or an `end` before
`start`, answers no rows. A 0.2 or 0.1 release answers the same range by a tabix
fetch of `variants.tsv.gz` (`fetch(chromosome, max(0, start - 1), end)`), and the
two answer every range identically (ADR 0105 §6). A Hybrid answers from its
shared axis and its Dense Component's, each by its own sidecar. A reader opens the
position sidecar when the release's `format_version` carries it, never because the
files are present, and refuses a 0.3.0 release missing it rather than reading
the range through tabix. It also refuses a sidecar whose chromosomes cannot slice
its rows: offsets that do not number the chromosomes plus one, a chromosome named
twice, or a label that is not UTF-8. A sidecar like that would answer one
chromosome's ranges from another's rows, or from none.

**The `source_alid` sidecar** (format 0.3.0, issue #470, ADR 0105 §8). A row's
`source_alid` is the ALID its source spelt it by, on the source's Reference Assembly:
for a lifted row the pre-liftover ALID, for a row its source already placed on the
release's assembly its own ALID. A row two source variants collided onto (§4 above,
#85) has none, and so has a row Reference Completion added from the panel, which no
source observed. Three plain `.npy` files, memory-mappable and read with numpy
alone, hold it:

| file | dtype | length | holds |
|---|---|---|---|
| `variant_source_alid_state.npy` | `\|u1` | rows | each row's state, in row order: 0, it has no `source_alid`; 1, its `source_alid` is its own ALID, which the ALID sidecar holds; 2, it is another ALID, held below |
| `variant_source_alid_utf8.npy` | `uint8` | total bytes | each state-2 row's `source_alid`, UTF-8, concatenated in row order |
| `variant_source_alid_offsets.npy` | `<u8` | state-2 rows + 1 | the `k`-th state-2 row's is `utf8[offsets[k]:offsets[k+1]]`; `offsets[0]` is 0, each later one is greater than the one before (no held value is empty), and the last is the byte array's length |

A row's state is its `source_alid` compared with its ALID, by the writer. A state-2
row's text is found by its rank among the state-2 rows: the reader gathers their row
numbers once from the state and binary-searches them. Text is held for state-2 rows
alone, so a release built on its own assembly, every row of which names its own ALID,
holds one byte a row and does not repeat the ALID sidecar's text (ADR 0105 §8). A
value is stored whole, however long (an indel's runs past 100 bytes). It holds no
tab, newline or NUL and is never `.`, the table's blank: the writer refuses such a
value, which the table would read otherwise than the sidecar. Nothing searches the
text, so it has no sort keys; the source-fidelity join (`validate --source`) finds a
state-1 row through the ALID index and scans the text for the rest; a release whose
every state is 0 holds nothing to join on, and the join says so, as for a table without
the column. On a release whose manifest records no lift, `validate --source` then lifts
the samples itself; on one that records a lift, `variant_table.source_alid` (§20.0)
fails first and the source-fidelity check is not run. Each row's state
and text equal the table's `source_alid` column row for row, a blank (`.`) there
being state 0, which `variant_table.source_alid_sidecar` (§20.0) holds a release
to. `variants_table()` gives it as `source_alid` (`None` where empty), and a resolved
row with variant info as `source_alid` (`.` where empty), on every format: a 0.2
release reads it from its table, and a table written before the column (seven
fields) gives none. A reader refuses a 0.3.0 release missing the sidecar, rather
than read every row as naming none. A Hybrid carries it at its root only: a 0.3.0 Dense
Component's rows give their shared rows' `source_alid` (§16). A reader refuses one
whose offsets do not start at 0 and end at the byte array's length, and, when it first
reads a value, one with a state outside 0-2 or whose offsets do not number the state-2
rows plus one.

Long alleles MAY use deterministic hashed ALIDs as compact identifiers, but the complete normalised alleles MUST be retained once per variant so exact export and validation do not depend on an irreversible hash.

Reference-Completed releases MUST expose Reference Panel Membership as variant metadata, distinguishing Reference Variant Set variants from observed off-panel variants.

## 5. Allele orientation and signed statistics

Every association MUST be normalised to the Store's canonical allele orientation.

If the source effect allele is not canonical `A1`, the builder MUST swap orientation and negate signed statistics. Z is signed and carries effect direction. SE is non-negative.

A source row is oriented in the source's declared assembly. When a lift onto the release's assembly makes the other allele `A1` (a reverse-strand chain block), the row is re-oriented by the same rule: its z is negated again and its effect-allele frequency complemented again. Every layout applies this one model.

Derived beta is:

```text
beta = z * se
```

## 6. Stored statistics

OpenGWASDB stores the canonical statistic pair:

```text
z
se
```

Requirements:

- `z` is signed.
- `se` is non-negative.
- `se` is on the same Stored Effect Scale as beta.
- beta is queryable but derived from `z * se`.
- p-value is queryable but derived from Z. A source's own p-value is never
  stored; where it is not the Wald p of the source's beta/se, a query returns a
  p the source did not publish. The known circumstances, and what the engine
  does about each, are in [statistic-disagreement.md](../statistic-disagreement.md).
- INFO and sample size MUST NOT be required to reconstruct beta, SE, Z, or
  p-value. EAF is not required to reconstruct beta, Z, or p-value, and is
  not required to reconstruct a legacy or floating-point `se`. A
  residual-coded `se` (§6a) **is** unreadable without the EAF its cells were
  coded against — the observed EAF for observed cells, the Reference EAF for
  imputed cells.

Statistic planes are not required to be floating point, and `z` is not. Their
physical encoding is declared per release, in `manifest.json` (§6a), and is
read from that declaration rather than inferred from a dtype.

## 6a. Statistic encodings

Every Store Release MUST declare an `encoding` object in `manifest.json`,
stating `version` 3 and a plan for each of `z`, `se` and `eaf` -- and, for a
Ragged release carrying per-association sample sizes, `n`:

```json
"encoding": {
  "version": 3,
  "z": {"kind": "int16_fixed", "scale": 1024},
  "se": {"kind": "int8_residual", "residual_range": 1.0},
  "eaf": {"kind": "int8_residual", "residual_range": 0.5}
}
```

- The declaration is authoritative. A reader decodes what the manifest says;
  validation checks that the arrays agree with it (§20).
- A reader meeting a `kind` it does not implement MUST reject the release
  (§21), not guess and not fall back.
- **The block is required, and there is no reading of its absence.** A release
  that declares no `encoding`, or a block that declares no `version` or no
  `eaf` plan, MUST be rejected. Every such absence used to date a release to a
  pre-reset format — "no block" meant `float16` throughout, "no `eaf`" meant
  ADR 0036's optional plane — and those formats are no longer read (ADR 0041),
  so the inference has nothing left to infer and would only let a malformed
  release of *this* format be decoded as something it is not.
- **`version` MUST be 3.** It identifies the shape of the block, not the store
  format, and is not reset alongside `format_version`: blocks stamped 1 and 2
  were real shapes, and reusing one of those numbers for a third shape would
  recreate the collision the format reset exists to avoid (ADR 0041 §3).
- Issue #157's rule that a release may declare only kinds its own
  `format_version` admits is retired with the versions it gated: one readable
  format admits every kind its parser implements.

**`z` — `int16` fixed point plus an exact overflow table** (ADR 0037 §1). The
stored code is `round(z × scale)`, `scale` = 1024 by default, with two
reserved codes:

| code | meaning |
|---|---|
| `-32768` | missing — decodes to NaN, and the paired `se` MUST also be missing (§15) |
| `-32767` | out of range — the exact `float32` is in the plane's overflow table |
| `-32766 … 32767` | `z × scale`, i.e. −31.998046875 … +31.9990234375 |

The representable interval is stated as exact endpoints rather than "±32":
signed fixed point is asymmetric, and reserving codes makes it more so.

A value outside that interval is **not** clipped and does **not** fail the
build — genuine associations reach |z| = 137.5. It is held exactly, in two
parallel arrays beside its plane:

```text
z_overflow_index   int64, sorted, unique — the cell's flat position in its plane
z_overflow_value   float32               — the exact z
```

A cell's flat position is `variant_index × n_analyses + analysis_index` for a
Dense grid, and the association's ordinal in the concatenated CSR arrays for a
Ragged sequence. The arrays are present whenever `z` is `int16_fixed`, even
when empty. Every out-of-range cell MUST have an entry and the table MUST NOT
describe any other cell (§20).

A non-finite `z` that is not a recorded absence (±inf, or a malformed
statistic) is neither a value nor an absence, and no encoding of it is honest.
A build never stores one: Association Admission drops the source row and logs
it (`z_nonfinite`, ADR 0072), and a writer handed one refuses it.

**`se` — `float16` or `int8_residual`.** Residual coding predicts
`log(SE) = intercept + slope × log(2 × EAF × (1 − EAF))` using decoded,
quantised EAF and two `float32` coefficients per Analysis in
`se_coefficients[n_analyses, 2]`. Codes `-128` and `-127` mean missing and
exact exception; `-126…127` carry a residual at `step = residual_range / 127`.
Exact values are stored in sorted parallel `se_exception_index` (`int64`) and
`se_exception_value` (`float32`) arrays, present even when empty. Dense keys
are `row × n_analyses + column`; Ragged keys are CSR ordinals.

Builders try ranges ±0.5, ±1, and ±2 in order, accepting one only when every
finite SE has decodable EAF, exact exceptions are at most 2% **in every
Analysis** — not pooled over the plane — ordinary-cell relative error is at
most 1%, and measured compressed bytes decrease after codes, coefficients, and
side tables are charged. Otherwise the entire plane is `float16`. A release
carrying an `n` plane keeps `se` in `float16` unconditionally: the residual
model has one intercept per Analysis and so assumes one N per Analysis, and
with per-pair N spanning 2.5 decades it measured a 0.79% worst-case SE error on
eQTLGen against `float16`'s 0.049% (ADR 0067 §4). A reader MUST reject an
`encoding` block that declares `n` beside `int8_residual`, and validation
names it (§20). Zero SE,
non-finite predictions, and out-of-range residuals are exact exceptions, never
clips.

Under either plan no SE above 65,504 -- the largest a `float16` plane holds --
is stored (§15, issue #338): from format 0.2.3 such an association is left out
before the plan is measured, so it plays no part in choosing the range or
fitting `se_coefficients`, and an SE encoder handed one refuses it rather than
narrow it to `+inf` or hold it as an exact exception. A residual exception
table therefore holds no value above 65,504. Nor does a code decode above it.
A code is the nearest step, so a kept SE at or near 65,504 could read up to half
a step above itself (65,520 from 65,504 under a 0.5 range); and a reader predicts
from the frequency it decodes, narrowed to `float32`, which under a steep model
moves the prediction by whole units, so an SE far below the bound could read
above it too (10,000 as 11,806,119 under a slope of 1e9). The encoder decodes
every kept cell's code as a reader will and holds any that would read above
65,504 as an exact exception. That is one decision, with the residual-range and
exact-carry rules (`se_residual_codes`): the candidate measurement, the Dense
rewrite's exception count and the encoder all make it, so the 2% cap below and
the side table's size count these exceptions too.

**Residual SE is all-or-nothing per component, and that verdict is reached
before the fit and the measurements.** One Analysis whose cells carry a finite
SE and no frequency, or from which the fit yields no coefficients — fewer than
two usable cells, or a frequency spread with no variation — leaves the whole
plane, every other Analysis included, in `float16`. This is a property of the
format rather than of any release: the plan declares one encoding for the
entire plane and every reader decodes every cell against it. A build therefore
decides it from one bounded streaming pass over both components, before it fits
a coefficient or measures a candidate, so a plane that cannot be coded never
pays for either; that pass reports which trigger fired and how many Analyses
were responsible. Coding the Analyses that can be fitted and falling back only
for those that cannot would need a representation for "this Analysis is coded
differently", which is format surface with its own version story (ADR 0037,
ADR 0041) and is deliberately not built (issue #229).

**Every cell carrying a standard error owes a finite EAF, exact exceptions
included.** A residual plane is defined over a store whose frequencies are
complete where its standard errors are, and encoding refuses a finite `SE`
whose cell has no frequency rather than absorbing it as an exception — a store
only this package could read is worse than one it declines to write. Nothing
upstream produces such a cell: an imputed standard error is derived from the
panel frequency, so a cell without one gets no standard error either.

The 2% budget is **per Analysis and pooled across a Hybrid store's two
components**, not met by each component separately. What it bounds is storage:
an exact exception stores the source value exactly, so a high exception rate
costs side-table bytes and no accuracy. The quantity that bounds those bytes
for an Analysis is its share over all of its cells, wherever they live. Hybrid
components share one decision, and each must save bytes on its own.

**Reference Completion keeps its source's SE model** (ADR 0078, issue #301).
A completed release declares its source's `kind` and `residual_range` (ADR
0038 §4), and every cell it holds is coded against the source's
`se_coefficients`, which it carries unchanged. Dense and Hybrid completion
patch the source's plane, so its codes carry over. Ragged completion rewrites
its whole CSR plane from decoded values, and it never refits the model: a
model fitted to the completed rows decodes each observed code to a value the
source never held. Each observed cell is held exactly: its code decodes to the
source's value, and one whose code would decode to anything else is an exact
exception. For example, a source exception whose `float32` value rounds back
inside the range stays an exception. So the source's exceptions carry over
with their values. An imputed cell is coded against the same model, and one
whose residual falls outside the range is an exact exception, like any other.

The 2% budget is the criterion a build uses to choose its range, and
completion does not choose again. Imputed cells may take an Analysis past
2%. Completion never brings it back under by refitting or by writing
`float16`: either would change observed values that §12 says completion
preserves. Instead a Ragged completion records each Analysis's share in
`manifest.json`'s `provenance.completion.se_exceptions` and logs a warning
naming every Analysis above the budget. `validate` does not check the budget:
it bounds side-table bytes, not accuracy. The block holds:

- `budget`: 0.02;
- `analyses`: one entry per Analysis, in `analyses.tsv` order, with
  `analysis_id`, `n_se` (its cells carrying an SE), `n_exceptions`,
  `n_imputed_se`, `n_imputed_exceptions` and `exception_rate`
  (`n_exceptions / n_se`, null for an Analysis with no SE);
- `over_budget`: the ids whose rate exceeds the budget.

It is absent when SE is `float16`, which has no exceptions.

**`eaf` — one of three kinds** (ADR 0037 §2). EAF's *semantics* are unchanged by
the encoding: it is still per (variant, Analysis), still oriented to the stored
effect allele (§5, §9.1), still declared per Analysis by `eaf_scope` (§9).

| `kind` | what the plane holds | written by |
|---|---|---|
| `absent` | nothing — the release has no `eaf` array | yes |
| `float32` | ADR 0036's exact plane | yes |
| `int8_residual` | a quantised logit residual against a per-variant baseline | yes |

There is no present-or-absent kind. ADR 0036's `float32_optional` — where the
plane's *presence* rather than the plan said whether a release had frequencies
— named the contract of a format this build no longer reads, and was deleted
with it (ADR 0041). A release with no frequencies declares `absent`.

**The residual coding.** Three arrays beside the plane, all in the same group:

```text
eaf                   int8    — the quantised residual, one per cell
eaf_baseline          float32 — one per variant of *this component's* axis
eaf_exception_index   int64, sorted, unique — flat position in the plane
eaf_exception_value   float32 — the exact frequency
```

Per-variant frequency arrays (`eaf_baseline` and `eaf_reference`) are chunked
along the variant axis, no more coarsely than the component plane they serve
and never above 200,000 variants per chunk. A multi-chunk-sized variant axis
stored as one chunk is invalid: point queries must not decompress the full
per-variant array.

The transform is the **logit**, `logit(f) = log(f / (1 − f))`, and the stored
code is `round((logit(f) − logit(b)) / step)` where `b` is the variant's
`eaf_baseline` and `step = residual_range / 127`. The logit, and not `log(f)`,
because a residual error of `d` moves `f` by a relative `(1 − f)·d` and `1 − f`
by a relative `f·d`: neither the effect allele frequency nor the minor allele
frequency a user filters on can be wrong by more than `d`. `log(f)` is blind to
the minor side, which for a frequency near 1 is the only side anyone reads.
Measured on real data the two transforms leave residuals of the same width
(FinnGen chr1, 8 endpoints: sd 0.0170 against 0.0169), so the choice costs
nothing.

Two of the 256 codes are reserved, leaving **254** levels:

| code | meaning |
|---|---|
| `-128` | this Analysis reports no EAF at this cell — decodes to NaN |
| `-127` | exception — the exact `float32` is in the plane's exception table |
| `-126 … 127` | `round((logit(f) − logit(b)) / step)` |

so the representable residual interval is `[−126·step, +127·step]`, stated as
exact endpoints for the same reason `z`'s is. A cell that is not an exception
round-trips to within **half a step**, which is a function of the declared
range and must be quoted per range:

| `residual_range` | step (logit) | worst-case relative error |
|---|---|---|
| 0.5 | 0.003937 | **0.197%** |
| 1.0 | 0.007874 | 0.394% |
| 2.0 | 0.015748 | 0.787% |

Three kinds of cell are **exceptions**, held exactly rather than approximated:
a residual outside the interval; a frequency of exactly 0 or 1, which has no
logit; and a cell at a variant with no usable baseline. The exception table has
the same shape and the same rules as `z`'s overflow table: present whenever
`eaf` is `int8_residual`, even when empty; every exception cell MUST have an
entry and the table MUST NOT describe any other cell (§20).

`eaf_baseline[v]` is the median, taken in logit space, of the frequencies the
release's Analyses report at variant `v` that lie strictly inside `(0, 1)`. The
median of an even count is the mean of the two central logits. A variant at
which no Analysis reports such a frequency has a NaN baseline, and every
EAF-bearing cell at it is an exception — there is no honest baseline to code
against, and a substituted one (0.5, say, or a store-wide mean) is exactly the
plausible-looking default this format refuses.

A build MUST fail on a value outside `[0, 1]`: it is not a frequency.

**Which kind a build writes is measured, not inferred from the layout.** The
builder measures the residual spread over its own data and picks the smallest
`residual_range` whose exception fraction is within budget, then compares the
resulting byte total against the `float32` plane and writes `float32` when the
residual coding would not be smaller. A store with roughly one EAF-bearing cell
per variant pays more for the per-variant baseline than the `int8` cell saves,
and nothing stops a Dense manifest spanning several cohorts — a store that
assumed otherwise would clip silently against a range chosen for data it does
not hold.

**Every component writes its own baseline and its own exception table**, against
its own variant axis. A Hybrid release has two: its Dense Component's is
panel-sized, its Ragged Overflow's covers the shared union table. Both
components share one `kind` and one `residual_range`, because they partition one
Analysis's associations and a result assembled from both must be coherent.

**`eaf_reference` — the panel frequency for imputed cells** (ADR 0037 §4). An
imputed cell's EAF *is* the LD Reference Panel's, and it is identical for every
Analysis imputed at that variant, so it is a per-variant constant rather than
per-cell data:

```text
eaf_reference   float32 — one per variant of this component's axis
```

declared by `"reference": true` in the `eaf` block. Which cells it describes is
already recorded, by Association Status (§9, §15): a reader substitutes it on
imputed cells and on no others. It is per **component**, not per release — a
Hybrid release's Dense Component has imputed cells where its Ragged Overflow
does not, and each declares its own plan in its own manifest. A component
declaring it MUST carry the array and an imputed mask; a component carrying the
array MUST declare it.

**An observed cell whose source reported no EAF stays NaN.** It does not fall
back to the panel. FinnGen's frequencies differ from the EUR panel by up to
3000× (max log-residual 8.07, the Finnish founder effect), so substituting a
panel frequency for a missing cohort one would hand a user a plausible number
that is wrong by three orders of magnitude, precisely for the rare variants
they filter on.

`eaf_reference` is declared independently of the plane, `absent` included. A
source whose Analyses reported no frequency at all still gains imputed cells
when it is completed, and those cells have the panel's frequency: such a release
carries `eaf_reference`, no `eaf` array, and reads NaN on every observed cell.
Its Analyses that gained imputed cells declare `eaf_scope=association`, which is
a statement about the arrays and not a contradiction of them — a release holding
only the panel's frequencies still holds frequencies.

The panel may itself declare none. An LD Reference Panel is supplied for
imputation and its frequencies are optional; a completion against one that has
none carries no `eaf_reference` and leaves imputed cells NaN, rather than
failing. In this pipeline that case is vacuous, and deliberately so: an imputed
`se` is scaled by the panel's heterozygosity, so a panel with no frequencies
imputes nothing at all rather than deriving an `se` from a substituted one.
What such a completion protects is the release's *own* frequencies — the run
succeeds and the observed plane survives it. A reader must still handle NaN
here, because the rule is about the panel and not about how any one pipeline
derives `se`.

Constraint: **one LD Reference Panel per completed release**. True of the
completion pipeline today, but load-bearing here, so it is recorded in
`manifest.json` rather than left implicit: `provenance.completion` names the
`ld_panel_id` and `ancestry` the release was completed against. A Hybrid
release records it at the top level as well as inside its Dense Component —
the component is where the imputation happened, but the release is what a
reader opens.

**`n` — the optional per-association sample size** (ADR 0067). A Ragged
release MAY carry a fifth CSR plane, `data.zarr/ragged/n`, and declares it as
`"n": {"kind": "uint32"}`. A release without the plane declares **no** `n` key
at all: unlike `eaf`, there is no `absent` kind, and a block without the key
is every release written before the plane existed and every release since
that was given no sample-size input. A reader meeting an `n` kind it does not
implement MUST reject the release (§21).

| code | meaning |
|---|---|
| `4294967295` (`2³² − 1`) | missing — the build was given no N for this pair; decodes to NaN |
| `1 … 4294967294` | that many participants |
| `0` | invalid — never written; a release holding one fails validation |

`n` has no side table: its codes are its values. It is written only by
Ragged builds, never by a Dense build or a Hybrid component, and is decoded to
`float64` (exact for every code) with NaN for missing.

Derived artifacts that hold their own copies of `z` — top-hit indexes (§18)
and the Rho Matrix — remain decoded `float32` and are explicitly rebuildable
from the encoded planes. A top-hit index's `z` MUST equal what a query reads
back from the plane, so candidate selection is done on the **stored** value.

## 7. Effect scale

Each Analysis MUST declare Stored Effect Scale from the controlled vocabulary:

```text
sd
log_or
log_hazard
```

There is no `other`, `unknown`, or original-units Stored Effect Scale in v0.1. Unsupported stored scales MUST fail ingestion until the vocabulary is deliberately extended.

An Analysis whose Stored Effect Scale is `sd` MUST have an `original_sd_method` that is a rescaling method (below) or `declared_standardised`: SD Units are claimed only for statistics that were divided by a phenotype SD or arrived already standardised. A builder refuses a manifest row that says otherwise, naming the Analysis, and `validate` fails a Store that holds one (`analyses.sd_scale_standardised`, §20.0), at every `format_version`. A blank `original_sd_method` beside a blank Stored Effect Scale is not a scale and not the vocabulary's missing value: it is an absent declaration, "not standardised, scale unknown" (ADR 0084), and no reader may treat it as SD Units. OGS-00001 and OGS-00002 hold it. A builder does not write it from a manifest that names a scale; `build-ragged-besd` reads a blank cell as absent and builds it, and `build-ragged-ssf` refuses a row with no scale.

`build-ragged-ssf` records `provenance.stored_effect_scale` in `manifest.json` as the scale its rows declare: the one value when they agree, else the distinct values sorted and comma-joined (`log_or,sd`). The per-Analysis scale is `analyses.tsv`'s.

Original Effect Scale MAY be recorded as free-text provenance. For continuous traits, builders SHOULD store effects in SD Units when phenotype standard deviation is available or can be derived with acceptable provenance, by rescaling the source statistics with a per-study phenotype SD rather than reconstructing them from Z, N, and allele frequency (ADR 0029). The method used to obtain that SD (`original_sd_method`) and a dispersion diagnostic over its supporting evidence MUST be recorded as Analytical Metadata (§7a).

Every builder that reads a build manifest applies that rescaling, and applies it
identically: an `original_sd_method` in a tier that carries an SD magnitude
(`source_provided`, `estimated_from_source_maf`,
`estimated_from_reference_maf`, `estimated_from_beta_distribution`) divides each
of that Analysis's standard errors by `original_sd` before the association is
encoded, in `build-dense`, `build-dense-vcf`, `build-hybrid` (its Dense
Component, its Overflow and its off-reference associations),
`build-ragged-besd` and `build-ragged-ssf` alike, and records that
`original_sd` in `analyses.tsv` (§7a). The divide is one module's, applied where
a writer judges what a Store holds (`storable`, ADR 0084): a builder hands each
Analysis's SD with its source's SEs, and a writer handing SEs a Store already
holds — a Reference Completion, an encode — hands none: an SE MUST be divided
exactly once. A builder judges `original_sd_method` as the manifest spells it,
and refuses a spelling outside the vocabulary — a padded `' source_provided '`
included — in every builder alike, rather than build a Release that records it
and then fails validation. `z` is scale-free and MUST be stored as the source gave it, so
dividing the SE never moves it. In every one of them a magnitude that is
missing, non-finite or not positive refuses the build, naming the Analysis: an
`inf` SD would store every SE as `0`, and `0` or a negative SD is no divisor. A
tier that carries no magnitude (`declared_standardised`, `binary_trait`)
divides by nothing and is refused if a magnitude is supplied beside it, and
`unavailable` is refused because nothing may be standardised without an SD that
was established (issue #18, #366).

## 7a. Analytical Metadata, Attribution Metadata, and `analyses.tsv`

A Store Release MUST carry its own Analytical Metadata — metadata affecting the
interpretation of association statistics — and its own Attribution Metadata —
metadata establishing how an Analysis may be cited, licensed, and attributed —
so a downloaded or mirrored copy remains usable and interpretable without a
catalogue service (ADR 0030, ADR 0034). Both live entirely in `analyses.tsv`,
one row per Analysis, keyed by `analysis_index`, **identically across every
Primary Storage Layout** (ADR 0034) — Ragged is not exempt, and `index.sqlite`
MUST NOT hold a second, layout-specific per-Analysis metadata table. This
column list is a **breaking revision** of the one ADR 0030 originally
specified (ADR 0034, further narrowed by ADR 0035's retirement of `gene_id`/
`gene_name`): a Store Release built against a prior column list is not a
valid Store Release against this one, and no reader is required to accept
both.

```text
analysis_index
analysis_id
analysis_label
trait_ontology_id            (CURIE, e.g. EFO:0001073; blank when unmapped)
trait_ontology_label
tissue
context
trait_chr                    (blank for Analyses with no single genomic position)
trait_bp
stored_effect_scale
assigned_ancestry
ancestry_assignment_method
ancestry_prop_<population>   (repeated, one column per reference population)
sample_size_kind
sample_size_scope
sample_size
n_cases
n_controls
eaf_scope                    (see §9; blank or `absent` when the build stored no EAF)
original_effect_scale
original_sd
original_sd_method
original_sd_dispersion
license
publication_doi
publication_pmid
consortium
first_author
completed_against   (Reference-Completed releases only; null when unimputed)
completion_median_pearson_r   (Reference-Completed releases only)
completion_n_imputed_total
completion_n_missing_total
n_missing_se_out_of_range   (associations not stored for an SE above 65,504; required from format 0.2.3)
eaf_orientation      (see §9.1; `passed`, `failed` or `unverified`; blank only on a store built before the check existed)
eaf_orientation_r    (the observed correlation; blank when none was computed)
eaf_orientation_n    (variants the correlation was computed over)
n_hits_5e8   (count of associations at p <= 5e-8, genome-wide significant)
n_hits_5e6   (count of associations at p <= 5e-6, suggestive)
n_hits_5e4   (count of associations at p <= 5e-4, nominal)
n_loci_5e8        (Clump Leads of the 5e-8 tier; present exactly when the release declares `clumps`, §18.1)
n_unclumped_5e8   (observed 5e-8 rows its LD Store could not clump; present exactly when `n_loci_5e8` is)
```

`trait_chr`/`trait_bp` are in the Store's `reference_assembly`, as every
variant coordinate is. A builder that lifts a source's variants lifts these
with them, through the same build and chain (issue #433), for `build-ragged-besd` and `build-ragged-ssf`. A position the
chain places nowhere, or on a different chromosome, is not kept in the source's
assembly: the Analysis's `trait_chr`/`trait_bp` are left blank, and the build
records the loss outside the Store, as ADR 0072 keeps a Store's bytes
independent of its record: the printed build summary counts the Analyses and
names them, and `trait_positions_unlifted.tsv` beside the Admission record's
`admission.json` names every one (the record's reset removes it, so it always
describes the build that wrote the record). Nothing is added to the manifest. A
build whose unlifted share exceeds the variant lift's failure threshold is
refused. `build-dense-vcf` and `build-hybrid` carry no Trait position.

Every column beyond `analysis_index`/`analysis_id` MAY be blank for an
individual row when genuinely unknown or not applicable — a phenotype-level
Analysis leaves `trait_chr`/`trait_bp` blank; a Trait with no clean ontology
mapping yet leaves `trait_ontology_id`/`trait_ontology_label` blank rather
than fabricating one. `trait_ontology_id` is not required to be unique — one
Trait MAY have several Analyses (differing by cohort, ancestry, model, sample
subset, or meta-analysis) that share it, and it MAY be blank on some or all of
them. There is deliberately no other Trait-identifying column: a raw,
source-native trait identifier alongside `trait_ontology_id` was considered
and rejected (ADR 0034) as recreating the same "which column is authoritative"
ambiguity `phenotype_id` had. This extends to gene identity for gene-centric
(pQTL) Analyses: `trait_ontology_id`'s CURIE contract is polymorphic by Trait
kind, so an Ensembl gene ID (e.g. `ENSEMBL:ENSG00000152256`) belongs there and
in `trait_ontology_label` (`"Ensembl"`) rather than in dedicated `gene_id`/
`gene_name` columns, with the gene symbol carried as free text in
`analysis_label` (ADR 0035). `trait_ontology_label`'s meaning is therefore
polymorphic along with `trait_ontology_id`'s: for an EFO/MONDO CURIE it MUST
be that specific term's human-readable name; for a gene-centric CURIE, whose
human-readable name is already `analysis_label`, it instead names the
identifying vocabulary (`"Ensembl"`) rather than repeating the gene name.
`analysis_id` MUST be unique within a Store Release.

An Analysis whose `original_sd_method` carries an SD magnitude (§7) MUST record
that magnitude in `original_sd`, finite and positive: it is the SD its standard
errors were divided by, and the one value that reads them back in the source's
units. `validate` fails a row that gives such a method with an `original_sd`
that is blank, non-finite or not positive (`analyses.original_sd_recorded`,
§20.0), at every `format_version`. `build-ragged-ssf` before issue #366 wrote
exactly that row, while storing its source's standard errors undivided; OGS-00006,
OGS-00024, OGS-00025 and OGS-00026 (4,443 Analyses) are such Releases, and
`validate` fails them until they are rebuilt or repaired.

For CORE build-input manifests (stores #175), optional `info_score_threshold`,
`imputation_score_column`, `imputation_score_kind`, and
`imputation_score_provenance` are per-Analysis shared-core policy inputs. They
are not inferred from source headers. A manifest omitting all four has no INFO
filter; a literal `NaN` threshold without a mapping explicitly means unavailable
and also has no filter. A numeric threshold, including zero, MUST be finite in
`[0, 1]` and MUST accompany an exact source column name, a kind of
`imputation_info` or `imputation_r2`, independent provider evidence in
`imputation_score_provenance`, and an INFO-capable Source Reader (currently
`opengwasdb.gwas-ssf`). Partial declarations, a mapping without a numeric
threshold, malformed thresholds, and a declaration alongside `NaN` are invalid.
The declared source column must occur exactly once with the declared spelling;
the GWAS-SSF reader rejects absent, padded, or ambiguous source header columns
when it opens the file. These inputs define an ingestion policy, and a CORE
build applies it: every builder (issue #175; since #357 not the Hybrid alone,
ADR 0072) passes the declaration to the Source Reader and drops every
association the policy excludes — a usable score
strictly below a positive threshold, or a score that is missing, malformed,
non-finite or out of `[0, 1]` — before Dense/Overflow routing, before the EAF
orientation check and before the Top-Hit Counts, so nothing a declared
threshold rejected can be stored, counted or oriented. A score exactly equal to
the threshold is kept. A literal `NaN` threshold and an explicit zero drop
nothing while remaining distinct recorded states. An Analysis that declares a
score and has no usable value anywhere in its source fails the build, naming
that Analysis.

What a Hybrid build filtered and how much it dropped is recorded per Analysis
in `manifest.json`'s `provenance.info_score.analyses` (stores #175): one entry
per Analysis of the build-input manifest, in `analyses.tsv` order, each carrying
`analysis_id`, `info_score_state` (`legacy_absent`/`unavailable`/`disabled`/
`filtered`), `info_score_threshold` (null when none was declared or the score is
unavailable), `associations_observed`, `associations_retained`,
`associations_below_threshold`, `associations_missing`, `associations_malformed`,
`associations_nonfinite`, `associations_out_of_range` and
`associations_usable`. The denominator is the associations the Analysis's Source
Reader yielded after its own effect/SE admission, **not** raw source lines and
not the whole-file canonical-row counts `resolve-analyses` reports separately:
`associations_observed` = `associations_retained` +
`associations_below_threshold` + the four unusable dispositions, and
`associations_usable` = `associations_retained` + `associations_below_threshold`
under a positive threshold. The whole block MUST be absent when no
build-input row declared a policy — an absent block means the manifest declared
none, never "nothing was dropped" — so a legacy manifest's release records
exactly what it did before this filter existed. A policy may be `unavailable` or
`disabled` for some Analyses of a table and `filtered` for others; every entry
appears whenever the threshold column is present at all.

`analyses.tsv` MUST be sufficient on its own to interpret every Analysis's stored
effect scale, sample-size semantics, ancestry, and licensing/citation terms —
this supersedes the general requirement in §3 that "Analysis metadata MUST be
sufficient to interpret stored effect scales, sample-size semantics, and source
provenance," which this section makes concrete. `index.sqlite` MUST NOT
duplicate any column of `analyses.tsv`; large, fine-grained, tooling-only
evidence (such as Reference Completion Quality at LD-block-by-Analysis
granularity, §12) stays SQLite-only, with only its per-Analysis rollup
appearing in `analyses.tsv`.

`n_hits_5e8`/`n_hits_5e6`/`n_hits_5e4` are Analytical Metadata too (ADR 0032): a
signal of study power and test-statistic-inflation risk, derived at build time
from the store's own top-hit index (§18) and never recomputed at query or render
time. A store whose associations are split across more than one on-disk top-hit
index for the same Analysis (a Hybrid store's Dense Component and Ragged
Overflow Component) records the sum, since the two partition an Analysis's
associations disjointly.

`n_loci_5e8` and `n_unclumped_5e8` are Analytical Metadata beside the Top-Hit
Counts, from the release's stored Clumps (§18.1, ADR 0106, amending ADR 0032).
`n_hits_5e8` stays the raw count. `n_loci_5e8` is the number of the Analysis's
Clump Leads: rows of its clump slice whose `lead` is their own offset.
`n_unclumped_5e8` is the number of its rows marked absent (−1) or ambiguous (−3):
observed associations its LD Store could not clump. Imputed rows (−2) are in
neither, because they are not clumped by design. For an Analysis that was clumped
both are non-negative integers, 0 included, and `n_loci_5e8 + n_unclumped_5e8 ≤
n_hits_5e8`. For an Analysis that was not clumped (−4: a blank `assigned_ancestry`,
or one with no LD Store in the group's `ld_stores`) both are **blank, never 0**: a
0 would claim the Analysis has no locus. The two columns are present exactly when
the release declares `clumps` (§2): a release that does not is not clumped, and a
reader does not read its absent columns as blank. A Hybrid has one
`analyses.tsv`, at its root (§16, #472), and its two columns count both
components' rows, as `n_hits_*` does; each component's own row counts are in its
group's `clumps` attribute (§18.1). Like
`n_hits_*`, both are computed when the component is written and never at render
time.

`n_missing_se_out_of_range` counts the Analysis's associations the Store does
not hold because their SE is above 65,504, the largest a `float16` plane holds
(§15, issue #338, ADR 0068). It is a non-negative integer. A release at format
0.2.3 or later MUST record it on every row, 0 included; in a release before
0.2.3 the column MAY be absent or blank, which means **unknown, never 0**. Each
writer counts what it leaves out; a Hybrid store's root counts both components
and its Dense Component counts its own cells, as the Top-Hit Counts do. A
Reference Completion records the source cells it does not carry and the fills
it leaves missing, the two parts per Analysis in
`provenance.completion.se_out_of_range` (`observed` and `imputed`, each a list
in `analysis_index` order), and its count is their sum plus its source's count
where that is known. A source at 0.2.3 or later records one, which is carried
forward. A source before 0.2.3 records none: its count is unknown, and is never
read as 0. Its completion counts instead each source association above 65,504
as it meets it -- exactly, because a completion reads every observed cell of
its source -- so the completed count is the two parts alone. A completion that
could not count a source's cells exactly would record the count as unknown
(blank), never as 0; none does. **A counted cell may hold an imputed value after
completion:** the count says how many of the Analysis's source associations the
Store could not hold, and a completion may impute a cell its source's build left
out, as it imputes any missing cell. The count is store-only: a build manifest
never carries it.

## 8. Sample size metadata

Sample size semantics are represented by kind and scope.

Sample Size Kind:

```text
total
case_control
effective
variant_level
```

Sample Size Scope:

```text
analysis_level
variant_level
```

OpenGWASDB MUST NOT present sample size inferred from effect statistics as an observed participant count.

A Ragged release MAY store a sample size **per association**, in the `n` plane
(§6a, §11, ADR 0067). It is a build input -- for a BESD build, a per-pair table
keyed by `.epi` probe ID and `.esi` SNP ID, such as eQTLGen's published
`NrSamples` -- and never a value recovered from `z`, `se` and EAF: a pair the
input does not name is stored as missing, not estimated. The input's path,
sha256 and match counts are recorded in `manifest.json`'s
`provenance.sample_size_table` (`n_rows`, `n_rows_matched`,
`n_rows_unmatched`, `n_associations`, `n_associations_missing`). An Analysis
holding at least one per-association N declares
`sample_size_scope=variant_level`; its `sample_size` column keeps whatever
per-Analysis figure its manifest supplied.

Physical sample-size encoding is an implementation detail. Builders SHOULD choose the smallest lossless representation compatible with source data, including scalar counts, total N plus constant case fraction, sparse residuals, or full per-variant counts.

## 9. EAF and INFO metadata

EAF Scope and INFO Scope use the same values:

```text
absent
variant
association
```

EAF and INFO are optional metadata, and neither is needed to reconstruct beta,
Z, or p-value, nor a legacy or floating-point `se` (§6). The exception is a
residual-coded `se` (§6a), which decodes against the EAF planes its cells were
coded against — the observed EAF for observed cells, the Reference EAF for
imputed cells — so a release carrying one is not reconstruction-independent of
EAF, and validation requires a complete `eaf` plane beside it (§20).

Variant-scoped EAF or INFO is valid only when the builder can establish that one value is genuinely shared. Builders MUST NOT average differing association values into variant-scoped values.

For imputed associations, EAF comes from the LD Reference Panel when stored. EAF provenance is inferred from Association Status:

- observed association: source EAF, or NaN where the source reported none;
- imputed association: reference-panel EAF, held once per variant in
  `eaf_reference` (§6a).

An observed cell never takes the panel's frequency: the two are not
interchangeable, and the difference between them can be three orders of
magnitude (§6a, ADR 0037 §4).

Each Analysis declares its EAF Scope in `analyses.tsv`'s `eaf_scope` column
(ADR 0036), derived by the builder from what it actually stored rather than
copied from a build manifest. Builders emit `absent` or `association`;
`variant` remains specified but unimplemented, since no ingestion path can
establish that one value is genuinely shared. Reference Completion carries
observed EAF across unchanged, and stamps `association` on an Analysis that
gained imputed cells in a release carrying `eaf_reference` — that Analysis now
stores a frequency for those cells, and the declaration follows what the
release holds rather than what its source reported.

`eaf_scope` is per Analysis and the `encoding` block (§6a) is per release: two
granularities of the same fact, which validation cross-checks (§20). A release
declaring no `eaf` plane while an Analysis declares `eaf_scope=association` is
invalid, and so is the reverse — unless the release declares `eaf_reference`,
in which case it does hold frequencies for its imputed cells and the Analyses
that gained them say so. On a Hybrid release the question is asked of **every**
component: `analyses.tsv` describes the Analyses of both, and `eaf_reference`
is per component, so a release whose frequencies are all in its Dense Component
is not a contradiction of its top-level plan.

### 9.1 EAF orientation is verified, and the verification is recorded

Stored EAF MUST describe the *stored* effect allele (§5). A source that
reports `effect_allele_frequency` against the other allele produces a store
whose every frequency is wrong by `1 - f`, with nothing in the row to show it:
`0.42` where the truth is `0.58` is a perfectly plausible frequency. This is
not hypothetical — `GCST003566` in the `gwas-catalog-eur-hybrid` pilot does
exactly this (ADR 0037 §6, issue #115).

Builders MUST therefore correlate each Analysis's A1-oriented EAF against a
reference over a deterministic sample of the overlapping variants, and MUST
fail the build when the correlation is negative. The reference is an external
panel where one is supplied; otherwise, for a build of three or more Analyses,
it is the consensus of the other Analyses — which can establish that Analyses
disagree but not which is right, so an inconsistent build fails rather than
dropping a study.

A BESD file set is the one source whose Analyses share their frequencies: the
`.esi` reports one per variant, and a build asked to store it
(`--store-esi-eaf`, opt-in) stores that one value at that variant for every
probe (`1 − f` where the canonical orientation flipped the allele). Its check
is therefore run **once, over the `.esi`**, against the supplied reference, and
the one outcome is recorded against every probe that stores a frequency, under
`provenance.eaf_orientation.scope = "source_file"` (ADR 0067). It MUST NOT fall
back to a consensus of probes: they agree by construction, so a consensus would
certify the `.esi` against itself. With no reference, every such probe records
`unverified`.

The check MUST NOT be interpreted where it cannot be. Below a minimum overlap,
or below a minimum frequency variance on either side, the Analysis records
`unverified` — never `passed`. An Analysis that stores no EAF likewise records
`unverified`: there is no wrong column, but neither is there a checked one, and
the two must not read alike.

The evidence is about a **stored, source-derived** frequency column, and only
about that. A Reference-Completed release whose components declare no `eaf`
plane at all carries the panel's `eaf_reference` and nothing else (§6a): its
Analyses declare `eaf_scope=association` because the release holds frequencies
for their imputed cells, but no cohort reported those frequencies and none can
be reported against the wrong allele — `panel_a1_eaf` orients the panel by
construction, through the same reader this check uses. Such an Analysis
therefore requires no orientation evidence, and a blank `eaf_orientation` on it
is correct rather than missing. Requiring evidence there asks for a check on a
column that does not exist, which no build can supply: it rejected every
Reference-Completed release built from a source with no frequencies of its own,
which is the release §6a exists for.

The reference itself is checked before it is trusted: one whose frequencies
exceed 0.5 for only a negligible fraction of its variants is minor allele
frequency, which is symmetric about 0.5 and would correlate a flipped source at
r ≈ +1. Such a reference is **refused outright** — the build fails on the
reference, not on the Analyses, because nothing correlated against it would mean
anything.

The threshold is on the *sign* of `r`, not its strength. A genuine study can
correlate weakly with a reference panel — `GCST007320` in the
`gwas-catalog-eur-hybrid` pilot reads +0.878 against the UKB EUR panel where the
other nine read above +0.99 — so a floor on `|r|` would reject real data while
adding nothing: the defect this catches sits at −0.999.

The outcome is Analytical Metadata: `eaf_orientation` (`passed`/`failed`/
`unverified`), `eaf_orientation_r` and `eaf_orientation_n` in `analyses.tsv`,
with the reference's identity and checksum, the sample size, and each
Analysis's evidence in `manifest.json`'s `provenance.eaf_orientation`.
Validation checks the recorded evidence rather than the panel, since a Store
Release must stay interpretable after the panel it was built against has moved;
re-deriving the answer from the store's arrays is a separate audit that takes a
panel as input.

A correlation is deliberately used in preference to any threshold on the *size*
of the difference: a bottlenecked cohort's frequencies legitimately differ from
a reference panel's by three orders of magnitude (FinnGen, max log-residual
8.07) while still correlating at r = +0.995, because a bottleneck changes
magnitudes, not direction.

## 10. Dense Observed-Only layout

Dense Observed-Only is the first implementation target.

Dense layout stores arrays with shape:

```text
n_variants x n_analyses
```

Required statistic arrays:

```text
data.zarr/z
data.zarr/se
```

`z` is encoded as §6a declares, and carries `data.zarr/z_overflow_index` and
`data.zarr/z_overflow_value` beside it when that encoding is `int16_fixed`.

Optional (ADR 0036), same shape and chunking as the required arrays:

```text
data.zarr/eaf
```

`eaf` is `float32` where `se` is `float16`: the canonical A1 is the
lexicographically smaller allele rather than the minor one, so EAF near 1 is
ordinary, and `float16` spacing near 1.0 (0.00049) would round a MAF of 1e-4
to zero. The array is absent entirely when no Analysis in the release carries
a frequency; per-cell NaN carries per-Analysis and per-cell absence alike.

In Observed-Only Dense stores:

- every present cell represents an observed association;
- unavailable associations are represented by each plane's missing marker
  (§6a, §15) in both `z` and `se`;
- no imputed mask is required;
- the dense variant axis is source-faithful and does not require an LD Reference Panel.

Recommended compression for initial implementation is Zarr with Zstandard and bitshuffle, using benchmarked chunking appropriate for mixed range, variant, PheWAS, and full-analysis extraction workloads.

## 10a. `data.zarr` physical layout in the 0.2 series

The 0.2 series (`0.2.0`, `0.2.1` and `0.2.2`) stores every array as **Zarr v3 with the sharding codec**. The
arrays, dtypes, fill values and encodings are exactly those of 0.1.0 (§10); only
the physical layout changes. A 0.2 release exists because the unit a query
reads — the **inner chunk** — is decoupled from the unit stored as a file — the
**shard** — so the Dense Analysis-axis inner chunk can narrow without
multiplying the file count (ADR 0057, ADR 0021).

```text
format_version 0.1.0   Zarr v2   .zarray / .zgroup, one file per chunk
format_version 0.2.0   Zarr v3   zarr.json, one file per shard
format_version 0.2.1   Zarr v3   the same; a Ragged release's optional regions.tsv (§1)
format_version 0.2.2   Zarr v3   the same; an indel's ALID spelt reference first (§4)
```

**Shards are bounded on both axes.** The Dense VCF builder writes `[all variants
× band]` column bands, so a shard spanning every Analysis is never written whole
(ADR 0057). A Dense shard is `[V_s × A_s]`, with `A_s` a whole multiple of the
Analysis-axis inner chunk. The decided shapes (#246, ADR 0058), which a
conversion takes as parameters, are:

| array role | inner chunk | shard |
|---|---|---|
| Dense statistic planes (`z`, `se`, `eaf`) and the imputed mask | `[1000, A_c]`, `A_c` the analysis-axis chunk (**decided 64**), clipped to the array | `[100_000, 1024]` (rows × Analyses); the inner chunk MUST tile this shard (**`100000 % V_c == 0` and `1024 % A_c == 0`**), and the shard is clipped only when the array itself is shorter than it |
| Dense per-variant side arrays (`eaf_baseline`, `eaf_reference`) | per §6: the serving plane's variant-axis chunk, capped at 200,000, clipped to the array | about 1,000,000 elements |
| Ragged association sequences (`ragged/z`, `se`, `variant_index`, `eaf`, `imputed`) | 200,000, or an explicit `chunks=(...)` | 50,000,000 elements, clipped to a whole number of inner chunks |
| Ragged per-variant side arrays (`ragged/eaf_baseline`, `ragged/eaf_reference`) | per §6 | 10,000,000 elements |
| Ragged exception / overflow tables (`ragged/z_overflow_*`, `ragged/eaf_exception_*`, `ragged/se_exception_*`) | the role policy's 200,000, clipped to the array length | 10,000,000 elements |
| flat Rho arrays | 1,000,000, clipped to the array | about 1,000,000 elements |
| top-hit index columns | 16,384 (as 0.1.0), clipped to the array | `--top-hit-shard-chunks` inner chunks (**decided 64**), clipped to cover the array. The converter may set it to 1, one inner chunk per shard, the "effectively unsharded" variant #246 measured the top-hit query against; the array is a sharded v3 array either way. A builder always takes the decided 64 |
| top-hit per-Analysis offsets | whole array | one shard holding the array |
| Dense exception / overflow tables (Z, EAF and SE) | the role policy's 200,000, clipped to the array length (a shorter table is one inner chunk) | one shard holding the array |
| SE coefficients | `(min(n_analyses, 1024), 2)` | one shard holding the array |
| CSR per-Analysis offsets | 10,000 | one shard holding the array |

The Ragged shards are fixed, not conversion parameters: they are chosen so
OGS-00011's overflow sequences (3,085,080,783 entries) become 62 files of
tens to low hundreds of MB per array rather than one multi-GB file, and its
Ragged `eaf_exception_index` (180,396,687 entries) becomes 19 files rather than
one 1.4 GB file.  The sequence shard is bounded by cells, not by one Analysis's
run, so a future variant-side index can be added beside the Analysis-sorted
arrays without re-sharding them.  A builder writes a Ragged sequence plane one
**whole shard** at a time: a write covering part of a shard is a read-modify-write
of the whole thing, so at a 50,000,000-element shard the flush region follows the
shard rather than the other way around (#249).

`clipped to cover the array` means the smallest whole number of inner chunks
that spans the dimension, so an array shorter than the decided shard gets one
shard of its own extent.  The inner
chunk is `chunk_layout(role, shape, …)`; the shard is `shard_layout(role, shape,
inner_chunk=…)` — one role → layout table in `opengwasdb.store.arrays`, so the
converter and the builders cannot disagree. The top-hit shard width is the
one override a caller passes to `shard_layout` (`top_hit_shard_chunks`); it
applies to `TOP_HIT_INDEX` alone and defaults to the policy's 64.

**A Dense inner chunk MUST tile the decided shard.**  The Dense shard is
`[100_000, 1024]`; a builder that supplied an inner chunk not dividing an axis
of it (`1024 % A_c != 0`, say) is refused, naming the values that do, rather
than silently writing a different shard such as `[100000, 1000]`.  That is the
one way a build could otherwise choose its shard, and a shard the converter does
not reproduce is a layout divergence a reader cannot see.  The one exception is
an array **shorter** than the shard on an axis: its shard is the array's own
extent, so divisibility is moot and it clips.  The default `[1000, 64]` tiles
both axes.

**The builders do not expose the shard shape.** `opengwasdb build-dense-vcf`,
`build-hybrid` and `build-hybrid-from-catalogue` take `--chunk-variants` and
`--chunk-analyses`, and both name the **inner chunk** (the unit a query reads);
the shard is the decided shape above and cannot be overridden on a build. That
is deliberate: the shard is part of the format's contract, a release whose
shard the converter cannot reproduce would break the identity #249 checks, and
a build-time shard knob is a way to write a release whose layout nothing else
in the release records. The converter keeps its `--dense-shard` and
`--dense-analysis-chunk` because it reproduces a chosen layout and records it
in `provenance.zarr_v3_conversion`; a builder chooses the format's layout and
records it in the same three places as any Dense release.

The inner chunk is the role policy of `opengwasdb.store.arrays` (`chunk_layout`)
and the shard its companion `shard_layout`; a shard MUST be a whole multiple of
the inner chunk on every axis, and a layout that is not is invalid rather than
clipped.  For a Dense plane the reverse also holds: the inner chunk MUST tile
the decided shard, or `shard_layout` refuses it (§10a).

The codec chain is Blosc Zstandard / clevel 3 / bitshuffle inside the
`sharding_indexed` codec — the v3 spelling of the 0.1.0 compressor. An array
written uncompressed in 0.1.0 (the `z`/`eaf` exception and overflow tables)
stays uncompressed inside its shard. Every shard carries the codec's own
`crc32c` index codec.

**Where the layout is recorded.** A 0.2 release records the Dense planes'
inner chunk and shard in three places, all of which MUST agree with the arrays.
From 0.3.0 the `index.sqlite` blob is dropped (ADR 0102, #471): `manifest.json`
is the one copy it held, and a 0.3.0 release records the layout in the other two.

- `manifest.json` `provenance.dense.chunk_shape`, `.shard_shape` and
  `.compressor` (with `.zarr_format`), plus the per-array layout in
  `provenance.zarr_v3_conversion.layouts` for a converted release;
- the `dense` metadata blob in `index.sqlite`
  (`chunk_shape`, `shard_shape`, `compressor`, `zarr_format`), 0.2 only;
- the `data.zarr` root attributes (`chunk_shape`, `shard_shape`, `compressor`,
  `zarr_format`).

A **Hybrid** release's nested Dense Component is a Store Release with its own
manifest, its own `index.sqlite` (0.2) and its own root attributes, so it records the
same places itself: its `provenance.dense` MUST carry `chunk_shape`,
`shard_shape`, `compressor` and `zarr_format`, and the outer release's
`provenance.hybrid` MUST agree with them.  Leaving the layout only in the outer
`provenance.hybrid` leaves the component undescribed — the gap #248 closes.  A
component root that holds no Dense plane (a Ragged or Hybrid outer root) carries
no Dense layout attributes at all.

For 0.1.0 the same three places record the inner chunk alone (there is no shard)
and a `chunk_shape` is a *hint* the role policy clips to the array's dimensions;
the recorded-layout rule (§20) clips it the same way before comparing, so a small
store's build-wide hint is not a disagreement.

The per-variant chunking rule (§6) applies to the **inner chunk** of a sharded
array. In zarr-python 3 `Array.chunks` is the inner chunk and `Array.shards` the
outer shard; every read-unit rule MUST use `chunks`.

The optional Clumps of the 5e-8 tier (§18.1) live inside that tier's group, in the
tier arrays' own role and chunking, in a 0.3.0 release; no earlier format carries
them.

## 10b. Indexed Variant Subsets (optional, Dense)

An **Indexed Variant Subset** is a named, optional, rebuildable query index over
a caller-supplied set of canonical ALIDs (ADR 0061). It is **derived,
non-authoritative data**: it changes no association and no Analytical Metadata,
a reader that does not know about it still reads the primary planes correctly,
and it may be added, atomically replaced or removed in place without minting a
Store Release or moving `format_version` (§21.1). Deleting it leaves a valid
release whose ordinary queries are unchanged. It is therefore **not** the
"optional array, index, or sidecar" a compatible format change is made of
(ADRs 0038, 0041): those are content a reader may need to interpret
authoritative data.

The index content is **Dense-only**, covering both Observed-Only and
Reference-Completed Dense releases. Ragged stores already expose each Analysis as
a direct CSR slice and carry none. A Hybrid release is reachable from its root:
`build-indexed-subset <root> ...` resolves to `<root>/dense` and stores the group
at `dense/data.zarr/indexed_subsets/<name>`, indexing only that self-contained
Dense Component's on-panel variants and never unifying them with the Ragged
Overflow (issue #271). A Reference-Completed Dense index carries the per-cell
`imputed` mask and the subset `eaf_reference`, so it reproduces the release's
ordinary Association Status and frequency exactly (issue #266).

It is stored beside the other optional derived artifacts:

```text
data.zarr/
  rho/
  top_hits/
  indexed_subsets/
    <name>/
```

For a Hybrid release these paths are relative to `<root>/dense`; the shared
`data.zarr`, which holds only the Ragged Overflow and the merged top-hit cache,
never carries the `indexed_subsets` namespace. Discovery, removal, overview,
validation and the CLI accept the Hybrid root and resolve to the nested
component, while a direct nested-Dense path remains valid.

### Variant list and subset name

The input is one canonical ALID (§4) per nonblank line; a malformed, repeated or
non-canonical ALID fails the build, naming the line. ALIDs absent from the Store
Variant Table are permitted but counted and recorded, never treated as matches;
a list resolving to no Store variant is refused. The caller MUST supply the
list's Reference Assembly, and a mismatch with the release's
`reference_assembly` is refused because cross-Store Variant Identity is
assembly plus ALID (ADR 0061).

On a Hybrid root, an ALID present in the shared union table but absent from the
Dense Component is an **overflow-only** request: it names a variant the release
carries at a Variant Index this index cannot address, so resolving against the
Dense Component alone would count it absent and silently drop it. `--overflow-only`
decides it. `refuse` (the default) MUST fail the build and name the ALIDs.
`skip` MUST leave them out of the subset and record `overflow_only_count` (the
number skipped, always written, `0` when none) and `overflow_only_sample`
(the deterministic first 20 in variant-list order) beside the absent count, and
MUST report both in the command's summary as `overflow_only` (`policy`,
`n_overflow_only`, `sample`).  The metadata key matches `absent_count`; only
the summary's field is `n_overflow_only`.  The skipped count is never folded
into `absent_count`: `absent_count` keeps its meaning of "the release does not
carry this ALID". The recorded counts MUST satisfy `requested_count ==
resolved_count + absent_count + overflow_only_count`, and a group recording
neither Overflow-only attribute is read as `0` because the builder that wrote
it could only refuse such a request. An ALID absent from the shared union
table as well keeps the counted-as-absent handling; the shared table makes the
two observable, and that is what licenses preserving the existing handling. A
direct nested-Dense build names only the Dense Component, so an off-panel ALID
there is absent-and-counted as before; a Dense release has no Overflow axis, so
there `--overflow-only` is accepted and has no effect.

A subset name MUST match `[A-Za-z0-9][A-Za-z0-9._-]{0,127}`. A leading `.` is
reserved so a name cannot collide with the `.{name}.tmp.*` staging groups or the
`.{name}.old` replacement directory of the atomic publication below.

### Arrays

`variant_index` is the subset's sorted, unique Store Variant Indices, shape
`(n_subset_variants,)`, `int32`; it is the subset's own axis order and the
Analysis-major planes below are indexed in that order (`order =
"analysis,variant"`). Its inner chunk is 65,536, clipped. The read seam and
validation require that storage dtype: a widened integer or floating-point axis
is refused rather than silently cast, because it could truncate or round a Store
Variant Index.

The statistic planes are **Analysis-major**: shape `(n_analyses,
n_subset_variants)`, so one Analysis is one row.

| array | when | inner chunk |
|---|---|---|
| `z` | always | `(1, 65,536)`, clipped |
| `se` | always | `(1, 65,536)`, clipped |
| `eaf` | when the release has an `eaf` plane | `(1, 65,536)`, clipped |
| `imputed` | Reference-Completed release | `(1, 65,536)`, clipped |
| `z_overflow_index`, `z_overflow_value` | declared fixed-point `z` | 200,000 |
| `se_coefficients` | declared `int8_residual` `se` | `(min(n_analyses, 1024), 2)` |
| `se_exception_index`, `se_exception_value` | declared `int8_residual` `se` | 200,000 |
| `eaf_baseline` | declared `int8_residual` `eaf` | 65,536, clipped |
| `eaf_reference` | when the release declares reference EAF | 65,536, clipped |
| `eaf_exception_index`, `eaf_exception_value` | declared `int8_residual` `eaf` | 200,000 |

The group carries exactly those arrays and no others, under the release's
declared `encoding` plus its Completion State: a `float16` `se` or a
`float32`/`absent` `eaf` has none of the side arrays its plan does not define,
exactly as §6a requires of the primary planes; a Reference-Completed release
always has `imputed`, a release declaring reference EAF always has
`eaf_reference`, and an Observed-Only release has neither. `imputed` is `uint8`
and MUST hold only 0 and 1. On a 0.2 release (§10a) each plane's shard is one
Analysis row by 1,048,576 variants (16 inner chunks), clipped to the array, so
reading one Analysis never decompresses another's cells.

The inner chunk and shard of **every** array, not only the statistic planes, are
part of the format: each array's expected layout is derived from its `ArrayRole`
and shape through the store-array seam's policies (§10a), so no attribute records
it and none is required. On a 0.2 release every array MUST carry that shard; on
a 0.1.0 release no array may be sharded. A plane inner chunk or shard that spans
Analyses defeats the index's one-Analysis narrow read, and a per-variant side
array off the format's layout is the same class of silent divergence; both the
read seam and validation refuse them.

A cell's flat position in an Analysis-major plane is `analysis *
n_subset_variants + subset_slot`, and a side table is keyed by it. The index
copies the primary planes' stored **codes** and re-keys their side tables into
this layout, so a decoded indexed cell is identical to the authoritative primary
cell rather than a re-encode of a decoded value. `eaf_baseline` is the release's
own per-variant baseline restricted to the subset's variants -- not one
recomputed from the subset, which would decode a single-Analysis variant to its
own value. `imputed` is copied cell for cell, because Association Status is a
per-cell fact and never an Analysis-level one; `eaf_reference` is the release's
own per-variant panel frequency restricted to the subset's variants. Decoding an
imputed cell substitutes that panel frequency through the same codec the primary
plane uses, so an imputed cell reads the panel's value and an observed cell whose
source reported none stays absent (ADR 0037 §4).

### Attributes

A published group self-describes; validation rejects a group missing any of
`indexed_subset_schema` (`1`), `indexed_subset_name`, `statistic_profile` (`full_statistic`),
`encoding` (the release's block, §6a), `reference_assembly` (normalised),
`source_store_id`, `source_release_id`, `source_format_version`, `n_analyses`,
`n_subset_variants`, `input_sha256` (the variant list's bytes),
`requested_count`, `resolved_count`, `absent_count`, `overflow_only_count`,
`overflow_only_sample`, `builder_version`,
`created_at` and `order` (`analysis,variant`). `overflow_only_count` is the
number of requested ALIDs present only on a Hybrid release's shared/Overflow
axis that a `--overflow-only skip` build left out (`0` when none were, and on a
Dense release, which has no Overflow axis), and `overflow_only_sample` is the
first 20 of them in variant-list order; a group written before the option
existed records neither and is read as `0` (ADR 0065). On a Hybrid release the
`source_store_id`/`source_release_id`/`source_format_version` attributes record
the nested Dense Component, the self-contained release the index physically
belongs to and the one the read seam validates it against.

*24 Nov 2026 (#472).* `ogdb rewrite-release` carries a subset to the release it
derives (§21.4, [ADR 0105](../adr/0105-format-0-3-0-variable-length-alid-sidecar.md)).
It changes no Store Variant Index and no stored code, so the subset holds the same
cells; it writes the new release's `release_id` into `source_release_id` and its
`format_version` into `source_format_version`, and keeps every other attribute. So
after a rewrite `builder_version` and `created_at` still describe the subset's
original build, not the rewrite, and `source_release_id` names a release the subset
was not built from. `subsets.indexed` then compares every decoded cell with the
release's primary planes, and a subset already stale on the source is refused.

A regenerated `overview.html` lists every published subset: the name, the
requested/resolved/absent/Overflow-only counts, the input checksum, the
Reference Assembly and
the build provenance are read from the group's own recorded metadata, while the
physical size is computed from the group's files at render time (it is not
recorded as an attribute). A named directory that cannot be read, whose
recorded `indexed_subset_name` disagrees with its directory name, or that fails
the structural read seam (§10b: schema, profile, order, counts, exact array set,
dtypes, shapes and in-range Variant Indices, but no decoded-value comparison) is
surfaced as an invalid entry rather than silently omitted or relabelled, and is
**not** also listed or counted as a valid subset. A structural probe that cannot
read the store metadata it needs (a missing or corrupt `manifest.json`) is
treated the same way, so one unreadable release envelope cannot abort the whole
page. The page presents these facts and is not a second source of truth (§1).

### Lifecycle

Generation follows ADR 0043's isolation and publication rules at the
named-group level: it creates the `indexed_subsets` namespace group under a
lock on `data.zarr`, writes into an invocation-unique `.{name}.tmp.*` sibling,
validates the complete staged group (structural invariants and the small side
tables exhaustively, a bounded deterministic decoded sample otherwise; §10b),
takes a release-local advisory lock on the
namespace, re-checks the destination under it, and publishes by rename. A
failure discards only that invocation's temporary group; an existing published
group is preserved byte-for-byte after any failed replacement. Two same-name
no-overwrite builds yield one winner and one loud failure; different names do
not delete or publish one another's work.

Removing a subset takes the same namespace lock and renames the group aside
before reclaiming its bytes, so a removal can never interleave with a commit of
the same name and a reader never sees a half-deleted group. The published name
disappears atomically; a `.{name}.old.*` directory left by an interrupted
removal is inert and is rejected by validation until it is cleaned up. A
removal beneath consolidated metadata is refused before the rename, because the
record would keep listing the removed group and the next open would read it.

The 0.2.0 converter (§21.4) does not carry this namespace: it refuses an array
or group it cannot name a role for, so a release holding an Indexed Variant
Subset must have it removed before conversion. That is safe -- the index is
deletable derived data -- and the refusal is loud rather than a silent drop of
an artifact the user built.

### Query

A selected-Analysis query may name a published subset
(`query-analysis STORE ANALYSIS_ID --indexed-subset SUBSET_NAME`, ADR 0061,
issue #265). It returns the same parallel arrays, with the same meanings,
dtypes, allele orientation, finite Z/SE filtering and Store ordering as
filtering the ordinary selected-Analysis result to the subset's Variant
Indices; beta and p-values remain derived from the returned Z and SE exactly as
they are without a subset. Every subset covers every Analysis, so there is no
partial-Analysis answer.

On a Reference-Completed release the result carries the same `association_status`
values (`observed`, `imputed`, `missing`) and the same allele orientation as the
ordinary path, because the index decodes the same stored codes through the same
`imputed`/`eaf_reference` dependencies. Imputed associations are included by
default, `observed_only` excludes exactly them, and the paired Z/SE finite rule
excludes missing cells. The mask is per cell: an Analysis left observed-only by
the ancestry-match filter reads its own observed cells correctly from the index,
and no completion state is inferred from another Analysis.

A reader MUST refuse an unknown, staging, incomplete, stale, invalid or
unsupported subset by name, naming the Store it belongs to, rather than fall
back to the authoritative planes: the selector is a request for the indexed
path, and answering it from the primary matrix would silently return the slow
path's result while appearing to be indexed. The named subset is resolved and
structurally validated **before** the Analysis ID is resolved, so a typo'd,
stale or corrupt selector always fails even when the Analysis ID is also unknown;
a *valid* subset with an unknown Analysis ID raises `UnknownAnalysisError`, as the
ordinary read does (§19, #474).
Before decoding any value, independent of whether `validate` has been run, the
read path re-checks the declared name, schema, profile and `order`, the declared
Analysis and requested/resolved/absent/Overflow-only counts, the exact array set, every plane's
declared dtype and shape, the `int32` storage dtype of `variant_index`, every
array's inner chunk and shard against the format's role policy, and that
`variant_index` is non-empty, sorted, unique and in bounds `[0, n_variants)`. A malformed encoding block is refused as a malformed
subset rather than allowed to raise a decode error. An entry that is not a
readable Zarr group -- a plain directory, an array, or metadata a reader
cannot parse or validate -- is refused the same way, not left to leak a zarr,
JSON or ValueError exception through the facade. For a Reference-Completed
index it also reads the `imputed` mask's dtype from its metadata and checks
that the mask column of the Analysis being decoded holds only 0 and 1, before
any value, Association Status or `observed_only` filter is derived from it: a
float or out-of-domain mask would otherwise be read as imputed by the frequency
substitution and as observed by Association Status at the same time. It does
not compare the mask's or `eaf_reference`'s content against the release --
`validate` does that. It does NOT re-derive
decoded values or side-table internals -- that is `validate`'s expensive job --
and cannot detect an in-range Variant Index shift while identity and bounds
hold. A subset on a Ragged release is refused, because Indexed Variant Subsets
are Dense-only. On a Hybrid root the selector is served by the nested Dense
Component's index: the result's panel-local `variant_index` is remapped through
`dense_to_shared.npy`, the Ragged Overflow is never read or appended, and an
unknown, stale or corrupt selector still fails loudly rather than falling back
to either ordinary path. When no subset is named, selected-Analysis behaviour
is unchanged and no indexed-subset state is consulted at all.

## 11. Ragged layout

Ragged layout stores Analysis-specific association sequences referencing the Store Variant Table.

Each retained association row contains at least:

```text
analysis index or analysis offset
variant_idx
z
se
```

`z` is encoded as §6a declares, with its overflow arrays
(`data.zarr/ragged/z_overflow_index`, `…_value`) keyed by the association's
ordinal in the concatenated CSR arrays.

The CSR is analysis-major: `data.zarr/ragged/offsets` bounds one contiguous
segment per Analysis, and within every segment `variant_index` MUST be
**strictly increasing** — a repeated `variant_index` is two associations at one
variant of one Analysis, which `(variant, Analysis)` resolution cannot tell
apart. The ordering is a format invariant, not a builder convention: a reader
locates a `(variant, Analysis)` pair by binary-searching that Analysis's
segment, and a segment out of order would answer with a plausible, wrong row
rather than an error. Validation therefore checks the ordering on every
release, including ones this build did not write (§20).

`eaf` (ADR 0036) is an optional fourth parallel array (`data.zarr/ragged/eaf`,
`float32`), aligned with the CSR `z`/`se` and absent when no Analysis in the
release carries a frequency. A BESD build stores the `.esi` frequency there
only when asked (`--store-esi-eaf`, §9.1, ADR 0067); without the flag it stores
none, whatever the `.esi` reports.

`n` (ADR 0067) is an optional fifth parallel array (`data.zarr/ragged/n`,
`uint32`, §6a), present exactly when the `encoding` block declares it, and
written only when the build is given a per-association sample size (§8). The
top-hit indexes do not carry it; a top-hit query resolves each hit to its CSR
cell for `n`, as it does for `eaf` when an index carries none.

A Ragged build standardises its standard errors from the same manifest, and in
the same place, as every other builder (§7, ADR 0084): `build-ragged-besd` and
`build-ragged-ssf` divide each Analysis's `se` by its `original_sd` before the
association is encoded, record that `original_sd`, and store `z` as the source
gave it. A Ragged SSF Release built before issue #366 corrected this records the
manifest's rescaling `original_sd_method` with a blank `original_sd` while
holding the source's own standard errors; `validate` fails it (§7a), and it is
rebuilt or repaired rather than read as SD Units.

### 11.1 The variant-centric index (`ragged/by_variant/`)

In the 0.2 series, every Ragged component (a Ragged Store Release or a
Hybrid Overflow) MUST carry a variant-centric index at `ragged/by_variant/`
(ADR 0060). It is **required**: an absent index is refused by the query facade
and fails validation, and builders always write it. Its presence is recorded
in `provenance.ragged.by_variant` (`{"group", "n_axis", "n_rows"}`). It holds
one row per association of the Analysis-sorted component, ordered
`(variant_index, analysis_index)`, so a variant's rows are contiguous:

| array | dtype | contents |
|---|---|---|
| `offsets` | int64 | `n_axis + 1` row offsets on the component's own variant axis (the shared axis for a Hybrid Overflow); `offsets[v] == offsets[v+1]` for a variant the index does not cover |
| `analysis_index` | int32 | the Analysis of each row |
| `z`, `se` | the component's `z`/`se` dtypes | the same stored codes, re-keyed |
| `eaf` | the component's `eaf` dtype | the same codes, re-keyed; present only when the component has an `eaf` array |
| `imputed` | uint8 | the imputed mask, present only when the component has one |
| `n` | uint32 | the same per-association sample-size codes, re-keyed; present only when the component has an `n` plane (ADR 0067) |
| `z_overflow_index` / `_value` | int64 / float32 | the re-keyed `z` overflow table |
| `eaf_exception_index` / `_value` | int64 / float32 | the re-keyed EAF exception table |
| `se_exception_index` / `_value` | int64 / float32 | the re-keyed SE exception table, under `int8_residual` |

The per-variant `eaf_baseline`, `eaf_reference` and the `se_coefficients` are
**shared** with the Analysis-sorted plane, never duplicated: only arrays keyed
on the flat cell position are re-keyed. `imputed` and the exception tables move
with the rows because a decode cannot reconstruct them from the
Analysis-sorted component (the duplicate does not preserve the source's CSR
ordinal). `analysis_index` and not `variant_index` is the per-row key: the
row's variant is implied by the offsets, and storing it would duplicate the
Analysis-sorted `variant_index`.

A query reads it through the analysis-sorted component's own layouts: the
`ragged/by_variant/offsets` array takes the `RAGGED_PER_VARIANT` role with a
**1,000-element inner-chunk hint** (it is read a variant at a time), the cell
sequences the `ASSOCIATION_SEQUENCE` role, and the re-keyed tables the
`RAGGED_EXCEPTION_TABLE` role. The hint is a fact about the path, so the
converter and the builders reproduce the same inner chunk.

Ragged layout is used when Analyses do not share one dense source variant axis, or when Association Coverage is narrower than `gwas` and cannot be represented as a Dense matrix (§2a, ADR 0064).

For Observed-Only Ragged stores, absence from an Analysis sequence means the association is not retained by that Store Release.

A Ragged store's Analytical and Attribution Metadata lives in `analyses.tsv`, the same schema §7a defines for every layout (ADR 0034) — not a layout-specific `index.sqlite` table, and not a second, tabix-indexed positional side-file either: an earlier draft of this section allowed such a side-file over `analyses.tsv`'s `trait_chr`/`trait_bp` columns as a query-acceleration structure, but issue #69 retired it before it shipped in favour of scanning `analyses.tsv`'s own columns directly (`range_by_analysis()`), so a Ragged Store Release's envelope (§1, §20) has no such file.

## 12. Reference completion model

Reference Completion is an optional build phase that produces a new Reference-Completed Store Release from an Observed-Only source release.

Reference Completion exists to avoid query-time LD proxy lookup and reduce missingness by filling gaps once at build time.

Reference-Completed releases MUST:

- declare an LD Reference Panel;
- declare a Reference Completion Method;
- expose Association Status;
- produce both Z and SE for imputed associations;
- record Reference Completion Quality at LD-block-by-Analysis granularity;
- preserve observed associations not present in the Reference Variant Set.

There is no Z-only completion mode.

Completion preserves every observed association exactly: a source-observed cell has the same decoded Z, SE and EAF in the Reference-Completed release and is not marked imputed, and no source-missing cell is observed in it. In a Hybrid release a Dense cell becomes observed only as a crossover, a source Overflow association moved into the Dense Component when the LD panel extends its axis; it holds what that component's own codec gives for the source value. `check-observed-view` (§20.4) re-derives that from the two releases' arrays.
A Hybrid crossover also removes the overwritten imputed or missing attempt from
each owning block's `completion_quality` row, using the LD panel while completing,
and refreshes the imputed rollup and completion counts. An observed association
is not a completion attempt merely because the Dense phase first imputed it.

The one exception is an association whose SE is above 65,504 (§15, issue #338),
which only a source before format 0.2.3 holds. Completion does not carry it: a
Dense cell is written missing and unflagged, a Ragged row is not written, and a
Hybrid crossover is not folded, so its Dense cell keeps what Dense completion put
there, imputed or missing. A fill whose SE is above 65,504 is left missing where
candidate fills become the release's, so its block's `completion_quality` row
counts it missing, not imputed. Completion records both per Analysis
(`provenance.completion.se_out_of_range`) and adds them to the count it carries
forward (§7a); `check-observed-view` holds the completed count to exactly that.
Completion fits no SE model (ADR 0078), so an Analysis left with fewer than two
SEs under a residual plan is coded against its source's model like any other.
A completion of a 0.2.2 source is stamped 0.2.3 (§21.3).

## 13. LD Reference Panel requirements

An LD Reference Panel used for Reference Completion MUST define:

| Requirement | Meaning |
|---|---|
| `reference_panel_id` | Stable panel identity |
| `reference_panel_version` | Panel version |
| `reference_assembly` | Genome assembly, matching the Store Release |
| `ancestry` | Population or ancestry label |
| variant list | Canonical ALIDs defining the Reference Variant Set |
| allele orientation | Orientation compatible with Store canonical ALID convention |
| LD blocks | Block definitions used by the completion method |
| LD representation | Form in which LD is stored — see below |
| source cohort | Cohort the panel's LD was estimated from |
| sample size | Number of individuals contributing to the LD estimate |
| variant inclusion | Threshold governing which variants enter the panel |
| checksums | Integrity checks for reference files |
| provenance | Source, build, and filtering provenance for the panel |

If EAF is emitted for imputed associations, the LD Reference Panel MUST provide EAF for panel variants or declare why EAF is absent.

The Store Release reference assembly MUST match the LD Reference Panel reference assembly.

A panel names its variants by an id whose two alleles are sorted, whatever the
genome's reference: every panel on the IEU host writes its 13.1 M indels that
way (issue #381). A panel indel is placed (§4) only by a reference the panel
declares (ADR 0079):
- a block's own `REF` column, where it has one; else
- the indel-reference table beside the panel's blocks,
  `ld_dir/{ancestry}/indel_reference.tsv.gz` (bgzipped, tabix-indexed; columns
  `chromosome`, `position`, `allele1`, `allele2` -- the id's alleles --,
  `reference`, `.` where unsettled, and `outcome`), with its provenance in
  `indel_reference.json`, whose `table_sha256` the table MUST match: a
  completion MUST refuse a table with no provenance or a different checksum.
  `scripts/build_panel_indel_reference.py` writes both from GRCh38 evidence,
  settling an indel only where a source reads it one way and none reads it
  otherwise, and never replaces either.

An indel neither settles names no ALID, is neither matched to a source's indel
nor filled, and stays in its block's LD; a fill there is dropped, and
`completion_quality` counts it neither imputed nor missing, since it counts only
rows the Store holds (the owner's ruling of 11 Nov 2026, ADR 0079's note). The
completion record counts it, in `provenance.completion.panel_indels`
(`unplaced.no_reference`). A
panel's eigenvectors and `EAF` are for each row's `EA`, and a Store's
statistics for its ALID's `A1`, so a row whose `A1` is not its `EA` -- a settled
panel deletion -- has its eigenvector row negated and its frequency complemented
before completion uses them. A row with no `EA` (an empty cell, or a block
with no `EA` column), or whose `EA` is neither of its alleles, names no ALID.
A completed release records how its panel placed its rows. In
`provenance.completion.panel_indels`: `reference_from` (`ref_column`, `table`,
`none` or `mixed`), each table read with its path, checksum, revision and
counts by outcome, the indels read and placed, and `unplaced`, the indels not
placed by reason (`no_reference`, `no_effect_allele`,
`effect_allele_not_an_allele`, `identity_invalid`), which sum to the
difference. In `provenance.completion.panel_snvs_unplaced`: the SNVs and
substitutions not placed, by the last three reasons. Every count is summed
over LD blocks: an indel on a block boundary counts once per block.

### 13.1 LD representation

A panel SHOULD store, per LD block, the **eigendecomposition** of the block's LD
matrix — all eigenvalues plus a retained set of eigenvectors — rather than the LD
matrix itself (ADR 0031). Reference completion consumes eigenvectors only, so the
matrix is not required to interpret or apply a panel.

The number of eigenvectors retained MUST be sufficient for the truncation the
Reference Completion Method requests, and the panel MUST record, per block, both
the retained count and the proportion of total eigenvalue mass it represents. A
fixed retained count is NOT sufficient: the number of components needed to reach a
given variance depends on the panel's sample size, so a count calibrated on one
cohort will silently under-resolve a panel built from a smaller one. Where a
consumer's requested truncation cannot be satisfied from the retained components,
it MUST surface that rather than proceeding with reduced variance.

Panels MAY additionally retain full LD matrices, but consumers MUST NOT require
them when a conforming eigendecomposition is present.

### 13.2 Panel power is not uniform across ancestries

Panels for different ancestries may be estimated from cohorts differing by orders
of magnitude in sample size, and a panel's LD matrix has rank at most one less
than its sample size regardless of how many variants it spans. Reference
completion quality therefore varies by panel construction independently of the
quality of the Analyses being completed. Because `sample size`, `source cohort`,
and `variant inclusion` are recorded per panel, that difference is discoverable;
comparisons of completion quality across ancestries MUST NOT assume panels are
equivalently powered.

## 14. Reference completion method requirements

The Reference Completion Method MUST record:

| Field | Meaning |
|---|---|
| `method_name` | Algorithm name |
| `method_version` | Method version |
| `software` | Software/package and version |
| `parameters` | Parameters affecting imputed Z or SE |
| `required_reference_inputs` | LD reference files/data required |
| `deterministic` | Whether same inputs produce same output |
| `quality_metric` | Definition of recorded quality values |
| `quality_thresholds` | Pass/fail or reporting thresholds, if used |

The initial intended method family is LD-eigenvector based imputation of Z and SE. The store format is not locked to one algorithm: different methods are valid if they record provenance, satisfy the `z + se` output contract, and pass validation.

The initial Reference Completion implementation should use the existing `pleiodb` imputation work as prior art:

- method source: `https://github.com/explodecomputer/pleiodb/blob/main/src/pleiodb/impute.py`;
- benchmark and reference-file location notes: `https://github.com/explodecomputer/pleiodb/blob/main/scratch/imputation_benchmark.qmd`;
- benchmarked LD panel root recorded there: `/local-scratch/projects/genotype-phenotype-map/data/ld_reference_panel_hg38/EUR`.

That prior art uses LD block TSV files alongside `.unphased.vcor1.gz` LD matrices, treating the eigendecomposition as a derived cache. Under §13.1 that relationship is inverted: the eigendecomposition is the primary panel artifact and the LD matrix is optional. Panels produced before that decision may still carry matrices, and a conforming reader MAY use one to derive a missing decomposition, but MUST NOT require it when a decomposition is present. These file types remain implementation inputs to the Reference Completion Method and MUST be captured through LD Reference Panel and Reference Completion Method provenance when used.

## 15. Association Status encoding

Reference-Completed Stores encode Association Status using a per-plane **missing marker** plus an imputed mask.

Each statistic plane's missing marker is defined by that plane's declared encoding, not by its dtype: a floating-point plane marks a missing cell with NaN, and an integer plane with the reserved sentinel its codec declares. Every release declares an encoding (§6a), so there is no plane whose marker has to be inferred. Stating it in terms of the codec rather than of NaN is what lets an integer `z` plane, which cannot hold NaN, express the same contract (ADR 0037, ADR 0038 §6).

A cell is **present** exactly when neither its Z nor its SE carries its plane's missing marker. Finiteness plays no part: **an infinite value is a value.** A release before format 0.2.3 may hold an SE above a `float16` plane's range as `+inf` beside a finite Z, and that cell is present, `observed` or `imputed` by its mask, in every reader of every layout (ADR 0070).

**An SE above 65,504 is not stored** (issue #338, ADR 0068). 65,504 is the largest value a `float16` plane holds; an SE above it -- `+inf` included -- is not a value this format stores: the SE is judged as stored (§7), after any SD standardisation (ADR 0084), so a source SE can pass or fail by its Analysis's `original_sd`. From format 0.2.3 a writer MUST NOT store such an association under any plan: a grid holds the cell missing, in Z and SE together (and so with no frequency and no imputed flag), a sequence holds no row for it, and `analyses.tsv` counts it per Analysis (`n_missing_se_out_of_range`, §7a). Whether an association is kept never depends on the plan: an `int8_residual` plane could hold such an SE as an exact exception, and does not. Nor does a kept SE decode above 65,504 under any plan: a residual code whose decoded value would read above it is an exact exception, held as its value (§6a). The rule is the writers' one gate (`storable`, ADR 0077), applied before an encoding is measured, and an SE encoder refuses such an SE rather than write it. A Reference Completion applies it to the cells it carries from its source and to its fills alike (§12). A release at 0.2.3 or later holding an SE above 65,504 is invalid (`associations.se_out_of_range`, §20); one before 0.2.3 holding `+inf` is reported (`associations.se_infinite`), as it is a value there.

State derivation:

| Z | SE | imputed mask | Association Status |
|---|---|---|---|
| present | present | false | observed |
| present | present | true | imputed |
| missing | missing | false | missing |

Invalid states:

- only one of Z or SE is missing — the two markers MUST agree;
- imputed mask is true while Z or SE is missing;
- a marker payload is non-canonical (for a float plane, a non-canonical NaN).

Builders and validators MUST reject invalid states. A builder rejects them through Association Admission (ADR 0072): a source row becomes a cell only through an Analysis's gate, which admits a row only with both a usable Z and a usable SE, and a writer handed cells from anywhere else checks them with `require_admitted`. Readers MUST refuse them: a query whose region holds an invalid cell fails, naming the component and the cell, rather than dropping it or reading it as missing (ADR 0070).

The imputed mask is:

- dense boolean or uint8 Zarr for Dense Reference-Completed grids;
- association-aligned boolean or uint8 Zarr for Ragged Reference-Completed sequences;
- chunk-aligned with Z and SE arrays.

The imputed mask is not a sparse offsets index like the top-hit significance index.

## 16. Dense Reference-Completed layout and overflow

A Hybrid Store Release physically nests its Dense Component as a Dense Store
Release at `<store>/dense` (§1), opened the same way as a standalone Dense
release, with `dense_to_shared.npy` mapping each Dense Component row to its
index in the Hybrid release's shared variant table. Its Ragged Overflow
Component lives in the Hybrid release's own `data.zarr/ragged`, alongside the
shared `variants.tsv.gz` and its sidecars covering both components (§4).

**From format 0.3.0 the Dense Component shares the Hybrid release's variants and
Analyses** (#472, ADR 0102 §4). Its envelope is `manifest.json`, `data.zarr/`,
`dense_to_shared.npy` and, when Reference-Completed, `index.sqlite` holding its
`completion_quality`. Its rows are the panel's, `0..n_panel-1`, the rows of its
grid, and:

- `dense_to_shared.npy` is `int32`, one entry per grid row, strictly ascending, each
  a row of the shared table. It is the component's whole variant identity: a reader
  names a Dense row's variant by the shared row the map gives, and a shared row's
  Dense row by a binary search of the map (a shared row it does not hold is off the
  panel);
- an identifier or a range is resolved once, against the shared sidecars, and its
  Dense rows reached through the map, so there is no second index to disagree with
  the first (#481, where a completed release's Dense copy had lost rsIDs and every
  `source_alid` the shared table kept);
- the Analyses are the root `analyses.tsv`'s. It counts each Analysis's Top-Hit
  Counts and `n_missing_se_out_of_range` over both components. Before 0.3.0 the
  Dense Component's own copy counted only its own, so it undercounted the first
  (issue #107); no reader needs its own count of the second, since a completion of a
  0.3.0 Hybrid carries the root's count into the completed root, which then counts
  what a completion of the 0.2.3 form counts.

A 0.2 Hybrid's Dense Component carries the full Dense envelope (§1) as well, a
copy of the shared table's rows and of the Analyses.

For Dense Reference-Completed releases:

- the dense matrix axis MUST contain only Reference Variant Set variants;
- observed off-panel associations MUST be stored in Ragged Overflow rather than discarded;
- Hybrid source-coordinate routing MUST treat allele-letter case as insignificant when
  matching a variant reference, without changing source effect-allele order or
  association sign/frequency orientation; conflicting case-folded source keys
  MUST fail rather than select a Dense target arbitrarily;
- the dense axis SHOULD be identical across Stores completed with the same LD Reference Panel.

Observed-Only Dense releases remain source-faithful and do not require an LD Reference Panel or panel-defined axis. A later Reference-Completed release MAY use a different dense axis defined by the LD Reference Panel.

Queries against Dense Reference-Completed releases with Ragged Overflow include overflow results by default for exact and range queries. Returned rows MUST expose Query Component when multiple components are involved.

## 17. Ragged Reference-Completed regions

For Ragged Cis-and-Signals molecular Stores, Reference Completion is bounded to retained regions:

- complete cis regions within existing cis boundaries;
- complete significant trans regions within existing trans-region boundaries;
- do not expand singleton suggestive associations, nor any other row kept for a
  reason other than a signal.

An Analysis's **regions** are its cis region, where it has a Trait position, and
its significant trans regions, each completed only within its own boundary: an
inclusive `[start, end]` on one chromosome, in the Store's assembly (GRCh38).
Their boundaries are the ones the Store's build recorded, in its **region table**,
`regions.tsv` (§1; ADR 0039 as amended, issue #430). It is the table a Release
Bundle's prep filter writes as `sidecars/sparse_regions.tsv`: a header row and
one row per region the build kept rows for, read by its `analysis_id`,
`region_id`, `region_kind`, `chromosome`, `start`, `end` and
`source_genome_build` columns; any other column is carried and not read.
`build-ragged-ssf --regions TABLE` refuses a table that breaks any rule below,
before building, and writes it into the Store with every row it holds, declaring it in the
manifest's `regions` entry by path and SHA-256 (§2). Reference Completion and the
Observed-View Check find it through that entry in the Observed-Only source, never
by the file alone, and refuse a source whose `regions.tsv` the manifest does not
declare, whose declared file is missing, or whose bytes are not the declared
SHA-256; the completed release carries the file unchanged, byte for byte, and the
entry with it. `validate` checks it when present or declared (§20). A Ragged
release whose Association Coverage is not `cis` and that declares no
`regions.tsv` MUST NOT be completed: it may hold significant regions
only the table records, which completing without it would leave out, so it is
refused and must be rebuilt with the table. A `cis` release without one is
completed on its Trait positions.

- `region_kind` is one of `cis`, `significant_trans`, `suggestive_trans` and
  `qc_panel`, and **only `cis` and `significant_trans` rows are completion
  regions**;
- the cis region's boundary is the table's `cis` row for the Analysis where it
  has one, and otherwise its Trait position plus or minus `cis_window_bp`
  (`complete-ragged --cis-window-bp`, recorded as
  `provenance.completion.cis_window_bp`);
- each significant trans region's boundary is a `significant_trans` row;
- `suggestive_trans` and `qc_panel` rows never make a region, however many of
  them fall in one LD block: they stay observed associations, and a QC panel's
  rows across the genome complete nothing;
- a row of any other kind, a row in another assembly than the release's, a row
  whose `start` is not between 1 and its `end`, a table missing a column above,
  and a row naming an Analysis the release does not hold are refused.

Not every Store Family has a Trait position: a family with no single encoding
gene per Analysis (small-molecule metabolomics, say) carries no
`trait_chr`/`trait_bp` at all, by design. Such an Analysis's regions come from
`regions.tsv` alone, so completing one the table says nothing of MUST be refused,
never completed by another rule; one the table gives no significant region is
carried Observed-Only.

An LD block is completed for an Analysis when its extent overlaps one of the
Analysis's regions. A region no block overlaps, in a gap of the panel or on a
chromosome it lacks, is completed nowhere; that is not refused, and the
completion names it by `region_id` in its summary (`regions_without_block`). The fit uses the Analysis's observations at all of that
block's panel variants, inside the regions or not, as `completion.block.run_block`
fits; only the panel variants inside a region's boundary become imputed or
missing rows, and observed rows outside every region stay exactly as the source
holds them. A block that holds only suggestive or QC-panel rows of an Analysis
gains it no row. Before issue #430, an Analysis with no Trait position was
completed in every block holding `impute.min_observed_points()` of its
observations, whole, and one with a Trait position in every block touching its
cis window, whole; both rules are withdrawn.

Each completed region contains:

- the full slice of Reference Variant Set variants within the region boundary;
- observed off-panel variants inside the same boundary;
- missing-marked statistic rows (§6a, §15) for reference-panel variants that were neither observed nor imputed.

Observed, imputed, and missing rows belong to the same ragged association sequence. Ragged Reference-Completed stores do not create a separate imputed-ragged component.

Observed off-panel variants inside a Ragged Reference-Completed region have ordinary observed Association Status and are not labelled as a separate Query Component.

## 18. Top-hit query contract

Top-Hit Queries return the associations whose two-sided p clears a threshold (|z| at least `z_critical(threshold)`), in `(analysis_index, variant_index)` order: the order a tier is stored in, not an order of significance. `limit` keeps the first rows of that order, after `observed_only`.

Dense, Ragged, Ragged Overflow, observed, and imputed associations have equal priority: the answer does not depend on storage component or Association Status.

Both Dense and Ragged components SHOULD provide Top-Hit Indexes using the same thresholds and result contract. The physical index encoding MAY differ by layout.

Each threshold tier stores `variant_index`, `analysis_index`, `z` and `se` in
`(analysis_index, variant_index)` order, and `analysis_offsets` addressing one
Analysis's slice; an index that predates `analysis_offsets` is still read (below). A 0.2
tier also stores `abs_z` (|z|, `float32`) and `p_value` (`erfc(|z| / sqrt 2)`,
`float64`); nothing but the validator read them, and it recomputes both from `z`,
so a 0.3.0 tier MUST NOT carry them (ADR 0102, #471). Every row's |z| clears the
tier's threshold: it is at least `z_critical(threshold)`. When the component can
report effect allele frequencies, the tier SHOULD also store decoded `eaf` as
`float32` in that identical order. Readers MUST use it when present and MUST
fall back to the component frequency plane when reading an older index. An
index without `eaf` therefore remains compatible; rebuilding the derived index
adds the fast path without changing the Store's association data or format
version.

Default thresholds:

```text
5e-8
5e-6
5e-4
```

Top-hit results from Reference-Completed releases include imputed associations by default. Observed-Only Query mode applies to Top-Hit Queries as well as exact and range queries.

**What each layout answers, and when** (#483, the owner, 24 Nov 2026). A Top-Hit Index is an accelerator; the answer at a stored tier is the same on every layout, and the layouts differ only in what they do for a threshold with no stored tier.

- **Dense** answers at a stored tier only and MUST NOT scan the grid: a scan reads every cell of an Analysis and takes hours on a release of OGS-00016's size. A `threshold` that is not a stored tier MUST raise an error naming the threshold and the stored tiers (`UnstoredThresholdError`); it MUST NOT return an empty answer.
- **Hybrid** answers at a stored tier only, because its Dense Component cannot scan; an unstored threshold raises the same error, so the Overflow never gives part of an answer. At a stored tier its Overflow reads its tier, or scans when the Overflow has no such tier, and `limit` applies to each component and then to the merge.
- **Ragged** answers an unstored threshold by scanning the CSR a window at a time, never a whole Analysis at once, against the same `z_critical` the index is built with, so a scan and a stored tier agree at the boundary.
- A stored tier **without `analysis_offsets`** answers one Analysis on every layout from that tier: a reader filters the tier's rows by `analysis_index`, and a Dense reader never scans the grid.
- An `analysis_id` the release does not hold MUST raise an error naming it (`UnknownAnalysisError`) on every layout; an empty answer is indistinguishable from "no association". Every other query that names an Analysis raises it too (§19).

### 18.1 Clumps of the 5e-8 tier (optional)

The **Clumps** of a Store Release are its 5e-8 tier clumped at build time, each Analysis
against its Assigned Ancestry's LD Store, by `opengwasdb.ld` (ADR 0106, issue #417). They are
one thing in two places: what `LDStore.clump` returns for an Analysis, an
`opengwasdb.ld.query.results.Clumps` (`opengwasdb/ld/query/results.py`), is what this
component persists, its `lead` as an offset and its `r` as a code, one row per tier row. They
are optional, derived and rebuildable: deleting them, with their manifest entry (§2) and
their two `analyses.tsv` columns (§7a), changes no other answer the release gives, and
they do not move `format_version` (§21.1). Only the 5e-8 tier is stored, in one Clumping
Configuration; any other tier or configuration is clumped when it is queried (#419). They are
a component of format 0.3.0 and of no earlier format, and they do not move it (§21.1, ADR 0106
§9). Under ADR 0102's rule they are *read*, an accelerator that also needs an LD Store outside
the release (§1.1, ADR 0106 §11), and they ship once a query reads them (#419). This section
says what the stored data mean; the Store Reader reads them (`TopHitTier.clumps`, *Reading*
below), and #419's Top-Hit Query is the first query to.

**Where.** In the 5e-8 tier's group, `p_5e_08` (`threshold_key(5e-8)`,
`opengwasdb/store_reader/top_hits.py`), of every component holding one:

```text
data.zarr/top_hits/p_5e_08/
  analysis_offsets, variant_index, …   the tier (§18)
  clumps/
    default/                           the one Clumping Configuration; attribute "clumps" (below)
      lead                             int32, one entry per tier row
      r                                int16, one entry per tier row
```

`default` is the only configuration a release may hold: another name under `clumps/`, or a
`clumps/` group without `default/`, is invalid. A Hybrid release holds the group in each
component with a 5e-8 tier, `<root>/data.zarr/…` for its Ragged Overflow and
`<root>/dense/data.zarr/…` for its Dense Component. Both arrays have the tier arrays' role and
chunking (`ArrayRole.TOP_HIT_INDEX`, `TOP_HIT_CHUNK_SIZE`), so one Analysis's entries are read
from the tier's own `analysis_offsets`. The tier writer replaces the whole tier group
(`write_index`), so a rewritten tier never keeps the Clumps of an earlier one. A release of a
format before 0.3.0 carries none.

**The clump slice.** An Analysis's clump slice is its rows of the 5e-8 tier in tier order; in a
Hybrid release, its Dense Component rows followed by its Ragged Overflow rows. An offset is a
position in that slice, from 0, so a Dense Component row may name a lead past its own rows.

**What is clumped, and how.** An Analysis is clumped when its `assigned_ancestry` is an entry of
the attribute's `ld_stores`; every other Analysis is not clumped. The step that writes the
component takes the Assigned Ancestry → LD Store mapping as an explicit input and has no default
of its own (ADR 0106 §2). For a clumped Analysis, every observed row of its clump slice is given
to `LDStore.clump` (`opengwasdb/ld/query/ldstore.py`, ld-store §9) against its ancestry's LD
Store, at r2 equal to that store's recorded `t_far` and kb 10,000 (W = 10,000,000 bp): a row
joins a lead at r̂² > r2 and d < W, plink2's edges.

- **Order.** |z| descending, ties by Store Variant Index ascending; never raw p, which
  underflows to 0 past |z| ≈ 38. A 0.3.0 tier stores `z` and no `abs_z` (§18), so |z| is taken
  from `z` through `top_hits.recomputed_abs_z_and_p` (`opengwasdb/top_hits.py`), the |z|
  `top_hits.threshold` recomputes. `clump` leads with the largest score and breaks
  ties by the LD Store's row order (`_component`, `opengwasdb/ld/query/clumping.py`), which
  differs from the Store's at a translated indel. So the step passes a score that is larger for
  a stronger row and has no ties: **n − rank**, where n is the rows given and rank 0 is the
  largest |z|, ties by Store Variant Index ascending. The score enters only that ordering, so
  for distinct |z| the leads are those of plink2's greedy on |z|. A score of the rank itself
  would lead with the weakest row.
- **Hybrid.** The Dense Component's tier `variant_index` is a panel row of its grid, and the
  Ragged Overflow's a row of the shared Variant Axis. The Dense Component carries no Variant
  Axis of its own (§16, #472), and the Store Reader resolves its rows through the shared axis
  and `dense_to_shared.npy` (`PanelVariantAxis`, `opengwasdb/store_reader/panel_axis.py`). Order
  and identity use the shared index, so a Dense Component row is mapped through
  `dense_to_shared.npy` (`dense_to_shared_path`, `opengwasdb/store_reader/hybrid.py`) first.
  "Store Variant Index" below always means the shared one.
- **Identity.** A row's ALID is its shared Variant Axis ALID, read from the ALID sidecar (§4;
  `VariantAxis.identity_by_indices`, `opengwasdb/store_reader/variant_axis.py`). A 0.3.0
  release spells an indel's ALID reference first (ADR 0079, ADR 0105), and LD Stores spell
  indels sorted, so it is translated to its sorted spelling through `opengwasdb.variants`
  (`normalise.sorted_alid_alleles`) before the lookup, and the sign of r flips for each of the
  row and its lead whose A1 the translation swaps.
- **Ambiguous identity.** An insertion and a deletion of one sequence at one position share a
  sorted spelling (`T:TA` is both `T>TA` and `TA>T`). A row whose variant's sorted spelling is
  also another shared Variant Axis variant's is ambiguous: it
  is never looked up, and is marked −3. What a sorted LD Store holds under a shared spelling it
  holds for one of the two, and it does not record which (`resolve_sorted_reversed_indels`), so
  every indel looked up by such a spelling is counted in its entry's
  `indel_rows_by_sorted_spelling` (ADR 0106 §6; #462 removes the exposure).
- **Refusals.** An LD Store that refuses the configuration (ld-store §9: a recorded `far_bp`
  under 10,000,000, say), or whose `reference_assembly` is not the release's, fails the step,
  naming the store; its Analyses are never silently left unclumped. So does a release of any
  format but 0.3.0, named by its `format_version`; one with no 5e-8 tier; and a
  Reference-Completed one whose 5e-8 tier has no `imputed` array.

**`lead`.** Per tier row:

| value | meaning |
|---|---|
| k ≥ 0 | the offset of the row's Clump Lead in its Analysis's clump slice; its own offset when the row is a Clump Lead |
| −1 | **absent**: an observed row of a clumped Analysis whose variant the LD Store does not hold (an Absent variant, ld-store §8), off its Variant Set or not a variant it spells; chromosome X, Y and MT rows of an autosomal LD Store among them |
| −2 | **imputed**: an imputed row of a clumped Analysis; never clumped, since an imputed z comes from the observed ones through LD |
| −3 | **ambiguous**: an observed row whose identity is ambiguous (above) |
| −4 | **not clumped**: every row, observed or imputed, of an Analysis that was not clumped |

The markers are decided in that order of precedence: −4, then −2, then −3, then −1. A row with
lead L ≥ 0 has, in its Analysis's clump slice: `lead[L] = L`; row L is observed; row L precedes it
in the order above, or is it; the two are on one chromosome and less than W apart; and, for a
member (L not its own offset), r̂² with its lead above the entry's `r2`. Every Clump Lead is a
row the LD Store holds; a row it does not hold is −1, **never its own lead**.

**`r`.** Per tier row, the row's signed r with its lead, **as the LD Store's own code**: r̂ =
code / `r_scale`, at the `r_scale` of the `ld_stores` entry its Analysis's `assigned_ancestry`
keys, never a release-wide scale. The code is the one the LD Store returns, a copy: `clump`
returns r = code / `r_scale`, which `REncoding.quantise` (`opengwasdb/ld/format/encoding.py`)
turns back into that code exactly, and it is never re-quantised at another scale (ADR 0097,
ADR 0090). It is signed to the release's A1 of the row and of its lead. A Clump Lead holds
+`r_scale` (r = 1). A row whose `lead` is negative holds −32768, the LD Store's reserved code,
which is never a correlation.

**Attributes.** The group's `clumps` attribute is a JSON object. Every key is required. A
Hybrid's two components each record their own rows' counts.

| key | type | meaning |
|---|---|---|
| `configuration` | string | `"default"` |
| `threshold` | float | `5e-08` |
| `tier_rows` | int | the rows of the tier the arrays are parallel to |
| `score` | string | `"abs(z)"`: \|z\| taken from the tier's `z` (*Order*, above) |
| `ties` | string | `"store_variant_index"` |
| `kb` | int | `10000` |
| `join` | string | `"r2_gt_distance_lt"`: r̂² > r2 and d < W (ld-store §9) |
| `markers` | object | `{"absent": -1, "imputed": -2, "ambiguous": -3, "not_clumped": -4}` |
| `ld_stores` | object | one entry per Assigned Ancestry clumped, keyed by its `assigned_ancestry` value (below) |
| `not_clumped` | object | the Analyses not clumped, by reason: `no_assigned_ancestry` (int, a blank `assigned_ancestry`) and `no_ld_store` (object: per `assigned_ancestry` value the mapping did not hold, the count of its Analyses, an int) |
| `opengwasdb` | string | the package version that wrote the component, the LD engine included |
| `created_at` | string | ISO 8601 UTC |

An `ld_stores` entry identifies its LD Store by what a reader can recompute from the store
itself; LD Stores have no release id (ADR 0106 §4).

| key | type | meaning |
|---|---|---|
| `name` | string | its `panel.id`, such as `hgdp1kgp-v2-EUR` |
| `kind` | string | `"ld_store"` or `"genotype_store"`: the root attribute its provenance was read from |
| `format_version` | string | its own `format_version` |
| `samples_sha256` | string or null | its `panel.samples_sha256`; null only where it records null (ld-store §7) |
| `provenance_sha256` | string | the SHA-256 of its root provenance record, as the UTF-8 bytes of `json.dumps(record, sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False)`: the identity |
| `location` | string | the path or URL the step read it from; information, not identity |
| `reference_assembly` | string | its own, equal to the release's |
| `n` | int | its `panel.n` |
| `k` | int | its `adjustment.k` |
| `t_far` | float | its recorded t_far |
| `t_partner` | float | its recorded t_partner |
| `near_bp` | int | its recorded `near_bp` |
| `far_bp` | int | its recorded `far_bp` |
| `r_scale` | int | its `encoding.r_scale`: a row's r is its code / this |
| `r2` | float | the r² clumped at, equal to `t_far` |
| `analyses` | int | Analyses clumped against it |
| `rows_clumped` | int | observed rows of this component given to `clump` |
| `rows_absent` | int | of those, rows marked −1 |
| `rows_ambiguous` | int | rows of this component marked −3 |
| `indel_rows_by_sorted_spelling` | int | of `rows_clumped`, indel rows looked up by a sorted spelling an insertion and a deletion share |

**Reading.** The Store Reader reads the Clumps, `TopHitTier.clumps` beside `TopHitTier.read`
(`opengwasdb/store_reader/top_hits.py`), which reads the tier they are parallel to: `lead`, `r`
and the `clumps` attribute, of the tier or of one Analysis's slice, refusing a group not laid out
as above by name (`MalformedClumps`). It reads them only where the release declares them:
`StoreRelease.top_hit_tiers` hands `TopHitTiers` the manifest's `clumps` entry, and a group the
manifest does not declare, or a declaration with no group, is refused by name, never read and
never silently ignored. The step's validation rules read through it (#418), and
#419's Top-Hit Query builds on it. #475 moves the Store Reader into the `ogquery` package; the Clumps follow the
reader. A reader reads `lead` and `r` only in a release that declares `clumps` (§2). A Clump
Lead's members are the rows whose `lead` is its offset. A row whose `lead` is negative belongs to
no clump and is reported as what its marker says, never as a lead of its own: an absent row is
not a locus the LD Store saw, and an Analysis marked −4 has no stored clumping at all, which a
query answers by clumping on the fly or by refusing, naming the reason (#419), never by returning
its unclumped rows as leads.

**Written last, and in place.** The component is written by one entry, the CLI command
`opengwasdb clump` (component `clumps`, layer 4, since it imports `opengwasdb.ld.query`; no
builder calls it). The Store Release Build in opengwas/opengwasdb-stores runs it after the build
and after any completion, passing its Assigned Ancestry → LD Store mapping
(opengwas/opengwasdb-stores#454). An existing 0.3.0 release gains it in place (#420, on the
Stores opengwas/opengwasdb-stores#498 rebuilds at 0.3.0, once a query reads the Clumps, #419;
§1.1), the one in-place addition that
carries Analytical Metadata (§21.4, ADR 0106 §10): the group, then `analyses.tsv` and
`overview.html`, then the manifest's `clumps` entry. Writing it again replaces all four, and
first removes the `clumps` entry from every manifest of the release, so a rerun interrupted
part-way leaves a group no manifest declares, which `clumps.declared` fails, rather than a
declaration of columns and arrays the new run has not finished writing. The
`release_id` and the `format_version` do not change. The command prints one JSON object of what it did: `store`, `seconds`,
`analyses` (in `analyses.tsv`), `clumped` (Analyses clumped), `n_loci_5e8` and `n_unclumped_5e8`
(totals over the clumped Analyses, `null` when none was clumped, never a 0 that would claim no
locus), `markers` (rows holding each marker, every component together), `not_clumped` (as the
attribute records it) and `ld_stores` (each mapped ancestry's entry, without its row counts). It
refuses, exiting 1 and naming the Store or LD Store and why, everything *Refusals* lists and an
LD Store that does not open or does not record a value its entry copies. A Reference Completion of a release that carries Clumps writes a
release without them, without the `clumps` entry and without the two columns, since it rewrites
the tier; the Store Release Build then runs the step again.

## 19. Query result contract

A query returns an association record (`opengwasdb.store_reader.associations.Associations`):
parallel arrays read as a mapping, keyed `variant_index`, `analysis_index`, `z`,
`se`, `beta`, `pval`, `eaf`, `n` (below) and `association_status` (ADR 0020,
ADR 0070, ADR 0104). A Dense grid stores no association at a missing cell, so a
Dense result omits them; a Ragged sequence stores a row for every attempted
pair, so a Ragged or Ragged Overflow result returns such a row as `missing` (§15).

`beta` and `pval` are derived, never stored, by one function of the record's
`z` and `se` (`opengwasdb.store_reader.stats.association_statistics`, ADR 0104),
on every layout and every query method alike:

| Value | Derivation | dtype |
|---|---|---|
| `beta` | `z * se`, on the Stored Effect Scale | `float64` |
| `pval` | two-sided, `erfc(\|z\| / sqrt(2))` | `float64` |
| `log10_p` | log10 of `pval`, computed in the log domain | `float64` |

- Where z or SE is NaN -- a missing association -- all three are NaN.
- Where SE is infinite (a release before format 0.2.3 may hold one; ADR 0068),
  all three are NaN, never infinite: such an SE is an error, so neither `z * se`
  nor the p of z alone is a value.
- `pval` is subnormal from |z| = 37.5 and 0.0 from |z| = 38.5, where p is
  below float64's range. `log10_p` stays finite and exact there (at |z| = 47.8
  it is -497.92), so rank and display by `log10_p`.

`log10_p` is not a key of the record. Resolved rows (`resolve_rows`) carry
`beta`, `pval` and `log10_p`, all three from the same function.

Query results SHOULD expose:

| Field | Required when |
|---|---|
| variant identity | always |
| analysis identity | always |
| z | always when available |
| se | always when available |
| beta | always, derived as `z * se` (above) |
| p-value | always, as `pval` derived from Z, with `log10_p` on resolved rows (above) |
| stored_effect_scale | always or through Analysis metadata |
| association_status | Reference-Completed releases |
| query_component | multi-component releases |
| eaf | when stored/requested |
| info | when stored/requested |
| sample size | when stored/requested |

A Ragged release with an `n` plane (§6a) adds `n` to **every** query result --
`float64`, NaN where the build was given no N for the pair, and present on an
empty result too, so "this release holds no sample sizes" and "no rows" never
read alike. A release without the plane never has the key. The CLI's resolved
output prints an `n` column immediately before `association_status` (`.` where
missing) only for such a release (ADR 0067).

`query --format json` prints that record, one JSON object per association, as
an array: `variant_index`, `analysis_index`, `z`, `se`, `beta`, `pval`,
`log10_p`, `eaf`, `association_status`, and `n` when the release carries it in
its integer form. `log10_p` rides beside `pval` because `pval` is 0.0 where p
underflows. The resolved TSV prints `beta` after `se`, and its `p` column is
`pval` to three significant figures, or `<1e-300` where `log10_p` is below -300.
The output is RFC 8259 JSON, so it never holds `NaN` or `Infinity` as a bare
token. A cell that is not there is `null`, and ±inf is the string `"Infinity"`
or `"-Infinity"`, because an infinite value is a value (§15) and a `null`
would be indistinguishable from the missing cell beside it (issue #394).

A `null` `eaf` therefore says the frequency is not available, not that the
association is: `association_status` says the association is `missing`. An
`eaf` is `null` wherever the cell holds no frequency -- on every cell of a
release with no association-frequency plane, except an imputed one, whose
`eaf` is the LD Reference Panel's where the release carries Reference EAF
(§9, ADR 0036).

Reference-Completed queries include imputed associations by default. Query APIs MUST provide an Observed-Only mode that excludes imputed associations.

**An Analysis the release does not hold is refused** (#474, the owner, 24 Nov 2026). Every
query that names an `analysis_id` -- `analysis()` (with or without an Indexed Variant
Subset), `lookup()`, `top_hits(analysis_id=...)`, `rho()`, `rho_row()` and `rho_matrix()`
-- raises `UnknownAnalysisError` naming it, on every layout, before reading anything; a
`lookup()` naming one unknown Analysis among known ones raises too. An empty answer would be
indistinguishable from "no association". `range_by_analysis()` names a region, not an
Analysis, and answers the Analyses whose Trait position falls in it.

**A Hybrid's Rho Matrix is its Dense Component's** (#496). `build-dense-rho` takes the
Hybrid release and writes `dense/data.zarr/rho`, estimated by the Dense builder over the
component's grid (through the shared Variant Axis from 0.3.0, through the component's own
Variant Table on 0.2), from its observed associations as the Association Reader reads
them: an imputed one is not observed, and a Reference-Completed component without its
imputed mask is refused (§15). Given the Dense Component -- by `dense/` or by any path
that resolves to it, a symlink included -- it refuses and names the Hybrid release to
give instead; it refuses a Ragged release. Neither `manifest.json` changes, as a Dense
release's does not. An Analysis with no observed association in the Dense Component, an
**Overflow-only Analysis**, has no Rho: the group records exactly these as
`overflow_only`, a list of distinct `analysis_index` values, ascending (`[]` when there
are none), read strictly: any other value is refused, not coerced. Membership is a fact
of the component, not of null support: an Analysis observed only at rows thinning drops
has no support and is a Dense Analysis. The packed triangle keeps its slots for every
Analysis, as a Dense release's does. `rho()`, `rho_row()` and `rho_matrix()` raise
`OverflowOnlyAnalysisError` naming one, after `UnknownAnalysisError`, never answering NaN
for it; a row or the whole matrix leaves them out. Without a Rho Matrix they answer
empty, as a Dense release's do. A Dense Component's Rho group whose record is absent or
malformed is refused by the reader, and fails `rho.overflow_only`, which also fails a
record that is not exactly the set the association scan finds.

Detailed Reference Completion Quality is not joined onto every imputed association by default. Query APIs MAY expose it when requested.

### Variant-only reads (issue #484)

A caller that wants variants, not associations, asks the query facade (every layout, every
readable `format_version`) for them, and does not read `variants_table()`, which builds
every variant in the release, or a Store file by name:

| Method | Answers |
|---|---|
| `variant_count()` | the number of variants in the release, an `int` (the Variant Axis's length) |
| `variants(identifiers)` | the rows for rsIDs or ALIDs, a `dict` keyed by `variant_index`, ascending |
| `variants_in_range(chromosome, start, end)` | the rows at a position in `[start, end]` on `chromosome`, keyed the same way: the rows `range_phewas` reads |

A row is a `variants_table()` row, spelt as it spells it (`alid`, `chromosome`,
`position`, `effect_allele`, `other_allele`, `rsid`); each method equals `variants_table()`
filtered to the rows asked. They resolve through the Variant Axis `lookup` and
`range_phewas` use, and add no index. An identifier the release lacks is absent, not an
error; an rsID naming several rows gives every row, as `lookup` does, and a cell naming
several rsIDs (`rs1;rs2`) is one name, whole (§4). A range ending before it starts, or on a
chromosome the release lacks, answers no rows; a chromosome the release cannot spell is
refused. From 0.3.0 none reads `variants.tsv.gz`, and none loads pysam or sqlite3.
`opengwasdb.store.query_digests` digests all three (`variant_reads`), so the rewrite's proof
and the golden contract (#474) compare them.

### The Store Reader contract (issue #474)

`tests/store_reader_contract/` is the contract every reader of format 0.3.0 is held to:
nine small 0.3.0 Store Releases (Dense, Ragged and Hybrid, each Observed-Only and
Reference-Completed) and, for each, what it answers -- every question
`opengwasdb.store.query_digests.questions` asks, rendered as digests and as readable rows
(`release_answers`). The refusals asked are `top_hits`, `analysis()` and `lookup()` of an
Analysis the release does not hold (`UnknownAnalysisError`, above), a range on a
chromosome no ALID can spell (`UnsupportedChromosome`) and, on Dense and Hybrid,
`top_hits` at a threshold with no stored tier (`UnstoredThresholdError`, §18). A refusal is
its type and the values it names (`fields`: the `analysis_id`; the `chromosome`; the
`threshold` and the `stored` thresholds); its message is informative. A reader in another
language compares the readable rows; the digests are the Python readers'. Every value is
compared exactly but `pval` and a resolved row's `log10_p`, which are the reader's libm
(`erfc`, `erf`, `log`, `log1p`) and differ between C libraries in the last ulp: they are kept
as numbers beside the digests, and compared, there and in the readable rows, to within four
float64 ulps (relative `4 * 2**-52`), NaN equal to NaN. The rewrite's proof, whose two sides
one build reads, compares them exactly. Its `VERSION`
names the bundle's version and the `format_version` its releases are; its README names what
each release exercises. Two of its states are ones the validator refuses at 0.3.0 and a
reader still meets, an infinite SE (above) and a tier without `analysis_offsets` (§18).
The bundle is read through the Store Reader alone, `open_release(path)` with no Variant
Table reader: a 0.3.0 release needs none, and its table refuses every read (§1.1, ADR 0105
§7). It loads none of pandas, scipy, pysam or sqlite3.

## 20. Validation rules

Validators MUST check at least:

- `manifest.json` contains required fields;
- `reference_assembly` is single-valued across the release;
- canonical variant identity is valid and unique within the Store Variant Table;
- signed statistics have been normalised to canonical allele orientation;
- `se >= 0` for all finite SE values, and, in a release before `format_version` 0.2.3, a
  **warning** — not a failure — when it holds an infinite `se`, naming the cell count and up to
  five Analyses holding one: such a release stored an SE above a `float16` plane's range as
  `+inf` beside a finite Z, so `z × se` is infinite although the source's beta was finite
  (issue #337); a query reads `beta` and `pval` there as NaN (§19, ADR 0104). From 0.2.3 a release holding any SE above 65,504 — `+inf` or an exact
  exception — **fails**: it stores no such association (§15, issue #338);
- from `format_version` 0.2.3, `analyses.tsv` (a Hybrid root's included) records
  `n_missing_se_out_of_range` as a non-negative integer on every row; below it the column may
  be absent or blank, and a value it holds is still a non-negative integer; and a Hybrid
  root counts at least what its Dense Component counts, Analysis by Analysis (§7a);
- Z and SE missingness is consistent, each read through its own plane's missing marker (§6a, §15);
- each statistic plane's dtype matches the `encoding` the manifest declares, and a plane with a declared `kind` this build does not implement fails the release rather than being decoded (§6a);
- every out-of-range Z cell has an entry in the plane's overflow table, and the table describes no other cell (§6a) — a lost entry is the *largest* |z| in the store, which is the one value that must never read as something plausible instead;
- Stored Effect Scale values are in the controlled vocabulary;
- Dense arrays match declared dimensions;
- Reference-Completed releases declare LD Reference Panel and Reference Completion Method;
- Reference-Completed Dense axes match the Reference Variant Set;
- imputed mask is consistent with Z and SE;
- Ragged Reference-Completed regions include all Reference Variant Set variants within completed boundaries;
- top-hit indexes, when present, are consistent with the **decoded** `z`, `se` and `eaf` planes — decoded, because an index built from raw codes and one built from values a query returns are indistinguishable until they are compared against the plane the query reads;
- the Clumps of the 5e-8 tier, when present, are declared, parallel to their tier and say what §18.1 says they say (ADR 0106). Each silent failure has its rule: a row dropped from the arrays (`clumps.structure`); Clumps left beside a rewritten tier, which cannot happen because every tier is written by `top_hits.write_index`, which replaces the tier group whole (`create_group(replace=True)`, `opengwasdb/store/arrays.py`) and deletes `clumps/` with it — on every Dense, Ragged and Hybrid build and completion — while a `clumps` manifest entry or columns left behind without the group fail `clumps.declared`; an absent row made its own lead, or a present one marked absent (`clumps.reclump`); an imputed row clumped, an ambiguous indel looked up, or a marked row given an r (`clumps.markers`); a lead weaker than its member, as raw p's underflow gives, or a member outside the window or under r2 (`clumps.greedy`); an Analysis with no LD Store counted as 0, or one with an LD Store left unclumped (`clumps.ancestry`); counts that disagree with the arrays (`clumps.counts`); the wrong LD Store, threshold or window recorded (`clumps.structure`, `clumps.reclump`); a group the manifest does not declare, as an interrupted step leaves, or Clumps on a release of a format before 0.3.0 (`clumps.declared`);
- `analyses.tsv` contains exactly one row per Analysis, covering every `analysis_index` referenced by `index.sqlite` (this is the one place SQLite cannot enforce the relationship as a foreign key, since `analyses.tsv` is a separate file);
- `regions.tsv`, when a Ragged release carries or declares one, is declared by the manifest's `regions` entry exactly when it is present, has the SHA-256 that entry names, parses as a region table and names only Analyses the release holds (§2, §17, issue #430);
- `index.sqlite` does not contain an `analyses` table, nor a `variants` table (§1, issue #128); from 0.3.0 it holds `completion_quality` and nothing else, and ships only where that table does (§1, ADR 0102);
- in the 0.2 series, `variant_alid_bytes.npy` holds one entry per ALID narrow enough to index, and no key in it is shared by two variants — a shared key is what silently truncating an over-wide ALID produced, and it makes one variant answer another's lookup (issue #127);
- from `format_version` 0.3.0, the ALID sidecar (§4) names every row of the Store Variant Table by that row's ALID, indexes every ALID, however long, and orders its keys by the full ALID bytes: a row it names wrongly answers another variant's lookup, and a row it leaves out answers its own with nothing;
- from `format_version` 0.2.2, every indel row of the Store Variant Table spells its ALID as the row records its orientation: `A1` is its `effect_allele` and `A2` its `other_allele`, and a lifted variant's `source_alid` spells the same allele first, a lift complementing an allele but never changing its length (§4, ADR 0079). An indel spelt sorted where its reference sorts second reads as the insertion of the same sequence; a 0.2.0 or 0.1.0 release, which sorts every indel, is not judged by this rule;
- `original_sd_method`, `ancestry_assignment_method` and `eaf_scope` values are in their controlled vocabularies (ADR 0029, ADR 0030, ADR 0036);
- an Analysis whose `original_sd_method` carries an SD magnitude records it in `original_sd`, finite and positive (§7a, ADR 0084, issue #366): a blank one is what a Ragged SSF build that stored its source's standard errors undivided wrote, and nothing else in a Store shows it;
- every rsid in the Store Variant Table is resolvable through the rsid search index (§1) — a release that carries rsids it cannot resolve fails silently at query time, so the check is on coverage, not merely presence (issue #109);
- `eaf`, when present, has the same shape/length as `z`/`se`, and its **decoded** values hold no finite value outside `[0, 1]` (ADR 0036) — decoded, because an `int8` residual plane's raw bytes are codes and checking those would pass every store while saying nothing about what a query returns;
- `variant_index` is **strictly increasing within every Analysis's segment** in a standalone Ragged or a Hybrid Overflow CSR (§11): an out-of-order segment makes the variant-side binary search answer with a plausible, wrong row, and a repeated one is a second association at a variant that Analysis already holds. It is checked on every release, not only on ones this build wrote. The check MUST be bounded and MUST NOT materialise the array: it reads the sequence in windows, the association scan's (§20.0, within one 1 GiB decoded budget), carries the preceding cell across a window boundary and resets at each Analysis boundary, so peak memory is the window and the per-Analysis offsets (`O(n_analyses)`), independent of the association count. The error names the first offending Analysis and says which of the two it found — a decrease, or a repeat;
- the variant-centric index MUST be present on every Ragged component (a Ragged Store Release or a Hybrid Overflow) in the 0.2 series, agrees with the Analysis-sorted component and is recorded in `provenance.ragged.by_variant`: its `offsets` array is `n_axis + 1` direct offsets spanning `[0, N)`, each variant holds exactly as many index rows as the component holds at that variant, `analysis_index` is non-decreasing within each variant's block and names a real Analysis, `eaf`/`imputed`/`n` are present on both sides or neither, and the cell contents match the Analysis-sorted planes (§11.1, ADR 0060);
- the `eaf` plane, its `eaf_baseline`, its exception table and its `eaf_reference` agree with the plan the manifest declares (§6a): a residual-coded plane has a baseline the length of its component's variant axis and an exception table, a plane of any other kind has neither, every exception cell has an entry and the table describes no other cell, and a component carrying `eaf_reference` declares it, carries an imputed mask, holds one entry per variant of its axis, and holds only frequencies in `[0, 1]`;
- the `n` plane is present exactly when the `encoding` block declares one, in the declared dtype, and only beside a `float16` `se` plane; its length equals the CSR's; every code is a count from 1 to `2³² − 2` or the missing code; the plane holds at least one N, since an all-missing plane reads exactly like a release without one; every Analysis holding an N declares `sample_size_scope=variant_level`; and the by-variant copy is present on both sides or neither and its sampled cells equal the CSR's (§6a, §11, ADR 0067). The read is windowed, never the whole plane;
- the `se` plane, its `se_coefficients` and its exception table agree with the plan the manifest declares (§6a): a residual-coded plane has finite `float32` coefficients of shape `(n_analyses, 2)`, a sorted duplicate-free exception table whose positions lie inside the plane and whose entries are exactly the cells marked `-127`, and a complete `eaf` plane beside it; a `float16` plane has none of those arrays, and carrying one is a failure rather than a harmless relic;
- `eaf_scope` (per Analysis) and the `encoding` block's `eaf` kind (per release) agree — a release declaring no plane while an Analysis declares `eaf_scope=association`, or the reverse, is rejected (§9, issue #106);
- each Analysis's completion metadata describes its own cells: an Analysis declaring a nonzero `completion_n_imputed_total` holds at least one imputed cell, one that holds imputed cells declares them, and a blank `completed_against` with a nonzero count is rejected. The comparison is categorical, not by count — the rollup counts what the LD blocks produced and the arrays hold what was written — and it is what an ancestry-match filter (ADR 0028) applied to one and not the other looks like from outside, including the `eaf_scope` derived from the count;
- every Analysis with `eaf_scope=association` carries EAF orientation evidence (§9.1, issue #115) **unless no component of the release declares an `eaf` plane**, in which case its frequencies are the panel's alone and there is no column to check: a blank `eaf_orientation` fails, since a frequency column that has never been checked is indistinguishable from one reported against the other allele; a recorded `failed` fails; `unverified` warns; and `analyses.tsv` and `manifest.json` MUST agree on the outcome recorded for each Analysis;
- the Zarr on-disk format matches `format_version`: a 0.1.0 release has Zarr v2 metadata (`.zarray`/`.zgroup`, `zarr_format: 2`) and no `zarr.json` anywhere; a 0.2 release (`0.2.0`, `0.2.1` or `0.2.2`) has Zarr v3 metadata (`zarr.json`, `zarr_format: 3`) and no v2 metadata anywhere, and every array uses the `sharding_indexed` codec. A half-converted release — one manifest, two formats — is invalid (§10a, ADR 0057);
- a 0.2 release is stamped the lowest `format_version` its features use, for every release and component, a Hybrid's outer release included: 0.2.2 when its indel ALIDs are spelt reference first (which its stamp declares and `variant_table.indel_order` holds it to), whether or not it carries `regions.tsv`; otherwise 0.2.1 when its manifest declares `regions.tsv`, and 0.2.0 when it does not (§21.3, issues #430, #381);
- an Indexed Variant Subset, when present, is self-describing and agrees with the release it indexes (§10b): the only entries under `data.zarr/indexed_subsets` are published subset groups — no staging or replacement directory, no unknown name, no non-group entry and no explicit empty group — and each group records a name, profile, encoding and source identity matching the release. It carries exactly the arrays its declared encoding and the release's Completion State define — an Observed-Only release's index has no `imputed`, a Reference-Completed release's must; a release declaring reference EAF carries `eaf_reference`, and one that does not carries none; `imputed` holds only 0 and 1; `variant_index` is stored `int32` and is non-empty, sorted ascending, unique and in `[0, n_variants)` — a zero-variant subset is not an index and is rejected even when its planes are zero-length; every array's inner chunk and shard match the format's `ArrayRole` policy (the layout is derived, never an attribute); its Analysis-major planes have shape `(n_analyses, n_subset_variants)` and the declared dtypes; `eaf_reference` holds one entry per indexed variant when declared; its side tables are sorted, unique and in range; Z and SE missingness agree within the index; no imputed cell is missing; the `imputed` mask and `eaf_reference` equal the release's own; and every **decoded** indexed Z, SE and EAF equals the authoritative primary-plane cell at that Store Variant Index. This is the **standalone** `validate` contract and it is exhaustive. The build's own staged publication gate is narrower and documented: exhaustively it checks only the enumerated structural rules -- self-describing identity and attributes, the exact array set, shapes and dtypes, the inner-chunk/shard layout, the full Variant Index (dtype, non-empty, sorted, unique, in bounds), counts and provenance, and the small side tables' structure and remapping (with the per-variant `eaf_baseline`/`eaf_reference`) -- while the `imputed` mask domain and agreement, Z/SE missingness, and decoded Z/SE/EAF values are compared over a documented deterministic, bounded, input-checksum-seeded sample (the endpoints of both axes, a spread of physical write-unit and inner-chunk boundaries, a spread of Analyses and seeded cells). The build records `validation_mode`, the sample strategy, seed and cell count, and its duration, and an isolated unsampled corruption is caught by the exhaustive standalone audit instead. A release with no `indexed_subsets` group stays valid and unchanged, and a reader MUST refuse a subset whose recorded source release, store, format, assembly or encoding does not match the release, before decoding any value (ADR 0061, issue #264, #266);
- the recorded layout matches the arrays: the Dense planes' `chunk_shape` and `shard_shape` in `manifest.json` `provenance.dense`, in the `index.sqlite` `dense` blob (0.2 only) and in the `data.zarr` root attributes each clip to the plane's dimensions to equal the plane's actual **inner** chunk, and name its actual shard, and the three compressors agree. A manifest that describes one shape over arrays of another is a silent failure class (§10a);
- the per-variant chunking rule applies to the **inner** chunk of a sharded array, not to the shard (§6, §10a);
- the Store Release directory contains no top-level file or directory beyond what its `primary_layout` (and, for Hybrid, its nested Dense Component directory) legitimately produces per §1/§10/§11/§16/§17 — the envelope is closed, not merely a set of required entries (issue #80). From 0.3.0 that envelope also depends on the Completion State: an Observed-Only release, and a Hybrid's outer release, carries no `index.sqlite` (§1, ADR 0102).

### 20.0 Validation Rules

Every check above is a named **Validation Rule** (ADR 0074). A rule judges one kind of
target:
- *release*: a Store Release, a Hybrid's outer release, or its nested Dense Component;
- *grid*: a Dense grid, a Dense Component's included;
- *sequence*: a Ragged release's association sequence, or a Hybrid's Ragged Overflow.

From format 0.3.0 a Hybrid's Dense Component carries no Variant Table and no
`analyses.tsv` (§16, #472). The `variant_table.*` rules and `sqlite.variant_aliases` do
not judge it; the rules that read its variants read the shared axis in its panel rows,
and its `envelope.required` names the shared search indexes it reads. The
`analyses.*` table rules judge the Hybrid's own `analyses.tsv`, its one copy of the
Analyses, as before 0.3.0 they judged the Dense Component's copy; and
`analyses.se_out_of_range_partition` has no component count to compare.

A rule may run after others. It is skipped, and recorded as skipped with the rules
that blocked it, when one of those failed or was skipped on its target or a target it
belongs to. A skip is not a pass. Whether a rule applies to a target is asked only
after its prerequisites passed. `fidelity.source`, which runs after every error rule
before it, is stopped only by one that failed. A *fold* is judged from one streamed read of its
target that every fold on it shares; a *check* reads what it needs. A fold may run after an
earlier fold on the same read: that prerequisite is decided when the read ends, the
folds are judged in this table's order, and whether the later fold applies is asked
before the read. A check may take part of what it reads from that streamed read instead
of reading it again (`encoding.eaf` the EAF exception table, `subsets.indexed` the
planes). `encoding.eaf` reports exactly what it would have reported reading the table
for itself. `subsets.indexed` takes the planes as one 64-bit digest per comparison unit,
under a key drawn at random once per run, and compares a unit cell by cell where the
digests disagree: a change to one value of one cell is always found, and a corruption
of several cells or planes in one unit is missed with probability about 2^-64 per unit,
whatever the key; no finding depends on the key. One listed
before the read's first fold is then decided when the read ends, and every rule that
runs after it is judged as if it had been decided first.

A Dense grid's read may be spread across forked workers (`validate --n-workers`, §20.1,
issue #315). Each band is measured wherever it is read and added in band order: every
fold's total, the first failure on the read, a plane reported undecodable, and each
riding check's share are the ones one process reaching the bands in order reaches, so
the report is the same at any worker count. The EAF exception table is still read once
a pass, by the process driving it, and the digest key is drawn there once and shared
with every worker. An association sequence's read, and every check of the Store
Variant Table, `analyses.tsv` and the envelope, run in one process.

**A release converted by `ogdb rewrite-release --convert-legacy`** (§21.4) records the
rules it does not meet in `provenance.converted_from.deviations`. Only three may be listed
-- `variant_table.indel_order`, `variant_table.source_alid` and
`side_tables.se_exceptions_rounded` -- each for the reason `manifest.converted_from` checks.
Each listed so reports what it judges an error as a **warning** that names the conversion
and says a rebuild from source fixes it; any other entry is not lowered and fails
`manifest.converted_from`; every other rule is unchanged, a rule that could not read
what it judges still fails, and nothing is skipped. A rebuild writes no `converted_from`.

`validate_store(path, rules={...})` runs the named rules and the rules they run after,
and refuses a name this table does not list. `ValidationResult.failed()` names the
rules that reported an error. `validate --format json` reports each finding's rule,
severity and target beside its message, skips included (§20.1). The names are
stable: a rule is renamed or removed only by a
change to this table, which the test suite holds to the registry, in its order.

| Rule | Judges | Kind | What it checks |
|---|---|---|---|
| `manifest.loads` | release | check | `manifest.json` loads, in a format this build reads; nothing else runs without it |
| `zarr.format` | release | check | the Zarr tree is in the on-disk format `format_version` names |
| `envelope.required` | release | check | every entry the layout requires is present |
| `envelope.closed` | release | check | no entry the layout does not produce is present |
| `manifest.coverage` | release | check | the declared association coverage is one the layout can carry |
| `manifest.format_stamp` | release | check | a 0.2 release is stamped the lowest `format_version` its features use: 0.2.2 when its indels are spelt reference first, whether or not it declares `regions.tsv`; otherwise 0.2.1 when it declares `regions.tsv`, 0.2.0 when it does not (§21.3); a release newer than 0.2.2 is not judged, and the rule warns that the package must be upgraded (§21.2) |
| `manifest.converted_from` | release | check | a release converted by `--convert-legacy` (§21.4) lists in `provenance.converted_from.deviations` only rules a conversion records, each for the reason its record gives: `variant_table.indel_order` from a `source_format_version` before `0.2.2`, `variant_table.source_alid` where `lifted` is true, `side_tables.se_exceptions_rounded` with its counts `se_exceptions_rounded` and `se_exceptions`; any other entry fails, and is not lowered |
| `sqlite.analyses_table` | release | check | `index.sqlite` holds no `analyses` table; not judged on a release that carries no `index.sqlite` |
| `sqlite.provenance_only` | release | check | from format 0.3.0, `index.sqlite` holds no table but `completion_quality`: no `metadata`, no `variant_aliases` (ADR 0102) |
| `variant_table.rows` | release | fold | the Store Variant Table has as many rows as the release counts variants: the rows of the ALID sidecar from format 0.3.0, the entries of `variant_offsets.npy` on an earlier release (#469) |
| `variant_table.alid_index` | release | fold | the 0.2 series' fixed-width ALID search index covers exactly the indexable ALIDs, collision-free; not judged on a 0.3.0 release, which carries the sidecar instead |
| `variant_table.alid_sidecar` | release | fold | from format 0.3.0, the ALID sidecar names each row by the ALID the table gives it, its offsets start at 0, rise with every row and end at its byte array's end, its order names every row once, each key is the first 24 bytes of its row's ALID, and the keys run in the strict order of the full ALID bytes (§4, ADR 0105); not judged on an earlier release |
| `variant_table.position_sidecar` | release | fold | from format 0.3.0, the position sidecar places each row at the chromosome and position the table gives it; each array has its dtype; its chromosome offsets start at 0, rise with every chromosome and end at the row count; each chromosome is named once, in the canonical chromosome order; and every position is at least 1 and never falls within a chromosome (§4, ADR 0105 §6); not judged on an earlier release |
| `variant_table.source_alid_sidecar` | release | fold | from format 0.3.0, the `source_alid` sidecar gives each row the state the table's `source_alid` and ALID give it (0 for a blank, `.`; 1 for its own ALID; 2 for another), and each state-2 row the table's text; each array is 1-d of its dtype, every state is 0, 1 or 2, the offsets number the state-2 rows plus one and rise with each, so text is held for those rows alone, and it holds one row per row of the table (§4, #470); a missing file fails `envelope.required`; not judged on an earlier release |
| `variant_table.rsid_index` | release | fold | every rsid in the table resolves through the rsid search index |
| `variant_table.rsid_rows` | release | fold | from format 0.3.0, the rsID index, inverted, names each row by the rsID the table gives it, and a row the table gives none by none, so `variants_table()` and resolved rows, which read the index, give the table's rsIDs (§4, #469); an rsID wider than the index's 24-byte slot fails it; not judged on an earlier release |
| `variant_table.sequence` | release | fold | rows are in `variant_index` order, one per canonical variant |
| `variant_table.representatives` | release | fold | the tabix index finds the rows the table holds, and on a release before 0.3.0 so does the offset sidecar; on 0.3.0, where no query reads the table or its tabix index, the tabix index is still checked as the convenience it is (§1.1), and the position sidecar, not offsets, places the rows (#469) |
| `variant_table.indel_order` | release | fold | from format 0.2.2, every indel row's ALID spells its alleles as the row records them: its `effect_allele` then its `other_allele`, and, for a lifted variant, its reference first as its `source_alid` does; not judged on a 0.2.1, 0.2.0 or 0.1.0 release, which sorts an indel's alleles |
| `variant_table.lifted_contig` | release | fold | no row on an alt, random or unplaced contig has a `source_alid` on another contig: a lift left no variant there (§4); an error from format 0.2.2, a warning on an earlier release, 0.9.0's 0.2.1 included, which #367 owns; a row with no `source_alid` is not judged |
| `variant_table.source_alid` | release | fold | a release whose manifest records a lift (a `provenance.lift` block with `n_lifted` above 0, or a `provenance.chain_file`, which a build writes as a default label whether or not it lifted) has at least one row with a `source_alid`; one blank row is no fault (a collision, or a row Reference Completion added from the panel), but a table with none holds no row's lift provenance (#449); a release in which every row is ambiguous under #85 (its sites name different origins) also fails, which only a toy fixture can be; an error on every `format_version`, a 0.2 release included -- every hosted release is rebuilt from source at 0.3.0; the rows are counted from the `source_alid` sidecar from 0.3.0, which `variant_table.source_alid_sidecar` holds to the table, and from the table before it; a Hybrid is judged on its shared table alone |
| `sqlite.variant_aliases` | release | check | every alias names a variant the table holds; skipped where there is no alias table; not judged on a 0.3.0 release, which carries none |
| `analyses.readable` | release | check | `analyses.tsv` parses |
| `analyses.retired_columns` | release | check | no retired column is present |
| `analyses.analysis_index` | release | check | one row per `analysis_index`, covering exactly `0..n-1` |
| `analyses.analysis_id` | release | check | no `analysis_id` names two rows |
| `analyses.completion_declared` | release | check | every `completion_n_imputed_total` is an integer, and an Analysis completed against no ancestry declares no imputed cells |
| `analyses.vocabularies` | release | check | each controlled column holds only its vocabulary's values |
| `analyses.original_sd_recorded` | release | check | an Analysis whose `original_sd_method` rescales records a finite, positive `original_sd`, at every `format_version` (§7a) |
| `analyses.sd_scale_standardised` | release | check | an Analysis with `stored_effect_scale=sd` has a rescaling `original_sd_method` or `declared_standardised`, at every `format_version` (§7) |
| `analyses.top_hit_count_columns` | release | check | the Top-Hit Count columns are present and non-negative integers |
| `analyses.se_out_of_range_count` | release | check | `n_missing_se_out_of_range` holds a non-negative integer on every row from `format_version` 0.2.3, a Hybrid root's included; below it, blank (unknown) or a non-negative integer (§7a) |
| `analyses.se_out_of_range_partition` | release | check | a Hybrid root's `n_missing_se_out_of_range` is at least its Dense Component's, Analysis by Analysis (§7a); from 0.3.0 the component counts none of its own, so nothing is compared (§16) |
| `regions.table` | release | check | `regions.tsv`, when present or declared, is declared by the manifest's `regions` entry, has its SHA-256, parses as a region table and names only Analyses the release holds (§2, §17) |
| `csr.arrays` | sequence | check | `offsets`, `variant_index`, `z` and `se` are present |
| `csr.lengths` | sequence | check | each parallel array, `eaf` included, holds one entry per association |
| `csr.analyses` | sequence | check | `analyses.tsv` has one row per segment `offsets` bounds |
| `csr.observed_only` | sequence | check | an Overflow holds no imputed array |
| `hybrid.dense_to_shared` | release | check | `dense_to_shared` against the shared variant axis: it names only rows of the shared variant table, in strictly ascending order, so no row twice; each fault is reported by itself (§16) |
| `hybrid.component` | release | check | the Dense Component opens, as a Dense release |
| `hybrid.plan` | release | check | both components declare one statistic encoding |
| `hybrid.coverage` | release | check | `dense_to_shared` against the Dense side: it names one shared row for each Dense Component row, and each Dense row's shared row holds its variant. From format 0.3.0 the Dense side is only the panel, the rows of its grid, as the component carries no variant of its own (§16, #472); before it, the component's Variant Table, whose representative rows' ALIDs are compared |
| `encoding.dtypes` | grid, sequence | check | each plane has the dtype its declared encoding stores |
| `encoding.per_variant_chunks` | grid, sequence | check | no per-variant array is chunked as one block |
| `encoding.eaf` | grid, sequence | check | the `eaf` plane, baseline, exception table and reference match the plan |
| `encoding.n` | grid, sequence | check | the `n` plane is present exactly when declared, in its dtype, beside a `float16` `se` |
| `encoding.se` | grid, sequence | check | the `se` plane's coefficients and exception table match the plan |
| `encoding.z` | grid, sequence | check | the `z` plane's overflow table matches the plan |
| `sample_size.length` | sequence | check | the `n` plane holds one code per association |
| `by_variant.present` | sequence | check | the variant-centric index is present in the 0.2 series; skipped in 0.1.0 without one |
| `by_variant.provenance` | sequence | check | the manifest records the index, and describes the index present |
| `by_variant.offsets` | sequence | check | the index's runs span `[0, N)` over the variant axis, and each column is `N` long |
| `by_variant.members` | sequence | check | `eaf`, `imputed` and `n` are on both sides or neither |
| `by_variant.layout` | sequence | check | each index array has its role's inner chunk and shard |
| `by_variant.analyses` | sequence | fold | every index row names one of the component's Analyses |
| `by_variant.order` | sequence | fold | within each variant's run, the rows' Analyses are non-decreasing |
| `grid.planes` | grid | check | `z` and `se` are present, and every plane spans the grid's axes |
| `grid.eaf_side_lengths` | grid | check | the per-variant `eaf` side arrays are the variant axis's length |
| `completion.mask` | grid, sequence | check | a completed component carries a mask of its shape, and a grid binary panel flags |
| `csr.segment_order` | sequence | fold | `variant_index` strictly increases within every Analysis's segment |
| `csr.shared_rows` | sequence | fold | an Overflow's `variant_index` addresses rows of the shared variant table |
| `hybrid.partition` | sequence | fold | no Overflow association is at a Dense Component variant |
| `by_variant.counts` | sequence | fold | each variant holds as many index rows as the sequence holds cells |
| `associations.decodable` | grid, sequence | fold | every block's SE decodes under the declared plan |
| `associations.se_infinite` | grid, sequence | fold, warning | names the cells of a `float16` `se` plane holding `+inf`, in a release before `format_version` 0.2.3 |
| `associations.se_out_of_range` | grid, sequence | fold | from `format_version` 0.2.3, no decoded `se` is above 65,504, `+inf` included (§15) |
| `associations.se_negative` | grid, sequence | fold | no finite SE is negative |
| `associations.markers_paired` | grid, sequence | fold | Z and SE are missing in exactly the same cells |
| `associations.markers_canonical` | grid, sequence | fold | every missing marker is the canonical one |
| `completion.mask_binary` | grid, sequence | fold | the imputed mask holds only 0 and 1 |
| `completion.imputed_present` | grid, sequence | fold | an imputed cell carries both Z and SE |
| `completion.off_panel` | grid | fold | no off-panel row is imputed |
| `completion.declaration` | grid, sequence | fold | each Analysis holds imputed cells exactly when it declares them |
| `completion.quality_counts` | grid, sequence | fold | for Analyses with at most one quality row, counts agree with stored cells; ancestry exclusion qualifies missing-cell comparison |
| `associations.eaf_range` | grid, sequence | fold | no decoded frequency falls outside `[0, 1]`; skipped on a component holding none, and behind `side_tables.eaf_exceptions` where the plane cannot be decoded |
| `side_tables.z_overflow` | grid, sequence | fold | the `z` overflow table describes exactly the overflow cells |
| `side_tables.eaf_exceptions` | grid, sequence | fold | the `eaf` exception table describes exactly the exception cells, and a plane that cannot be decoded is reported |
| `side_tables.se_exceptions` | grid, sequence | fold | the `se` exception table describes exactly the exception cells |
| `side_tables.se_exceptions_rounded` | grid, sequence | check | no more than 1% of the `se` exception table is a value a `float16` plane stores, which is what a plane rounded before its plan was chosen holds; an error from `format_version` 0.2.2 and a warning before it, 0.9.0's 0.2.1 included |
| `sample_size.codes` | sequence | fold | every `n` code is a sample size or the missing code, and some cell holds a size |
| `sample_size.scope` | sequence | fold | an Analysis holding per-association N declares `variant_level` scope |
| `top_hits.arrays` | grid, sequence | check | every tier carries the arrays a tier of its format is made of (`abs_z` and `p_value` too before 0.3.0), and from 0.3.0 neither of those two |
| `top_hits.structure` | grid, sequence | check | every tier has parallel arrays, sound offsets and ordered slices |
| `top_hits.threshold` | grid, sequence | check | every tier row's \|z\|, recomputed from its `z`, clears the tier's threshold (`z_critical`); a NaN z does not |
| `top_hits.abs_z` | grid, sequence | check | before format 0.3.0, every tier's stored `abs_z` and `p_value` are what its `z` implies, recomputed through `store_reader.stats` (`abs_z` within 1e-3; `p_value` within 1e-3 relative, and absolutely only within float64's smallest normal number, where an `erfc` flushed a subnormal p to 0.0); not judged on 0.3.0, which stores neither |
| `top_hits.held` | sequence | fold | every tier cell is an association the sequence holds |
| `top_hits.z` | grid, sequence | fold | every tier cell's Z agrees with the decoded plane and clears the cutoff |
| `top_hits.se` | grid, sequence | fold | every tier cell's SE equals the decoded plane's |
| `top_hits.imputed` | grid, sequence | fold | every tier cell's imputed flag equals the mask's |
| `top_hits.eaf` | grid, sequence | fold | every tier cell's EAF equals the decoded plane's |
| `top_hits.complete` | grid, sequence | fold | a tier holds every cell whose \|z\| clears its cutoff |
| `clumps.declared` | release | check | the manifest declares `clumps` exactly when a 5e-8 tier holds `clumps/default/`, in each component of a Hybrid alike; `default` is the only configuration; the release is 0.3.0; `analyses.tsv` has `n_loci_5e8` and `n_unclumped_5e8` exactly when it declares `clumps`. Catches the group an interrupted step leaves undeclared, columns without the arrays they count, and Clumps on a release of a format no clumping step writes |
| `clumps.structure` | grid, sequence | check | `lead` is `int32` and `r` `int16`, each as long as the tier and its attribute's `tier_rows` (a rewritten tier takes `clumps/` with it, `write_index`; this rule catches arrays copied in beside a tier of another length); the `clumps` attribute holds every key §18.1 requires, `kb` 10000, the markers §18.1 lists, and each `ld_stores` entry's `r2` equal to its `t_far` and its `reference_assembly` equal to the release's. Catches a dropped row, a tier rewritten under old arrays, and a threshold, window or assembly other than the configuration's |
| `clumps.markers` | grid, sequence | check | within each clumped Analysis, −2 exactly on the tier's imputed rows; −3 exactly on the rows whose variant is an indel sharing its sorted spelling with another variant of the shared Variant Axis; `r` is −32768 exactly where `lead` is negative, and within ±`r_scale` elsewhere. Catches an imputed row clumped, an ambiguous indel looked up, and a marked row given an r |
| `clumps.greedy` | release | check | every row with lead L ≥ 0 names a row L of its Analysis's clump slice (across both components of a Hybrid, so a release rule) with `lead[L] = L`, observed, preceding it by \|z\| (from `z`) descending then shared Store Variant Index, on its chromosome and less than 10,000,000 bp away; a lead's `r` is +`r_scale`; a member's (`r` / `r_scale`)² exceeds its entry's `r2`. Catches a lead weaker than its member, which ordering by raw p gives where p underflows, and a member outside the window or under r2 |
| `clumps.ancestry` | release | check | an Analysis's rows are all −4 exactly when its `assigned_ancestry` is blank or not a key of `ld_stores`, and its `n_loci_5e8` and `n_unclumped_5e8` are blank exactly then; `not_clumped` counts those Analyses by reason. Catches an Analysis with no LD Store counted as 0, and one with an LD Store left unclumped |
| `clumps.counts` | release | check | for each clumped Analysis, `n_loci_5e8` equals its rows whose `lead` is their own offset and `n_unclumped_5e8` its rows marked −1 or −3, both non-negative integers with `n_loci_5e8 + n_unclumped_5e8 ≤ n_hits_5e8`; a Hybrid's, in its one `analyses.tsv`, count both components' rows; each entry's `rows_absent` and `rows_ambiguous` equal the markers' counts. Catches counts that disagree with the arrays they count, imputed rows counted as unclumped, a Hybrid that counts one component, and more loci than hits |
| `clumps.reclump` | grid, sequence | check | runs only when `validate` is given the LD Stores (`--ld-store ANCESTRY=PATH`), and is recorded as not run otherwise, which is not a pass. Each given store's recomputed `provenance_sha256` equals its entry's; and for a seeded sample of clumped Analyses (at most 25 of those whose ancestry was given, drawn with the run's fidelity seed, `validate --fidelity-seed`, 0 unless given), clumped again from that LD Store as §18.1 says, `lead` and `r` agree row for row. The finding names the seed and the sample. It re-clumps with the step's own code (`opengwasdb.clumps.compute_clumps`), so it catches arrays changed after they were written, or clumped against another LD Store, not a defect in the step itself, which would write and re-derive the same wrong arrays; `clumps.greedy` and the tests' independent re-clump are the checks of the step. Catches the wrong LD Store, an absent row made its own lead, a present row marked absent, and a sign not flipped where a translated indel's A1 swaps |
| `by_variant.sample` | sequence | check | sampled index cells hold the codes and exact values the sequence holds |
| `completion.quality_table` | grid, sequence | check | the `completion_quality` table is complete and names real Analyses |
| `completion.n_missing_column` | grid, sequence | check | `analyses.tsv` carries `completion_n_missing_total` |
| `rho.members` | grid | check | a Rho Matrix records its provenance and carries its arrays |
| `rho.analyses` | grid | check | the matrix was estimated over the release's Analyses |
| `rho.lengths` | grid | check | `rho` and `n_null` hold one entry per pair of Analyses |
| `rho.values` | grid | check | rho is finite exactly where it has null support, and in `[-1, 1]` |
| `rho.variants` | grid | check | `variant_index` holds the variants the estimate used |
| `rho.overflow_only` | grid | fold | a Hybrid's Dense Component records exactly its Overflow-only Analyses, those the association scan finds no observed association for, as distinct ascending `analysis_index` values; a standalone Dense release records none |
| `layout.recorded` | grid | check | the three layout recordings describe the planes |
| `hybrid.recordings` | release | check | a Hybrid's outer recordings describe its Dense Component's planes |
| `subsets.indexed` | grid | check | every Indexed Variant Subset is self-consistent and value-equal |
| `eaf_orientation.readable` | release | check | the table the orientation rules read can be read |
| `eaf_scope.plan` | release | check | `eaf_scope` and the plan's `eaf` kind agree |
| `eaf_orientation.evidence` | release | check | every Analysis storing EAF carries orientation evidence, recorded alike twice |
| `eaf_orientation.unverified` | release | check, warning | names each Analysis whose orientation is `unverified` |
| `fidelity.unsupported` | release | check | a source is given only for a Dense release |
| `fidelity.source` | grid | check | sampled source associations equal the stored ones |

`completion.quality_counts` counts cells on the existing `ASSOCIATIONS` scan,
without another plane read. An Analysis with **one quality row** is judged against
the final planes: `completion_quality.n_imputed` equals the imputed mask's count,
and `n_imputed + n_missing` equals imputed plus missing panel cells. Dense off-panel
missing cells are excluded. With **zero quality rows**, both expected counts are
zero and the same comparisons apply, except that missing completion attempts are
not judged when recorded panel ancestry, Assigned Ancestry and blank
`completed_against` establish ancestry exclusion. Even then the imputed count must
be zero. Missing quality rows alone do not establish ancestry exclusion.

An Analysis with **more than one quality row** is not judged by either count
equality (owner ruling, 16 Nov 2026,
[#307](https://github.com/opengwas/opengwasdb/issues/307#issuecomment-6904046848)).
The table records block ids and attempt counts, not block-to-cell membership or
duplicate-resolution outcomes. Supported overlapping blocks can count the same
cell repeatedly, including fills collapsed or dropped under ADR 0072. The Store
cannot prove whether multiple rows describe distinct cells, so validation skips
their reconciliation, including apparently non-overlapping blocks. It cannot
detect lost fills or count transfers in these Analyses from quality counts alone.
No per-block comparison is made, and a block id is not interpreted as a genomic
interval or an external panel path. Malformed quality-table structure is reported by
`completion.quality_table`; `completion.quality_counts` also fails if its counts
cannot be read, including when selected on its own.

### 20.1 Validation and inspection CLI interface

Command-line validation (`ogdb validate`) and inspection (`ogdb info`) provide both human-readable text output (default) and machine-readable JSON output via `--format json` (issue #175, ADR 0042):

- `ogdb validate <store> --format json` outputs a single JSON object on `stdout`:
  ```json
  {"ok": true, "errors": [], "warnings": [], "findings": []}
  ```
  On failure (`ok=false`), it outputs the JSON object containing the recorded error strings on `stdout` and exits with a non-zero exit code. On success, `stderr` is empty.
  `findings` names the rule behind every record (§20.0, ADR 0074, issue #378): each
  item is an object of exactly `rule`, `severity`, `target` and `message`, all
  strings, where `severity` is `error`, `warning` or `skip`, `rule` is a name from
  §20.0's table, `target` is the part of the release the rule judged — `.` for the
  release, `data.zarr` for a Dense grid, `data.zarr/ragged` for an association
  sequence, `dense` and `dense/data.zarr` for a Hybrid's Dense Component — and
  `message` is the same string the rule's entry in `errors` or `warnings` holds,
  or, for a skip, the reason ADR 0074 records for it: the rules that blocked it, or
  the rule's own reason for having nothing to judge. A skipped rule appears once per
  target it could not judge, one record whose message names every rule that blocked
  it in the order it looks them up, so a release where a rule never ran is not
  indistinguishable from one where every rule passed. The order is deterministic:
  rule order, as §20.0's table lists the rules, then target order; a rule's failures
  and warnings on a target come before its skip of that target, and a rule is one or
  the other, never both. A rule that enumerates something the store holds unordered
  — a Zarr group's members above all — sorts it, so the tiers of a Top-Hit Index are
  named by threshold and then by name, strictest first (`p_5e_08`, `p_5e_06`,
  `p_5e_04`), a tier whose threshold will not parse last; and the nodes
  `zarr.format` walks are named by path. `ok`, `errors` and `warnings` carry the
  messages and the verdict they carried before this key, and `errors` and `warnings`
  remain the `message`s of the `error` and `warning` records in that order. Order is
  the one thing that changed: a release that named the same defects in a different
  order on each run names them in one.
- `ogdb validate <store> --ld-store ANCESTRY=PATH …` gives the LD Stores the Clumps were
  written against, and runs `clumps.reclump`, which is recorded as not run without them;
  `--fidelity-seed S` seeds its sample (§20.0, ADR 0106).
- `ogdb validate <store> --n-workers N` reads each Dense grid's association scan on N
  forked workers, one band a worker at a time, and reports exactly what one process
  reports: the same records, in the same order, text and JSON (§20.0, issue #315).
  `N` is at least 1, and 1, the default, reads every band in one process. A worker
  holds one band, which the decoded-band budget bounds (issue #254): a worker's cost is
  its private memory, beside its proportional share (PSS); its `VmHWM` also counts the
  pages it shares with the driver from the fork, which are the driver's. A failure of
  the worker pool itself -- a worker that dies, a fork the host refuses -- ends the run
  with an error naming the band whose result the pass was waiting for; no finding is
  reported about a read that never finished. A worker's failure to read its own band is
  a finding, as it is in one process.
- `ogdb info <store> --format json` outputs a single JSON object on `stdout` representing the store release manifest with decomposed structured encoding:
  ```json
  {
    "store_id": "...",
    "release_id": "...",
    "format_version": "0.2.2",
    "primary_layout": "dense",
    "association_coverage": "gwas",
    "completion_state": "observed_only",
    "reference_assembly": "GRCh38",
    "encoding": {
      "version": 3,
      "z": {"kind": "int16_fixed", "scale": 1024},
      "se": {"kind": "float16"},
      "eaf": {"kind": "absent"}
    }
  }
  ```

### 20.2 Phenotype-SD estimation CLI interface

`ogdb estimate-phenotype-sd <manifest.tsv> <out.tsv>` estimates the per-Analysis
phenotype SD used to standardise continuous-trait effects (§7, §7a; ADR 0029)
from a canonical `analyses.tsv` (ADR 0034), needing no caller-pre-extracted
arrays (issue #176):

- `MANIFEST_PATH` is read through the same column-alias resolver as every other
  manifest. It supplies `analysis_id`, `source_file`,
  `source_reader_capability`, `sample_size`, and the caller-chosen
  `original_sd_method`. Each row's capability resolves a `SourceReader` through
  the registry; an unknown capability is rejected naming the registered set.
- `--af-source source` estimates from the source's own `se`/`eaf`;
  `--af-source reference` (with `--af-reference`, a frequency table or LD panel
  directory, and `--af-reference-ancestry` for the latter) estimates from the
  source's `se` and the reference's A1-oriented frequency at each variant.
- The output TSV is keyed by `analysis_id`, in input order, and carries the
  shared-core `analyses.tsv` spellings so a caller merges rather than
  translates: `analysis_id`, `original_sd`, `original_sd_method`,
  `original_sd_dispersion`, `notes`. A missing or unusable `sample_size` writes
  `original_sd_method=unavailable` with a blank `original_sd` — an explicit
  unresolved outcome, never a fabricated value.
- Results are order-preserving and independent of `--n-workers`.

The command **computes** the number; it does not choose the method tier, the
tolerance, or whether a disagreement blocks a release. Those remain registry
acceptance policy per ADR 0029, and the manifest column is read, never inferred
from whichever arrays happen to be present.

### 20.3 Column Map: reading a tabular collection

A Source Collection whose files are tabular summary statistics may be read
through a **Column Map** (ADR 0063, issue #281): a TOML file declaring the
provider column for each field and the conventions its values follow. A
manifest row opts in with `source_reader_capability = opengwasdb.column-map`;
`resolve-analyses`, `build-dense-vcf`, `build-hybrid`,
`build-hybrid-from-catalogue` and `extract-variant-reference` take
`--column-map PATH|NAME`, where `NAME` is a
built-in map (`gwas-ssf`, `finngen-r13`). A built-in name that is also a file
in the working directory is refused as ambiguous.

- **Keys.** `column_map_version` (`1`), `name`, `[columns]` and
  `[conventions]` are required; `description`, `[optional_columns]` and
  `ignored_columns` are optional. Anything else is refused.
- **Fields.** `chromosome`, `position`, `effect_allele`, `other_allele`, `ref`,
  `alt`, `beta`, `odds_ratio`, `z_score`, `standard_error`, `frequency`,
  `p_value`, `ci_lower`, `ci_upper`, `confidence_interval`, `sample_size`,
  `rsid`, `variant_id`. A value is one column name or a list of spellings, of
  which a file carries at most one. `[columns]` must be present in every file,
  and `[optional_columns]` are read when present. `chromosome`, `position` and
  the allele convention's fields are required, and at least one of `beta`,
  `odds_ratio` and `z_score` must be declared. The field a column maps to is its
  effect type.
- **Conventions.** `missing_values`, `unmapped_columns`, `alleles`,
  `position_notation`, `chromosome_spelling` and `genome_build` are always
  declared. `frequency_allele`, `p_value_form`, `confidence_interval_separator`
  and `rsid_separator` are declared exactly when their column is. Every value
  comes from a closed vocabulary (ADR 0063 lists them). A value the reader
  cannot honour (`plink`, `neg_log10_p`, `other_allele`) is refused with its
  reason. Nothing is defaulted.
- **Reading.** The file is presented to the GWAS-SSF reader in GWAS-SSF's
  columns, and every undeclared column is renamed out of reach. These are
  failures, never skipped rows:
  - a declared column the file lacks;
  - a field the file names twice;
  - a column `unmapped_columns = "refuse"` did not expect;
  - a statistic that is neither a number nor a declared missing token;
  - an effect allele naming neither `ref` nor `alt`;
  - an interval that does not contain exactly one declared separator;
  - a row longer than the header.

  A shorter row has omitted trailing empty cells; it is padded at the trailing
  edge only, so those cells enter the declared missing-value rules exactly as
  explicitly empty cells do.
- **Agreement.** These are refused before any source is read:
  - a mapped row with no `--column-map`;
  - a `--column-map` no row reads through;
  - a row whose build is not the map's `genome_build`;
  - a row with no build of its own, no CLI fallback, and a `per_analysis` map.

  A mapped row's build is its own, else the CLI fallback, else the map's; no
  builder default applies to it.
- **Provenance.**
  - A mapped Resolution Record's fingerprint carries
    `resolution_config.column_map = {"name", "sha256"}`; an unmapped record
    omits the key, so its digest is unchanged.
  - A Dense or Hybrid store built through a map carries the same object as
    `manifest.json` `provenance.column_map`.
  - `sha256` is the checksum of the map file's bytes.
  - A checkpointed Hybrid build records the map (a built-in's name or a file's
    absolute path) and refuses to resume once it has changed.
  - The variant-reference artifact records no map.

### 20.4 Observed-view check CLI interface

`opengwasdb check-observed-view SOURCE TARGET --seed N --output verdict.json [--n-random 1000]`
(the **Observed-View Check**, issue #289, stores ADR 0037) compares an Observed-Only Dense
release `SOURCE` with the Reference-Completed Dense release `TARGET` completed from it, and
confirms every observed association survived completion unchanged. Reference completion
replaces its Store under the same id, so this check gates the swap.

- **Exhaustive axis check.** Every `SOURCE` variant is mapped to `TARGET` by its ALID, and the
  map must be complete and strictly increasing (order preserved). Both releases must list the
  same Analyses in the same order (compared by `analysis_id`, not by every column, since
  completion rewrites `analyses.tsv`). The map is exact: the mmap'd ALID index is used where
  it covers a row, and an ALID wider than its key (§1, issue #127), or a release with no index,
  is read from the variant table, so a long indel is mapped and never reported unmapped. A
  row recovered from the table is searched against both the other release's index and its
  unindexed rows, so either release, or both, may lack the index.
- **Sampled cell check.** Whole `SOURCE` chunk-rows (the inner chunk height of `SOURCE`'s `z`,
  across all Analyses), compared against the `TARGET` rows they map to. A chunk-row is chosen by
  one or more strata:
  - `random`: `--n-random` rows drawn uniformly with `numpy.random.default_rng(--seed)`; a
    grid with fewer chunk-rows is sampled whole;
  - `chrom_edge`: the first and last chunk-row of every run of one chromosome;
  - `final_partial`: the last chunk-row;
  - `writer_band_boundary`: the chunk-rows whose spans hold the `TARGET` rows either side of
    every row where the completion writer's band starts, whose height is derived from `TARGET`'s `z` by the writer's own rule
    (`completion_band_rows` over the shard height, or the inner chunk height when unsharded).
    Neither height is a constant of this check.

  Each chunk-row owns a **span** of `TARGET` rows. The spans partition the completed axis: a
  span starts after the previous chunk-row's last mapped row and ends at its own, the first
  starts at row 0 and the last runs to the end. Every `TARGET` row, inserted panel rows
  included, is therefore in exactly one chunk-row's span, and sampling every chunk-row examines
  every `TARGET` row. Per chunk-row, over its span: each source-observed cell (Z and SE both
  present, read through each plane's missing marker, §15) has identical decoded Z, SE and EAF
  (NaN equals NaN) and is not marked imputed; no
  source-missing cell is observed with `imputed == 0`; and no inserted panel row carries an
  observed cell with `imputed == 0`. Before cells are classified, every sampled `imputed` value
  must be 0 or 1 (`imputed_mask_invalid`) and every sampled cell, in `SOURCE` or `TARGET`
  and on inserted rows, must have Z and SE both present or both missing
  (`z_se_missingness_mismatch`, §20). An infinite value is a value: `inf` equals `inf`, and
  `inf` against a number is a `*_mismatch`.
- **Verdict.** One JSON object, written to `--output` (which must be in an existing directory)
  and printed on `stdout`. `seed` is required so every verdict is reproducible from its record.

  | key | meaning |
  |---|---|
  | `seed`, `n_random` | the sample's inputs |
  | `source`, `target` | `store_id`, `release_id` and `path` of each release |
  | `analyses` | `n_parent`, `n_child`, `identical` |
  | `axis` | `n_parent`, `n_child`, `parent_rows_unmapped`, `order_preserved`, and `parent_rows_unindexed` / `child_rows_unindexed` (rows read from the variant table) |
  | `geometry` | `parent_chunk_rows`, `n_parent_chunk_rows`, `completion_band_rows` |
  | `bands_checked`, `bands_by_stratum` | distinct chunk-rows; per stratum, overlap-inclusive |
  | `bands` | each checked chunk-row: `band`, `parent_rows`, `strata` |
  | `bands_with_mismatch` | chunk-rows with a nonzero failing counter |
  | `totals` | below |
  | `max_abs_diff` | `z`, `se`, `eaf`: the largest gap over cells where both sides are finite; a NaN against a number is counted in `*_mismatch`, not here |
  | `failures`, `passed` | the failing names, and whether there are none |
  | `seconds` | timing; informational |

  `totals` sums over the sampled chunk-rows. Informational fields never fail the check:
  - `cells_compared` (informational): sampled `SOURCE` rows × Analyses. It excludes inserted
    `TARGET` rows, which `inserted_rows` counts, so it is comparable across spans.
  - `parent_observed` (informational): the sampled `SOURCE` cells with Z and SE both present.
  - `inserted_rows` (informational): the inserted `TARGET` rows (not mapped from any `SOURCE`
    row) in the sampled spans.
  - `missing_now_imputed` (informational): source-missing cells that `TARGET` holds present
    (Z and SE both present) and flagged imputed, which is what completion is for.
  - `parent_rows_without_finite` (informational): sampled `SOURCE` rows with no observed cell.
  - `infinite_cells` (informational): the sampled cells, in `SOURCE` or `TARGET`, whose Z or
    SE is present and infinite. They are reported and never fail the check: a release before
    format 0.2.3 stored a source SE above the plane's range as `+inf` (issue #337).
  - `se_out_of_range_left_out` (informational): sampled `SOURCE` cells whose SE is above
    65,504 that `TARGET` holds missing and unflagged -- completion left them out (§12, issue
    #338). Only a `SOURCE` before format 0.2.3 completed into a `TARGET` at 0.2.3 or later has
    any; such a cell is set aside, not compared or counted as lost.
  - `se_out_of_range_miscounted` and `se_out_of_range_unaccounted` (failing), decided per
    Analysis over the whole sample, and explained in the verdict's `se_out_of_range` record:
    the first counts Analyses whose `TARGET` `n_missing_se_out_of_range` is not exactly
    both parts `TARGET`'s completion records in `provenance.completion.se_out_of_range`
    plus `SOURCE`'s count where that is known (a `SOURCE` before 0.2.3 has none: unknown,
    not 0, §7a; the record's `source_counts` is then null) -- or is blank, never read as
    0, or whose parts are not recorded, or holds a part that is not a non-negative integer; the second counts cells left out beyond the recorded
    `observed` part and, where the sample compared every `SOURCE` cell, cells of that part
    it did not find. A sample bounds the `observed` part from below, so a count inflated
    together with its part is caught only where the sample is whole; the `imputed` part is
    held by the arithmetic alone. A `TARGET` before 0.2.3 left nothing out, so every such
    cell it lacks counts as `observed_missing_in_child`.
  - Failing, each over the sampled cells: `z_mismatch`, `se_mismatch`, `eaf_mismatch` (a
    source-observed cell whose decoded value differs, NaN equal to NaN);
    `observed_marked_imputed`; `observed_missing_in_child`; `missing_became_observed`
    (a source-missing cell observed with `imputed == 0`); `inserted_observed_cells`;
    `imputed_mask_invalid` (an `imputed` value outside 0 and 1);
    `z_se_missingness_mismatch` (a cell, in `SOURCE` or `TARGET`, with only one of Z and SE
    missing); `non_canonical_marker` (a cell, in `SOURCE` or `TARGET` or on an inserted row,
    whose Z or SE holds a NaN other than the plane's canonical one, §15: an invalid state a
    reader refuses, and one `isnan` alone cannot tell from a missing cell — issue #373).

  A nonzero failing
  counter, `parent_rows_unmapped > 0`, an order that is not preserved, and differing Analyses
  each fail the check (`failures` names `parent_rows_unmapped`, `order_not_preserved`,
  `analyses_mismatch`, or the counter). After an axis or Analyses failure the sample is skipped
  (`bands_checked` is 0) and the verdict says why. **A counter for cells nobody inspected is
  `null`, never 0** (issue #375): in a skipped sample `totals`, `max_abs_diff` and
  `bands_by_stratum` are `null` throughout, so no zero in a failed verdict stands in for a
  clean census of an uncompared part. The keys stay, so a record's shape does not say
  whether the sample ran; `bands_checked` is 0 because it counts the chunk-rows read, and
  none were. A `null` tally neither fails a verdict nor passes one: the structural failure
  is what fails it.
- **Exit codes.** `0` pass; `1` the check ran and found a mismatch (the verdict is still
  written, and each failure is named on `stderr`); `2` refused: nothing was checked, so no
  verdict is written and the reason is on `stderr`. Refused are a mixed-layout pair, a layout
  the check does not support (it checks Dense, Hybrid and Ragged pairs), a `SOURCE` that is
  not Observed-Only, a `TARGET` that is not Reference-Completed, a release that cannot be opened,
  a `TARGET` with no `imputed` mask, a release whose `z` plane and variant axis disagree in length
  or are empty.
- **Hybrid scope.** A Hybrid pair (issue #295) is an Observed-Only Hybrid `SOURCE` and the
  `complete-hybrid` output made from it. Completion changes both components: it completes the
  Dense Component, folds each `SOURCE` Overflow association at a variant the LD panel added to
  the Dense axis into the Dense Component as an observed cell (`imputed == 0`), and rebuilds the
  Overflow on the completed shared axis without it (a **crossover**, issue #99). So the check
  compares the observed view across both components, by ALID:
  - *Axes, exhaustively.* The Dense Components' axes and the shared axes are each mapped as
    above, and every `TARGET` Dense row must be on `TARGET`'s shared axis. Every `SOURCE` Dense
    row must be mapped, but a `SOURCE` shared row need not be. Completion may leave out a shared
    row that no Analysis observes (stores#478), and such a row is **dropped**: it is counted
    (`parent_rows_unmapped`), and the first 1,000 are named (`dropped_alids`). Every Analysis
    is then read, and an association on a dropped row fails the check
    (`all_analyses.associations_on_dropped_rows`).
  - *Every crossover.* `complete-hybrid` records none, so they are derived from the axes: a
    `SOURCE` Overflow association whose ALID is a `TARGET` Dense row. Each must be an observed
    Dense cell, not marked imputed, whose decoded Z, SE and EAF equal the `SOURCE` value encoded
    and decoded with the `TARGET` Dense Component's own codec: Z, then EAF against that row's
    `eaf_baseline`, then SE against that EAF, as the fold writes it. A crossover is coded against
    the Dense Component's baseline, not the Overflow's, so bit-identity with `SOURCE` is not the
    rule; the round trip is exact, and a moved or altered value still differs from it. Every
    crossover is read, so the cost grows with the `TARGET` chunk-rows that hold one.
  - *The Dense Component, sampled.* The chunk-row sample above, over the two Dense Components,
    with the crossover cells on inserted rows set aside for the crossover check: they are the
    only observed, unflagged cells an inserted row may hold.
  - *The Overflow, sampled.* `--n-random` Analyses (all of them when there are fewer), drawn
    with their own `numpy.random.default_rng(--seed)`. Every association of each is matched with
    `TARGET`'s by shared-axis ALID, in both directions, and must have bit-identical decoded Z, SE
    and EAF. `SOURCE` crossovers are left to the crossover check, and `TARGET` associations at a
    Dense variant to `observed_in_both`.
  - *The Overflow, every Analysis.* `TARGET`'s Overflow holds `SOURCE`'s association count less
    that Analysis's crossovers, none of them at a `TARGET` Dense variant and none marked imputed.

  The verdict carries `"layout": "hybrid"`, then `seed`, `n_random`, `source`, `target` and
  `analyses` as above; `analyses.identical` also needs both Overflows to have one offset per
  Analysis.

  | key | meaning |
  |---|---|
  | `components.dense` | the Dense verdict's `axis`, `geometry`, `bands_checked`, `bands_by_stratum`, `bands`, `bands_with_mismatch`, `totals` and `max_abs_diff`, over the Dense Components; `totals.crossover_cells` (informational) counts the crossover cells set aside in the sampled spans |
  | `components.overflow` | `axis` (the shared-axis map, with `child_dense_rows_unshared`, `child_dense_order_preserved` and `dropped_alids`), `n_parent_associations`, `n_child_associations`, `analyses_checked`, `analyses`, `analyses_with_mismatch`, `totals`, `max_abs_diff`, `all_analyses` |
  | `crossovers` | `n` associations on `rows` Dense rows (null when the comparison was skipped), `totals`, `max_abs_diff` (`TARGET` against the round trip) and `reencoding_max_abs_diff` (the round trip against `SOURCE`; informational) |

  `components.overflow.totals` sums over the sampled Analyses, each side's cells counted as
  the Dense part counts them: `parent_associations`, `crossovers`, `child_associations`,
  `infinite_cells` and `se_out_of_range_left_out` (a `SOURCE` row `TARGET`'s Overflow lacks
  because completion left it out, §12) are informational; `z_mismatch`, `se_mismatch`,
  `eaf_mismatch` (a matched association whose decoded value differs, NaN equal to NaN),
  `observed_missing_in_child` (a `SOURCE` association that `TARGET`'s Overflow lacks),
  `missing_became_observed` (a `TARGET` association that `SOURCE` lacks),
  `z_se_missingness_mismatch` and `non_canonical_marker` fail. `components.overflow.all_analyses`
  covers every Analysis and all fail: `observed_in_both`, `imputed_cells`,
  `associations_on_dropped_rows` (`SOURCE` associations on a dropped shared row, which the
  sampled counters do not count again), and `analyses_count_mismatch` (Analyses whose count
  is not `SOURCE`'s less its crossovers and the rows completion left out, which a `SOURCE`
  before format 0.2.3 is read in full to find).
  `crossovers.totals` counts `infinite_cells` and `se_out_of_range_left_out` (crossovers whose
  SE is above 65,504, which completion did not fold) as informational, and the rest all fail,
  `left_out_but_observed` (such a crossover whose Dense cell is observed and unflagged) among
  them:
  `z_mismatch`, `se_mismatch`, `eaf_mismatch`, `observed_marked_imputed`,
  `observed_missing_in_child`, `z_se_missingness_mismatch` (a crossover cell, in the `SOURCE`
  Overflow or the `TARGET` Dense Component, with only one of Z and SE missing — the Dense part
  cannot see it, because a crossover is set aside there) and `non_canonical_marker` (likewise
  counted on both sides, and here or nowhere, for the same reason).
  The accounting is made twice: for the Dense Component, against its own counts, with the
  crossovers left out among the cells found (`components.dense.se_out_of_range`, its two
  counters in `components.dense.totals`), and for the root, against the root's counts, with
  the Overflow rows left out too (`se_out_of_range`, whose `totals` hold its two counters,
  named `root.` in `failures`).
  `failures` names each nonzero failing counter with the part that counted it
  (`dense.inserted_observed_cells`, `overflow.observed_in_both`, `crossovers.z_mismatch`), and
  `dense.parent_rows_unmapped`, `dense.order_not_preserved`, `overflow.order_not_preserved` (the
  shared axes), `overflow.child_dense_rows_not_on_shared_axis` and `analyses_mismatch`; after
  any of these last the comparison is skipped and every tally in all three parts — each
  `totals`, `all_analyses`, `max_abs_diff`, `reencoding_max_abs_diff` and `bands_by_stratum` —
  is `null`, as is `crossovers.n` and `rows` (issue #375). `dense.bands_checked` and
  `overflow.analyses_checked` are 0, because they count what was read and nothing was. Also
  refused: a Dense Component that is not Dense
  or not in its root's completion state, a `TARGET` Dense Component with no `imputed` mask, and
  an Overflow that cannot be opened or holds a variant index off its shared axis.

The check does not compare `TARGET`'s `source_release_id` with `SOURCE`'s `release_id`: a wrong
pairing fails the axis or cell checks.

#### Ragged scope

`check-observed-view SOURCE TARGET --seed N --output verdict.json --ld-panel DIR [--ancestry EUR]
[--n-random 1000]` also checks an Observed-Only **Ragged** release `SOURCE` against the
`complete-ragged` output `TARGET` (issue #296). A Ragged release has no grid to sample, and
completion rebuilds the union variant axis, so every comparison is by variant identity (ALID),
never by index. The exit codes, the required `--seed` and the verdict's `seed`, `n_random`,
`source`, `target`, `analyses`, `failures`, `passed` and `seconds` are those of the Dense check.

- **Axis.** The exact `SOURCE` -> `TARGET` ALID map of the Dense check; an unmapped source
  variant (`parent_rows_unmapped`) or differing Analyses fail the check and skip the sample.
  Order is not required: `axis.order_preserved` is reported, not failed, because the associations
  are compared by ALID.
- **Sample.** Whole Analyses, each compared completely: `--n-random` drawn uniformly with
  `numpy.random.default_rng(--seed)` (a store with fewer is sampled whole), plus the strata
  `non_admitted` (every Analysis the ancestry filter did not admit, up to 100, drawn with
  `default_rng((seed, 1))` beyond that), `largest` (the 5 with most associations), `empty` (up to
  5 with none) and `trait_less` (the first 5 without a Trait position). An Analysis is
  *not admitted* when its `TARGET` `completed_against` is empty (ADR 0028).
- **Per Analysis.** Each source-observed association (Z and SE both present, §15) is in
  `TARGET` with identical decoded Z, SE and EAF (NaN equal to NaN) and `imputed == 0`;
  `TARGET` holds no association with Z and SE both present and `imputed == 0` that `SOURCE`
  lacks (`target_observed_not_in_source`); every `imputed` value is 0 or 1; every imputed
  association lies inside one of the Analysis's **retained regions**
  (`imputed_outside_retained`), and so does every missing association completion added, one no
  source association maps to (`missing_outside_retained`); a non-admitted Analysis holds no
  imputed cell (`imputed_in_non_admitted`). Rows that are neither observed nor imputed (NaN,
  read through each plane's missing marker: panel positions inside a region that completion
  could not fill, or a source's own missing rows) are counted as `nan_rows`; an infinite value
  is not one of them.
- **Retained regions need the LD panel and the source's region table.** A release's arrays
  hold no region, only block ids and counts in `completion_quality`; the regions are the
  `regions.tsv` `SOURCE`'s manifest declares (section 17), and their rows the panel's.
  The check rebuilds each sampled admitted Analysis's regions as `complete-ragged` chose them,
  by the same call (section 17, ADR 0039 as amended, issue #430), from `SOURCE`'s
  `regions.tsv`: its `cis` and `significant_trans` rows, and, for an Analysis with a Trait
  position and no `cis` row, its Trait position plus or minus the manifest's
  `provenance.completion.cis_window_bp`. A region's rows are the panel variants of the blocks
  it overlaps that lie inside its boundary. `--ld-panel` (the directory `complete-ragged` was
  given) is therefore required for a Ragged pair, and `--ancestry` must equal
  `provenance.completion.ancestry` when given. There is no panel-free fallback. A
  `completion_quality` block the rebuilt regions lack is `quality_blocks_not_in_regions`, so a
  panel other than the one used is noticed. The verdict's `regions` names `SOURCE`'s
  `regions.tsv` and its SHA-256, or is `null`. `--ld-panel` for a Dense or Hybrid pair is
  refused.
- **Totals.** `observed_in_source`, `imputed`, `nan_rows`, `regions` (retained
  Analysis-by-block regions), `infinite_cells` (present-but-infinite cells, in `SOURCE` or
  `TARGET`, which never fail the check) and `se_out_of_range_left_out` (`SOURCE` rows whose SE
  is above 65,504 that `TARGET` does not hold, which completion left out, §12) are
  informational. A sampled Analysis is compared whole, so its rows left out are found
  exactly: `se_out_of_range_unaccounted` there also counts recorded ones not found, beside
  `se_out_of_range_miscounted`, both as the Dense check decides them (the verdict's
  `se_out_of_range` record). Failing: `z_mismatch`, `se_mismatch`,
  `eaf_mismatch`, `observed_marked_imputed`, `observed_missing_in_target`,
  `target_observed_not_in_source`, `imputed_outside_retained`, `missing_outside_retained`,
  `imputed_in_non_admitted`,
  `imputed_mask_invalid`, `z_se_missingness_mismatch`, `non_canonical_marker` (a cell, in
  `SOURCE` or `TARGET`, whose Z or SE holds a NaN other than the canonical one: an invalid
  state, not a `nan_rows` row — issue #373), `target_variants_unordered` (an Analysis's
  variant indices not strictly increasing), `quality_blocks_not_in_regions`,
  `se_out_of_range_miscounted` and `se_out_of_range_unaccounted`. `sample` lists
  each checked Analysis with its strata, admission, the ids of its retained `blocks` and counts, and `by_stratum` counts
  them. An unmapped variant or differing Analyses skip the sample: `sample.analyses_checked`
  is 0, and `totals`, `max_abs_diff` and `sample.by_stratum` are `null` throughout rather than
  0, since no cell was inspected (issue #375).
- **Refused (exit 2)**: a mixed-layout pair, a Ragged pair without `--ld-panel`, an LD panel
  with no chromosomes for the ancestry, an ancestry other than the one recorded, a `TARGET`
  completed against an ancestry other than the panel's, a `TARGET` with no completion ancestry
  or `cis_window_bp` recorded, a release that cannot be opened or decoded (a missing array
  group or EAF array included), a `SOURCE` `regions.tsv` `complete-ragged` would refuse, or
  none where `SOURCE`'s Association Coverage is not `cis`, and either `--ld-panel` or
  `--ancestry` for a Dense or Hybrid pair.
- **Residual-coded SE is compared exactly too.** SE is compared for exact equality, as the
  contract in section 12 states, whether it is `float16` or `int8_residual` (owner ruling,
  2026-10-22). Ragged completion used to refit `se_coefficients` over the completed Analysis,
  which re-quantised every observed SE; it now keeps the source's model and holds each observed
  cell exactly (section 6a, ADR 0078, issue #301). On three real Chen 2023 Analyses completed
  with `--cis-window-bp 1000000` against the HGDP+1kGP EUR panel, the refit moved all 135,596
  observed SEs (by a median of 0.09% and at most 0.14%) and the check failed with
  `se_mismatch`; since #301 none moves and the check passes.

### 20.5 Association TSV: building a Dense Store with `build-dense`

`ogdb build-dense OUTPUT --manifest MANIFEST.tsv --store-id ID --release-id ID
--admission-record DIR` builds a Dense Observed-Only Store from a build manifest
(issue #385, ADR 0076). The manifest is the one every builder reads: a row per
Analysis, with `analysis_id`, `source_file`, `stored_effect_scale` and
`original_sd_method`, and optionally the label, Trait Ontology, attribution,
`maf_threshold` and `info_score_threshold` columns. Each row's `source_file` is
that Analysis's **association TSV**, read as `opengwasdb.association-tsv`,
which a row that omits `source_reader_capability` takes. The Store's columns are
the manifest's rows in order.

- An association TSV holds associations only, one Analysis per file. It names
  its columns as `chromosome`/`chrom`/`chr`, `position`/`pos`/`base_pair_location`,
  `effect_allele`/`ea`/`a1`, `other_allele`/`oa`/`a2`/`non_effect_allele`,
  `se`/`standard_error`, `z`/`zscore`/`z_score` or else
  `beta`/`effect`/`effect_size`, and optionally `eaf`/`effect_allele_frequency` and
  `rsid`/`variant_id`. A `.csv` file is comma-delimited; `.gz` is read
  compressed. A header that names a column the manifest owns (an Analysis id,
  label, Trait Ontology, attribution, effect scale, `maf_threshold` or
  `info_score_threshold`) is refused.
- The format declares no reference allele (§5): its effect and other alleles
  need not be REF and ALT.
- A row that cannot be read (a required field missing, a number that is not
  one, equal alleles) refuses the run, naming the row. A row whose identity no
  ALID can spell (§4) is dropped by Association Admission and logged.
- A build whose sources spell one site in different case and name it with
  different rsids is refused, naming the routing key and both rsids (§4,
  issue #379).
- `build-dense` does not lift. Each row's source assembly (`source_assembly`,
  default `--reference-assembly`, which is `GRCh37` unless given) must be the
  assembly the Store records, and a row in another is refused.
- A row whose reader is not `opengwasdb.association-tsv`, a numeric INFO
  threshold (an association carries no imputation score), and an
  `original_sd_method` of `unavailable` are refused; an SD-rescaling method
  divides the Analysis's standard errors by its `original_sd`, as in
  `build-dense-vcf` (§7).
- The Python API's source-fidelity check, `validate_store(store, source=...)`
  (§20.0), takes the same build manifest. It compares each sampled source
  association with the Store after that standardisation, reads a source as the
  build does (a row the build dropped as malformed is not a failure), and
  reports `fidelity.source` for a bare association TSV, which names no Analysis,
  or a manifest with no rows. A source on another assembly has its samples
  lifted through the build's own lift, whatever the join finds, because only
  the chain says which of them a reverse-strand block re-oriented: such a
  sample's z is compared negated, as the build stored it (§5, #284, #486). The
  chain is the one the release records in `provenance.chain_file` (and
  `provenance.chain_sha256`, where recorded): a given chain with another label
  or other bytes is refused, and with none given the recorded one is used if it
  is pyliftover's built-in hg19→hg38 chain or a file on disk at the recorded
  path (matching its sha256, where recorded); otherwise the check is refused,
  naming the recorded chain and asking for one. A sample the release holds by
  `source_alid` where that chain places it nowhere, or on another row, fails
  the check, naming the chain.

## 21. Compatibility

`format_version` describes compatibility of the store representation. It does not describe biological data release version or source publication version. The **package version and `format_version` are independent**: a package release may change neither, one, or both. Which package reads and writes which format is recorded in the package's `CHANGELOG.md` compatibility table.

`format_version` is semantic versioning — `MAJOR.MINOR.PATCH`, three non-negative integers. A release whose `format_version` is not of that shape MUST be rejected (ADR 0041). That includes every pre-reset version (`0.1`, `1.0`, `2.0`, `3.0`), which a reader MUST refuse with an instruction to rebuild rather than any attempt to decode.

**The leftmost non-zero component carries an incompatible change.** Below `1.0.0` a format declares itself unsettled, so it is `MINOR` that breaks compatibility and `PATCH` that does not; from `1.0.0` it is `MAJOR`, and `MINOR` joins the compatible remainder. The components left of and including the breaking one are a release's **series**.

### 21.0 Before 1.0, a metadata or vocabulary change is applied in place

A format below `1.0.0` declares itself unsettled. Before then, a change to a
**manifest vocabulary or required metadata** — a value added, renamed or
re-spelled in a required field, with no array, encoding or required entry
touched — is applied by **editing the existing Stores' metadata in place**, as
one coherent step across this package, `opengwasdb-stores` and every published
Store. Such a change:

- **does not move `format_version`**;
- MUST be recorded in `CHANGELOG.md`, naming the old and new value, so a reader
  of an old Store knows what it will now be reported as;
- MAY leave an older package unable to read a release written after it, because
  a closed vocabulary is refused by name rather than guessed at (§21.2). Below
  `1.0.0` that refusal is the accepted consequence of one coherent vocabulary,
  not a compatibility break in the sense of §21.1 — which is why the in-place
  edit, not a version bump and a rebuild, is the migration.

This rule exists because the alternative was tried first: ADR 0064 §5 required
the rename of `association_coverage`'s `full` to `gwas` without a version bump,
and had to justify it against §21.1 and §21.2's "MUST accept". The owner's
decision of 23 Oct 2026 is that one vocabulary across all three repositories is
worth more than an old package reading a new release, and that this rule is
what says so. From `1.0.0` the usual rule returns: a vocabulary change is
incompatible and moves the series (§21.1), because a released format is a
contract with readers outside this project.

An in-place metadata edit still follows §21.4: it is a **Provenance Amendment**
only when it touches `provenance`; a change to a required field is a recorded,
reviewed edit of the release's `manifest.json`, made as part of the same
coherent step, and every edited Store is re-validated afterwards.

### 21.1 What breaks compatibility, and what does not

The distinction is defined by **what a reader that does not know about the change would do**, not by the size of the change:

- **Incompatible** (moves the series) — a reader that does not know about the change would *misinterpret* the store: the encoding of an existing array changes; a required entry is removed, renamed, or restructured; the meaning of an existing field changes while its name and type do not. **Before `1.0.0`, a change confined to a controlled vocabulary is the §21.0 exception**: it is applied by editing existing Stores' metadata in place and does not move the version.
- **Compatible** (moves the remainder) — a reader that does not know about the change still reads correctly everything it already knew, and the new thing is discoverable through the manifest: a new optional array, index, or sidecar; a new `analyses.tsv` column; a new `provenance` block.

| change | bump (at `0.x.y`) |
|---|---|
| a new optional array (e.g. `eaf`, ADR 0036) | patch |
| a new `analyses.tsv` column | patch |
| a new optional, manifest-declared sidecar (`regions.tsv`, 0.2.1, issue #430) | patch |
| an indel's ALID spelt reference first, its statistic signed for that allele (0.2.2, issue #381, ADR 0079) | patch |
| `analyses.tsv`'s `n_missing_se_out_of_range`, and no SE above 65,504 stored (0.2.3, issue #338, ADR 0068) | patch |
| the Clumps of the 5e-8 tier, with `n_loci_5e8` and `n_unclumped_5e8` (§18.1, ADR 0106, issue #417) | none: derived and rebuildable, below |
| a required column removed or renamed (ADR 0034) | **minor** |
| the encoding of `z`, `se` or `eaf` changes (ADR 0037) | **minor** |
| the fixed-width ALID index replaced by the variable-length ALID sidecar (0.3.0, issue #467, ADR 0105) | **minor** |
| the position sidecar required (0.3.0, issue #468, ADR 0105 §6) | **minor** |
| `variant_offsets.npy` removed, and no query reading the Variant Table (0.3.0, issue #469, ADR 0105 §7) | **minor** |
| the `source_alid` sidecar required (0.3.0, issue #470, ADR 0105 §8) | **minor** |
| `index.sqlite`'s `metadata` and `variant_aliases`, an Observed-Only release's `index.sqlite`, and the Top-Hit tiers' `abs_z` and `p_value` removed (0.3.0, issue #471, ADR 0102) | **minor** |
| a Hybrid Dense Component's own Variant Table and `.tbi`, ALID, position and rsID indexes, `analyses.tsv` and `overview.html` removed: it reads the shared ones through `dense_to_shared.npy` (0.3.0, issue #472, ADR 0102 §4) | **minor** |

An **Indexed Variant Subset** (§10b, ADR 0061) is not one of those compatible
additions: it is a rebuildable, non-authoritative acceleration artifact that can
be deleted without changing any existing query answer, so it may be added or
removed in place and does not move `format_version`. That narrows ADR 0038 and
ADR 0041, whose "optional array, index, or sidecar" means optional content a
reader may need to interpret authoritative data.

The **Clumps** of the 5e-8 tier (§18.1, ADR 0106 §9) are close to that class: the
release's own tier clumped by a named LD Store, which a query reproduces row for
row by clumping on the fly, so deleting them with their manifest entry and their
two `analyses.tsv` columns changes no other answer. They differ from a subset in
needing that LD Store to rebuild, which is why its identity is recorded, and in
carrying Analytical Metadata, which §21.4 admits in place. They are an optional
component of 0.3.0, discovered by the manifest's `clumps` entry (§2), added in place
to a 0.3.0 release, and they do not move `format_version`: a clumped and an
unclumped 0.3.0 release are both 0.3.0. No earlier format carries them. A package
that knows 0.3.0 and nothing of them reads every association and column it knew,
correctly, and ignores the entry and the two columns (ADR 0034's superset rule). Its
`validate` passes them unjudged, since the closed envelope (§1) judges only a
release's top-level entries and the Top-Hit rules only the tier arrays they name. Its
completion writes a release without them (§18.1), which the Store Release Build
clumps again. ADR 0106 §9 gives the evidence, and the cost of a 0.3.1 instead
(`docs/store-format-compatibility.md`).

### 21.2 Reader obligations

For a release at `M.m.p`, a reader that fully understands that release series up to remainder `k`:

| condition | behaviour |
|---|---|
| series unknown | MUST reject |
| series known, remainder `<= k` | MUST accept |
| series known, remainder `> k` | MUST accept, and SHOULD warn |
| not `MAJOR.MINOR.PATCH` | MUST reject |

Accepting a newer remainder follows from the definition of a compatible change: if an older reader could not read it correctly, the change was incompatible and was classified wrong. The warning is what makes such a misclassification visible instead of silently returning partial data.

This build reads three series, `0.1` (Zarr v2, readable but no longer written), `0.2` (Zarr v3 with sharding, §10a, what every builder wrote from #247 to #467), and `0.3` (what every builder and completion writes since epic #450, #467-#472). The 0.2 series has four releases, `0.2.0`, `0.2.1`, `0.2.2` and `0.2.3` (§21.3), and `0.1.0` is the only 0.1 release; another remainder in either series is a decision, not an accident. A 0.2 release is a different physical layout, not a different decoding: a reader decodes a 0.2 plane exactly as §6a says and gets the same values as the 0.1 release it was converted from.

`0.2.2` moves the remainder, not the series. A reader that knows only `0.2.0` or `0.2.1` reads a `0.2.2` release's data as written — an ALID is a string it looks up as given, and a statistic is signed for the ALID's `A1` in all three — and warns that the release is newer. What such a reader does not know is how a `0.2.2` builder spells an indel: a completion run by it would spell its panel's indels sorted, beside the release's reference-first deletions. Only a build that knows `0.2.2` completes one. Nor does it know which stamp a `0.2.2` release's features give: package 0.9.0's `validate` fails every `0.2.2` release with one error, `release is stamped 0.2.2, but a release carrying no region table is 0.2.0` (`… carrying regions.tsv is 0.2.1` with the table). The remedy is to upgrade the package, never to re-stamp the release: re-stamped, it passes 0.9.0's `validate`, and 0.9.0 completes it. So this build does not judge the stamp of a release newer than every version it writes: `manifest.format_stamp` warns that the package must be upgraded (§20).

`0.3.0` moves the series. A 0.2 reader looks up an ALID in `variant_alid_bytes.npy`, which a 0.3.0 release does not carry: it would find no ALID index, and answer every ALID lookup from a scan, or not at all, while the release read as one it fully understood. So a package without the 0.3 series refuses a 0.3.0 release by name, as ADR 0041 requires (`… declares format_version='0.3.0', a release series this build does not implement`); a 0.3 reader reads a 0.2 release's fixed-width pair as before.

`0.2.3` moves the remainder too. A reader that knows only `0.2.2` reads a `0.2.3` release's data as written: an association the release left out for an SE above 65,504 is a missing cell or an absent row, as any other is, and `n_missing_se_out_of_range` is a column it does not know, which it ignores (ADR 0034's superset rule). What it does not know is that such a release holds no SE above 65,504 and that its `analyses.tsv` counts the ones it left out; a completion run by it would carry `+inf` through and not count it, so only a build that knows `0.2.3` completes one. It warns that the release is newer.

A reader meeting a feature it does not implement — an encoding kind, an index type, or a value in a controlled vocabulary it does not know — MUST reject the release rather than guess or fall back. Before `1.0.0` that refusal is exactly what a §21.0 vocabulary change produces in an older package: the "MUST accept a newer remainder" rows above govern a release whose *content* a reader understands, and §21.0 is the pre-release substitute for the version bump those rows would otherwise require.

Future format versions may add fields, arrays, or indexes, but MUST preserve explicit manifest-based feature discovery.

### 21.3 Writing

**A build stamps each release the lowest `format_version` whose features it uses**, and reads every series it implements (the owner's decision of 2026-11-11, issue #430, amending ADR 0038 §3). Within the 0.2 series the releases are written by the same encoders, so a 0.2.0 release is a 0.2.1 release without its optional file, and the lowest version is the true one: a reader that knows only 0.2.0 reads every release that uses nothing newer without a warning, and is warned (§21.2) by exactly the releases that hold something it does not know. One function decides the stamp (`format_version_for`), and every writer stamps by it: the builders, Reference Completion, the converter. A release stamped other than its features give disagrees with itself; `validate` fails it and completion refuses it. A release newer than every version a build writes is not judged by that build's rule, which is a later package's to state: `validate` warns that the package must be upgraded, and completion refuses the release as a format it cannot write (§21.2). There is no facility for writing an older format: a store that needs to be in an older format already exists in that format.

| `format_version` | adds | stamped on |
|---|---|---|
| `0.1.0` | the reset (ADR 0041): Zarr v2 | no release this build writes |
| `0.2.0` | Zarr v3 with sharding (§10a, ADR 0057) | a release this build converts from `0.1.0`, which carries no `regions.tsv` and sorts its indels |
| `0.2.1` | a Ragged release's optional `regions.tsv`, declared by the manifest's `regions` entry (§1, §2, §17; issue #430) | no release this build writes: package 0.9.0's, for a Ragged release carrying one |
| `0.2.2` | an indel's ALID spelt reference first (§4, ADR 0079; issue #381), `regions.tsv` still optional | no release this build writes: package 0.11's, and earlier builds since #381 |
| `0.2.3` | `analyses.tsv`'s `n_missing_se_out_of_range` on every row, and no association whose SE is above 65,504 (§7a, §15; ADR 0068, issue #338), on 0.2.2's features | no release this build writes: every build and completion from #338 to #467 |
| `0.3.0` | the variable-length ALID sidecar in place of the fixed-width ALID index (§4; ADR 0105, issue #467), the position sidecar a range is answered from (§4; ADR 0105 §6, issue #468), and no `variant_offsets.npy`: no query reads the Variant Table (§4; ADR 0105 §7, issue #469), the `source_alid` sidecar (§4; ADR 0105 §8, issue #470), on 0.2.3's features; `index.sqlite` only beside `completion_quality`, and no `metadata`, `variant_aliases`, or tier `abs_z` and `p_value` (§1, §18; ADR 0102, issue #471); a Hybrid Dense Component without its own copy of the shared variants and Analyses, read through `dense_to_shared.npy` (§16; ADR 0102 §4, issue #472) | every release this build builds, completes or rewrites from `0.2.3` (§21.4) |

A package before 0.2.1 reads a 0.2.1 release, warned that it is newer than it fully understands (§21.2), and ignores the `regions` entry; its `validate` refuses `regions.tsv` as an entry outside the envelope, and its completion refuses the release, whose format it reads but cannot write (§21.4), so it cannot complete one outside its regions or drop its table (`docs/store-format-compatibility.md`). A package before 0.2.2 reads a 0.2.2 release the same way, warned, and its completion refuses it too, so it cannot spell its panel's indels sorted beside the release's reference-first ones. Package 0.9.0's `validate` also fails a 0.2.2 release, on its stamp rule (§21.2): upgrade the package, do not re-stamp the release. A package before 0.2.3 reads a 0.2.3 release, warned, and its completion refuses it. Its `validate` does not judge the newer stamp: packages 0.10.0 to 0.12.0 warn that the package must be upgraded (§21.2), and 0.9.0, whose stamp rule judges every 0.2 release, fails it, as it fails a 0.2.2 one (`docs/store-format-compatibility.md`). The remedy is again to upgrade, not to re-stamp.

**Since #467**, every builder and Reference Completion write `0.3.0` (`CURRENT_FORMAT_VERSION`): `write_variant_axis`, which every build and completion path calls, writes the ALID sidecar and, since #468 and #470, the position and `source_alid` sidecars, so a completion of a `0.2.2` or `0.2.3` source is `0.3.0` too. 0.3.0 carries every feature of 0.2.3, so a release with the sidecar whose indels are sorted, or whose `analyses.tsv` does not count what it left out, is no version, and `format_version_for` refuses to stamp one. The converter still writes `0.2.0`, and copies its source's fixed-width pair. A release newer than this build writes *in its series* (a `0.2.4` one) is still not judged by its stamp rule (§21.2).

**From #338 to #467**, every builder and Reference Completion wrote `0.2.3`: 0.2.3 is 0.2.2 with the count, so a release is stamped it exactly when its indels are spelt reference first, and a completion of a `0.2.2` source is stamped `0.2.3` -- it carries every feature its source has, and adds the count, which it records for every Analysis (§12). The converter is unchanged: its copy of a `0.1.0` source sorts its indels, so it is `0.2.0`, whose `analyses.tsv` need not carry the count, and it carries none. It refuses a source holding an SE above 65,504, naming each Analysis and array, because it copies stored codes and cannot leave an association out (§21.4).

**From #381 to #338**, every builder and Reference Completion wrote `0.2.2` (`CURRENT_FORMAT_VERSION` for a release without `regions.tsv`). The converter (§21.4) stamps by the same rule from a `SOURCE_FORMAT_VERSION = "0.1.0"` release: it copies the source's stored codes and ALIDs, and a `0.1.0` release carries no `regions.tsv` and sorts an indel's alleles without saying which is the reference, so its copy is honestly `0.2.0`. From #247 to #381 a built and a converted release both declared `0.2.0`, which is what let #249 check their identity; they now differ in their indel ALIDs and in `format_version`, and carry the same layout. `0.1.0` stays readable; deleting the v2 reader is a later decision (ADR 0057). Because completion writes into its source's arrays and keeps its `format_version`, a `0.1.0`, `0.2.0` or `0.2.1` source cannot be Reference-Completed by this build: completing one would add panel ALIDs spelt by §4 beside its own deletions spelt like insertions, and nothing in it says which of its indels are deletions. **The one executable order is to rebuild the release, with its region table where it has one, and complete the rebuilt one.** Completion refuses such a source and says so. A completed release carries every feature its source has, so it keeps its source's version, and adds the count (above).

### 21.4 I have an old store — now what?

Store Releases are immutable. Reference Completion, re-indexing and migration all produce a **new release**. Anything that changes association data or Analytical Metadata derives a new release, with exactly one exception below (the third). These, and only these, are made in an existing release in place, keeping its `release_id`, and the release is re-validated afterwards:

- a **Provenance Amendment**: folding additional facts into an existing release's
  `provenance` dict, including a format migration recording what it did to that
  release. It touches no association data and no Analytical Metadata;
- before `1.0.0`, §21.0's coherent vocabulary sweep: a change of spelling in a
  required manifest field, applied by editing the existing Stores' metadata, not
  by deriving or rebuilding them. It touches no association data and no
  Analytical Metadata;
- **a derived, rebuildable component and the count columns derived from it,
  recomputable from the Store and a named LD Store** (ADR 0106 §10, on the
  owner's plan of 23 Nov 2026 on #62, narrowing ADR 0038 §4–§5 and widening ADR
  0061). That is the Clumps of the 5e-8 tier (§18.1), with `n_loci_5e8` and
  `n_unclumped_5e8`, which are Analytical Metadata. They are added to a 0.3.0
  release beside every existing value and change none, its `format_version`
  included (§21.1). They are written by one step with the manifest's `clumps` entry
  last, and are replaced whole when the step runs again. An
  Indexed Variant Subset (§10b, ADR 0061) is added in place too; it is
  non-authoritative and carries no Analytical Metadata (§21.1). So is a Rho Matrix (ADR
  0025): `data.zarr/rho` of a Dense release, or `dense/data.zarr/rho` of a Hybrid
  release's Dense Component (#496), replaced whole when `build-dense-rho` runs again.
  It is nuisance metadata recomputable from the Store, carries no Analytical Metadata,
  and changes no association, `format_version` included.

1. **Rebuild** — the default. Sources are retained and builds are reproducible, and a rebuild also picks up every build-time fix since the store was made.
2. **Migrate** — where a mechanical transformation is sufficient and a rebuild is disproportionate. `ogdb rewrite-release SOURCE DESTINATION` (`opengwasdb.store.rewrite`, issue #467) derives a new `0.3.0` release from a `0.2.3` one: it copies the source (by reflink where the filesystem can), runs its named steps on the copy — #467's writes the ALID sidecar from the Variant Table and drops the fixed-width pair; #468's writes the position sidecar from the same table; #471's drop `index.sqlite`'s `metadata` and `variant_aliases` (an Observed-Only release then has no `index.sqlite`; a Reference-Completed one keeps `completion_quality`) and every tier's `abs_z` and `p_value`, which the copy leaves out rather than copying to delete, and refuse, before anything is written, a source whose `index.sqlite` holds a table 0.3.0 neither keeps nor drops, whose `variant_aliases` names an rsID its rsID index lacks, whose `dense` blob disagrees with its manifest, which is Reference-Completed with no `completion_quality`, or which has a tier storing one of `abs_z` and `p_value` without the other, storing values its `z` does not imply, or described by a consolidated-metadata record; #469's leaves `variant_offsets.npy` out of the copy and drops the Dense provenance's `row_offsets` that names it (the `dense` blob that also named it goes with `metadata`), refusing unless the ALID, position and `source_alid` sidecars count the rows the offsets did; #470's writes the `source_alid` sidecar from the table's `source_alid` column, each row's state from comparing it with the row's ALID, state 0 on every row of a table written before that column, and refuses unless the sidecar read back gives every row the table's state and text; on a 0.3.0 Hybrid it writes the root's alone, which the Dense Component's rows are answered from; #472's leaves a Hybrid Dense Component's own Variant Table, `.tbi`, ALID index, rsID index, `variant_offsets.npy`, `analyses.tsv` and `overview.html` out of the copy (the earlier steps write it no sidecar), refusing, before anything is written, unless `dense_to_shared.npy` names one shared row for each of its rows, in range and strictly ascending, holding that row's ALID; it does not compare the two copies' rsID or `source_alid` columns, as the shared table, which every query reads, kept what a completed release's Dense copy lost (#481); the `indexed_subsets` step records the new `release_id` and `format_version` in each Indexed Variant Subset the release carries, as it holds the same cells of the rewritten release (§10b, ADR 0061), and refuses a source whose subset already names another release — and stamps every manifest `0.3.0` with a fresh `release_id` and `created_at`, `store_id` kept, and a `format_rewrite` provenance block naming the source `release_id`, the steps, and the range probes the release could not pose (`range_questions_not_posed`, which the log line also names). Before it publishes, it asks the source and the staged copy the same deterministic set of questions (`opengwasdb.store.query_digests`: each Analysis, PheWAS and lookups of variants spread over the axis, a range, the top hits at five thresholds, Observed-Only and not, the ALID probes: the release's longest ALIDs and one at each of 23, 24, 25, 32 and 33 bytes, and the range probes: ranges at the first and last variant, either side of a chromosome boundary, between two variants, on a chromosome the release lacks, and on a position several variants share, the misses: rsIDs no release names, by PheWAS and inside a lookup, and each Indexed Variant Subset's answer for the spread Analyses) and refuses on any difference in any array of any answer; #467's step also refuses unless every ALID it wrote resolves to its own row, #468's unless the sidecar places every row where the table does, and the table steps unless the table holds the rows the source's offsets count; then it validates the copy and publishes by rename only if it is clean. It never writes its source, refuses a destination that exists or lies inside the source, and, without `--convert-legacy`, refuses every source but `0.2.3`: 0.3.0 keeps 0.2.3's reference-first indels and its count of associations left out for an SE above 65,504, which an earlier release lacks and no rewrite can add, so such a release is rebuilt. **Behind `--convert-legacy`, with `--lifted` or `--not-lifted`, a `0.2.0`, `0.2.1` or `0.2.2` Dense release is converted instead** (issue #492, ADR 0105 "25 Nov 2026 (#492)"; the owner, 25 Nov 2026: the priority Stores are converted first with recorded deviations and rebuilt from source later). A `0.2.3` source is refused under the flag, and so is a Ragged or Hybrid one. `--n-workers` sizes the final validation as it sizes `validate`'s. Three steps join the rewrite's: `se_out_of_range` gives every cell whose SE decodes above 65,504, `+inf` included, the missing codes in the grid and every Indexed Variant Subset, removes its side-table entries and its row from every tier, writes `n_missing_se_out_of_range` and recounts `n_hits_*`; `own_source_alid`, on `--not-lifted`, names each row a cell is observed in by its own ALID (state 1) and a row completion added from the panel by none, refusing unless those rows number the completion's `n_variants_new`, and refusing a table that already names another ALID; `completion_quality_missing` counts each masked cell on a panel row as missing in the one `completion_quality` block that holds it. A completion's fill above 65,504, and a masked panel cell no one block holds, are refused. What cannot be fixed is recorded in `provenance.converted_from` (`source_format_version`, `source_release_id`, `engine`, `deviations` by §20.0 rule name, `lifted` and `lifted_decided_by`, the masked count): `variant_table.indel_order` for a source before `0.2.2`, whose indels are carried as spelt; `variant_table.source_alid` for `--lifted`, whose rows keep state 0; and `side_tables.se_exceptions_rounded` where the source's SE exception table was rounded to `float16` before its plan was chosen (#355), which the rule's own measurement says, with the counts recorded as `se_exceptions_rounded` and `se_exceptions` (a source whose table is not rounded records neither). Its proof asks the source through its 0.2 reader with exactly those changes applied (each masked cell missing and out of the tiers, the counts, each row's expected `source_alid`), so every change is compared, not skipped. A rebuild writes no `converted_from`. The rewrite is otherwise the proof that each format step changes no answer; its range PheWAS spans at most 10,000 variants and 2,500,000 cells, variants by Analyses (`RANGE_ROWS_ASKED`, `RANGE_CELLS_ASKED`), which every fixture release's whole range is within (ADR 0105 §3); where that narrows it, the log names the narrowed range and `format_rewrite.range_question_narrowed` records it (chromosome, start, end, the unbounded end, and the variants asked of how many), None otherwise. `scripts/convert_store_to_0_2_0.py` (`opengwasdb.store.convert`, issues #245 and #248) derives a new `0.2.0` release from a `0.1.0` one at an explicit `--into` path: every array is re-written as Zarr v3 with the sharding codec holding the same stored codes, so no value is re-encoded. It accepts every layout whose arrays the role table names — Dense Observed-Only and Reference-Completed, Ragged Observed-Only and Reference-Completed, and Hybrid — and refuses an array or group it cannot name a role for, a source that is already `0.2.0` (including a Hybrid with one component already converted), a Hybrid without its nested Dense Component, and -- before anything is written -- a source holding an SE above 65,504, naming each Analysis and array that holds one (issue #338): it copies stored codes, and leaving such an association out would mean rewriting z, the exception tables, the Top-Hit Index and a Ragged release's offsets, so the release is rebuilt instead. A Hybrid release is two Store Releases, so both of its manifests and both of its `data.zarr` trees are converted; a half-converted Hybrid is invalid under §20. Like every derived release it never writes its source, mints a fresh `release_id` and `created_at`, records the source `release_id` and the new layout in a `zarr_v3_conversion` provenance block per component, regenerates `overview.html` where the layout carries one, and publishes by rename only after the staged copy is verified **bit-identical** to its source and validates with no errors. It reads no source VCF, so conversion rather than a rebuild is the migration route for a store whose values are right and whose layout is old (ADR 0057). `scripts/restamp_store_to_0_1_0.py` (issue #143) derives a new `0.1.0` release from a `3.0` one at an explicit `--into` path. It reads no array: the reset renumbered the format and deleted the pre-release decoders, and did not change the bytes a build writes, so a `3.0` release already holds what `0.1.0` describes. It exists for `ukb-b`, where a rebuild is 13h30m (issue #148); the pilots are rebuilt. It refuses `0.1`, `1.0` and `2.0`, whose planes are genuinely different encodings. Like every derived release it mints a fresh `release_id` and `created_at` rather than inheriting the source's, regenerates `overview.html` — which embeds `release_id` in its header (ADR 0032) — so the release's own page agrees with its new identity (issue #164), and builds the destination in a staging directory, publishing it by rename only when the staged copy validates with **no** errors — an error string identical to one the source already carried is never subtracted (issue #164). Its source release is never written. `scripts/migrate_store_to_analyses_tsv.py` predates this policy: it rewrites `analyses.tsv` in place, which is outside the Provenance Amendment exception. Its targets are stores that should be rebuilt instead (ADR 0038 §5).
3. **Rejected** — a store whose series this build does not implement cannot be read, and no amount of validation makes it readable. Every pre-reset release is in this category, and says so by name.

There is no support window for older remainders: a known series reads every remainder within it.

**Reference Completion preserves its source's `format_version`**, because it writes into the source's arrays and therefore its encoding — a completed release is the same format as its source, but for the count of associations left out for an SE above 65,504, which every completion records and which moved a `0.2.2` source's completion to `0.2.3`, and for the ALID sidecar, which every completion writes for its axis since #467, so a `0.2.2`, `0.2.3` or `0.3.0` source completes to `0.3.0` (§21.3). A build that can read a source but cannot write that format MUST refuse to complete it, rather than stamp a version onto arrays it did not encode that way. Since #381 the refusal fires on a `0.1.0` or a `0.2.0` source, converted or built: both sort an indel's alleles (§4), so it is rebuilt and the rebuilt release completed; the message says so.
