summaryrefslogtreecommitdiffstats
path: root/docs/DECISIONS.md
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 19:00:25 +0000
committeraur-build <aur-build@localhost>2026-11-18 19:00:25 +0000
commit8835a0a86c82d922a2d674f3543c331dc9adb9e5 (patch)
tree7ac728613b7d24b28dee4fd7ba30d2137e8f7554 /docs/DECISIONS.md
parent76a214ed4d82d8937a3ec38c27d4d59304b8fac3 (diff)
downloadaur-build-8835a0a86c82d922a2d674f3543c331dc9adb9e5.tar.gz
aur-build-8835a0a86c82d922a2d674f3543c331dc9adb9e5.zip
docs: the review's decisions, and the invariants that hold them
The structural findings are only durable if they are written down as rules with the test that enforces each one, so: `docs/INVARIANTS.md` gains a second table. The first one is the twelve numbered invariants from DESIGN.md §2 — claims about what the system does. The new one is about how the code is allowed to be shaped: SQL has one owner, a version is formatted in one place, the dependency arrows point one way, the state machines are the ones the transition table defines, the production binary carries no test scaffolding, the served index has one lock, `canonical_json` is canonical in fact, the session id is the credential, and a pinned clock pins everything derived from it. Each row names the test that fails if the shape regresses. `docs/DECISIONS.md` gains the decisions the review turned into code — the session id as the credential, `db/` as a boundary that does not hand out connections, a stale review and a broken database being different answers, shims compiled out of production, states as enums with compare-and-swap writes, unreadable rows failing the query, and only momentary I/O counting as transient. Two existing entries were amended rather than added to: the publisher lock (there is now one, and the second one that used to sit inside it is gone) and the test hooks (they are a gated submodule now, not fields on the production config). `README.md` says where the shims live and that none of them exist in a plain `cargo build`.
Diffstat (limited to 'docs/DECISIONS.md')
-rw-r--r--docs/DECISIONS.md112
1 files changed, 105 insertions, 7 deletions
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index a32d67a..68f1fee 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -84,13 +84,27 @@ nothing should be withdrawn automatically — a human has to decide whether the
mirror or the upstream is wrong. The row appears on Attention with both versions
and no action button.
-## `publish_fault`, `shim_fail` and `shim_kill_parent` are test hooks in the config
-
-Three fields exist only so the harness can reproduce failures it cannot otherwise
-cause: a crash between the rename and the signature, a tool that exits non-zero,
-and a process killed mid-step with a signal it cannot catch. They are inert when
-unset, and the alternative — an in-process simulation of a crash — can be caught
-and cleaned up by accident, which is precisely what I5 must not allow.
+## The test hooks are a gated submodule, not fields on `Config`
+
+`publish_fault`, `shim_fail`, `shim_kill_parent` and their siblings exist only so
+the harness can reproduce failures it cannot otherwise cause: a crash between the
+rename and the signature, a tool that exits non-zero, and a process killed
+mid-step with a signal it cannot catch. The alternative — an in-process
+simulation of a crash — can be caught and cleaned up by accident, which is
+precisely what I5 must not allow.
+
+They are no longer seven `Option` fields on the production `Config`, and the
+branches that consult them are no longer compiled into the binary at all. Under
+the default features there is a `TestHooks` type with no fields, the shims and
+their binaries do not exist, and `Config::child_env` exports nothing; the fault
+branches in `publish` are `#[cfg]`-ed away rather than guarded by a runtime
+`if`. A production binary that carries its own fault injection is a binary in
+which someone will eventually ask whether a fault can be triggered from the
+network, and the honest answer will be "not today".
+
+**Cost.** The test harness depends on the crate with `features = ["test-support"]`,
+so `cargo test` and `cargo build` compile slightly different libraries — which is
+the point, and is why `production_surface.rs` asserts the default build is clean.
## CAS baseline comes from the candidate, not from the live pointer
@@ -108,6 +122,90 @@ machinery; the critical section is the db file rewrite, never a build. The lock
poison is cleared deliberately: atomic publish means a panic cannot have left a
half-written db, so wedging the queue would be worse than continuing.
+There is now exactly one such lock, `REPO_LOCK`, taken at the top of `publish()`
+for the whole sequence — file rewrite, signature, index update — and by
+`withdraw_package`, which rewrites the same files. There used to be a second one
+(`PUBLISH_LOCK`) covering a shorter span inside the first, which gave the
+appearance of a second serialization point and would have been the natural place
+for the next writer to acquire the wrong one. A test fails if a second lock
+guarding the served index appears.
+
+## The session id is the credential, not a cookie the client controls
+
+Login used to set `auth=1`, so the secret was the *name* of a cookie and anyone
+who could type `Cookie: auth=1` was the reviewer. Sessions are now a map the
+server owns — a random sid minted at login, marked authenticated only in the
+server's table — and the cookie carries the sid and nothing else. Logging in
+rotates the sid, so a session id that a previous identity might have leaked is
+useless after a re-login; logging out deletes the entry, so the id stops working
+rather than being re-interpreted.
+
+**Cost.** Sessions are per-process and lost on restart, so a server restart signs
+everyone out. For a single-operator tool that is a feature: the same restart that
+reloads the binary also revokes every session it was running under.
+
+## `db/` is a boundary, and the writer does not hand out connections
+
+Every SQL statement in the crate lives in `db/`. `Writer::call`, `tx` and `send`
+are `pub(crate)`, and the raw door the test harness needs exists only under
+`test-support`. A module that needs the database asks `db/` for a typed query;
+if the query does not exist, writing it is the change to make.
+
+**Cost.** `db/` is large, and a one-off ad-hoc query now costs a function instead
+of a line. That is the trade: the schema's shape is knowable from one directory,
+and a grep for a table name finds every reader of it.
+
+## A stale review and a broken database are different answers
+
+`approve()` used to return an `Approval` with `id: 0` when the transaction
+failed, which the UI then rendered as "someone else got there first" — telling a
+reviewer their click lost a race it did not lose, and hiding an I/O error behind
+a message that invites them to retry. It returns `Result<Approval, ApproveError>`
+now, with `Stale` (the review moved: 409, re-render the current diff) kept apart
+from `System` (the database failed: 500, name the cause). `bulk()` answers the
+same way, per row.
+
+## The shims are test-only, and the real `.PKGINFO` parser is the only one
+
+The publish path used to read a package's name out of the archive with a
+simplified parser that the shim harness also had a copy of, which meant
+production was tested against a model of the format rather than the format. There
+is one parser (`pkginfo::parse_pkginfo`), the shims are behind `test-support`,
+and the shim binaries are not built by default.
+
+## States are enums, and writing one is a compare-and-swap
+
+`build.state`, `candidate.state`, `step.state`, `release.state` and
+`subscription.state` were free text, and `current_state` returned `""` for a
+build that did not exist. They are five enums now, parsed at the row boundary — a
+state the code does not define is an error, not a default — and every transition
+is a conditional update (`WHERE state IN (…)`), so a worker whose lease expired
+finds its write refused instead of quietly overwriting the state of the build
+somebody else now owns. A zombie finishing a live build is the failure mode this
+prevents, and it is silent in the old shape.
+
+**Cost.** The transition table is real code that has to be kept honest with the
+schema, and `failed → running` is legal (I5 says a failed build resumes on its
+own row), which is not obvious and is commented where it is defined.
+
+## A row that cannot be read fails the query
+
+`filter_map(|r| r.ok())` was used in some queries and not others, so a row that
+failed to deserialize was sometimes skipped and sometimes an error — and the
+skips were invisible. The policy is now uniform: if a row cannot be read, the
+query fails. A silently missing package is worse than a failed page, because the
+missing package looks like an absent one. `setting_i64` is the one documented
+exception, because a *setting* falling back to its default is the designed
+behaviour, not a lost row.
+
+## Only momentary I/O is transient
+
+`is_transient` classified every `Io` error as retryable, so ENOSPC and EACCES
+were retried with the same backoff as a connection reset — a full disk produced a
+build that retried until it gave up, blaming a network that was fine. Retryable
+now means the kinds that can genuinely pass on the next attempt: would-block,
+timed out, interrupted, broken pipe, connection reset/refused/aborted.
+
## The pipeline refuses symlinks in the srcdir, even though a chroot should make that moot
`collect` scans the build's srcdir for `*.pkg.tar.zst`, and `ingest` copies