ADR-0071: A config holds a block for each context a run is in
Status: Accepted
Date: 2026-11-04
Amends: 0002: its rule 5, the order layers resolve in, and its rule 2, what config:show prints
Context
A project runs the gate in more than one place: on a developer's machine
through watch, pre-commit and pre-push, on every pull request, and on the
default branch. Each place wants different settings. A pull request wants a
tight budget and few shards, the default branch wants every shard it can
get, and a developer's machine wants a short budget and no sharding at all.
ADR-0002 gives one config whose layers are the presets, the config file and
the command line. None of them depends on where the run is, so a project
that wants different settings has to pass command-line options in each CI
job, or keep a second config file and name it with --config. ADR-0002
refuses two config files for exactly this reason.
Presets (ADR-0008) are named layers chosen by the kind of project, such as
laravel or library. They hold what a kind of project needs wherever it
runs. Where a run happens is a different question, and a preset cannot
answer it.
Decision
contextsholds a block for each context a run can be in. Its keys arelocal,ci,prandmain, and each block holds the keys of a layer:{ "budget": "30m", "contexts": { "local": { "budget": "2m" }, "ci": { "shards": { "max": 8 } }, "pr": { "budget": "10m", "shards": { "max": 4 } }, "main": { "shards": { "max": 16 } } } }The PHP builder writes a block with
Context::local(),Context::ci(),Context::pullRequest()andContext::main(), each taking aGate::configure()of its own, inwith(). A block that is not an object, a context with any other name andcontextsinside a block are refused, and an unknown context's problem names the nearest one.A block refuses what is read before the context is known.
presetandextensionsdecide which layers and adapters exist before any context is told, andci.planandci.defaultBranchdecide the context itself. A block that sets one of them is exit code 2, with the problem at its path, such ascontexts.pr.ci.plan. Every other key a layer may write is allowed.The context is told from the environment and the CI plan.
- Outside CI (
CIandTF_BUILDunset), a run is inlocal. - In CI, a run is in
ci. It is also inpr, laid overci, where the CI plan says the run is of a pull request or a merge group, and inmain, laid overci, where the run is on the default branch:ci.defaultBranch, else the one the CI names, elsemain. A push to any other branch, and a run the CI plan says nothing of, are incialone. - The CI plan is the one the settings choose without any block, which no block can change, by rule 2. Telling the context is a second pass over the same layers.
- watch, pre-commit and pre-push are in
localwherever they run. --context=<local|ci|pr|main>, which every command takes, puts the run in that context and in those it is laid over:--context=prisci, thenpr. It beats what the environment says, and it beats thelocalthat watch, pre-commit and pre-push take. Any other value is exit code 2.
- Outside CI (
Each layer resolves its blocks before the layers are laid. A layer's blocks for the run's contexts are laid over the rest of that layer, in order, and the block is gone from the result. The layers are then laid as ADR-0002 lays them: zero-config defaults, the presets in order, the config file, the command line. So a preset (ADR-0008) can carry blocks of its own, and a setting the config file writes at its top still beats a preset's block, as a later layer beats an earlier one. A block replaces, merges and concatenates as a layer does: a block's
treesreplace the layer's, and itsreach.everythingadds to them.The settings a run judges by are the resolved ones. The proof key (ADR-0007), what a change to the config file is compared by (ADR-0005) and every adapter read the settings with the run's blocks laid and none left. A block that changes a setting that affects results therefore keys that context's proofs apart from another context's. A block that changes only what judges or reports keys nothing apart.
config:showprints the config as written, and--resolvedprints a run's.config:showprints the effective config with every layer's blocks kept, laid context by context, so it still converts to every format.config:show --resolvedlays the blocks of the contexts the run is in, or of those--contextnames, prints the result withoutcontexts, and names the contexts on standard error:Resolved for the contexts ci, pr.The schema names a block's keys once. The generated schema (ADR-0002, rule 7) defines a block under
$defs.contextBlock, with the keys rule 2 refuses markednot, and each context undercontextsrefers to it.
Alternatives considered
| Option | Why it lost |
|---|---|
Top-level local, pr, main and ci keys | local (ADR-0010) and ci (ADR-0006) are already sections, so the names clash, and moving them needs a migration (ADR-0026). One contexts key clashes with nothing and is one entry in the schema. |
| Merge every layer's top first, then every layer's blocks | A preset's pr block would beat the config file's own top-level setting, so a project could not override a preset without writing the same block itself. Resolving each layer first keeps "a later layer wins" true. |
A block that only names presets (contexts.pr: "fast") | Reuses presets, but needs a registered preset for every tweak, and a project cannot write a one-off value in its own file. |
| Allow every key in a block, and use the first pass's value for the ones that decide the context | A block that sets ci.plan would be silently ignored, which ADR-0002 refuses for an unknown key for the same reason. |
| A second config file per context | ADR-0002 refuses two config files, because the forgotten one becomes a second answer nobody reads. |
| Contexts told only from environment variables | Every CI spells "pull request" and "default branch" differently, and the CI plans (ADR-0006) already read them. Asking the plan keeps one reading. |
Consequences
One file holds every place's settings. A CI job needs no options to get
its context's settings, and config:show --resolved --context=pr shows what
a pull request runs with on any machine.
A context's proofs are its own where its settings differ in what affects
results. A block that sets only what judges or reports, such as
shards.max or budget, keys nothing apart, so a pull request still
carries the default branch's proofs. A block that sets timeouts.seconds
keys them apart.
Telling the context costs one more pass over the layers. It builds the CI plan, which reads only the environment and the event file.