From bc543e4182d51917fe6bfa608af2c09c8b578671 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 09:25:13 +0000 Subject: =?UTF-8?q?staleness:=20blocked=20builds=20wait=20properly,=20and?= =?UTF-8?q?=20the=20review=20answers=20=C2=A710.3=20before=20you=20approve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three real defects, all found while writing the tests that pin §10 down: - **requeue_blocked requeued everything blocked.** The dispatcher sweeps it every pass, so a build waiting on a package that has not arrived was put back on the queue, claimed, blocked again, and repeated — a busy loop burning a claim and a plan step each tick. It now only requeues a build whose every blocking name is actually in the index. The old pipeline test asserted the broken behaviour and has been rewritten to assert the correct one. - **The review page could not warn about missing dependencies, because nothing ever computed them.** candidates::set_missing_deps existed and was never called; missing deps were discovered at plan time, i.e. after a human had already approved. Detection now records them with the same rule the plan step uses, so the reviewer sees 'the build will block until these are published' before deciding, and the CLI and the page agree because both read the row. - **The dependents question was unanswered.** §10.3 asks 'approving this marks N packages stale'. The review page now says exactly that and names them, from the same derivation the Attention page uses. tests/staleness.rs (6 tests) also pins the claims that were easy to fake: staleness is derived on read — a schema scan asserts no column anywhere stores it, and withdrawing a dependency flips a dependent from Outdated to Missing without a single write to the dependent; a blocked build names its blocker on Attention and is not counted as a failure; a dependency we stopped publishing reads as missing rather than outdated. dep-partner added to the corpus so blocked builds are testable end to end. 149 tests pass, clippy clean. --- src/db/builds.rs | 41 ++++++++++++++++++++++++++++++++++++----- src/http/render.rs | 3 +++ src/http/routes.rs | 1 + src/watch/detect.rs | 29 +++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/db/builds.rs b/src/db/builds.rs index 27fa23b..3770746 100644 --- a/src/db/builds.rs +++ b/src/db/builds.rs @@ -221,12 +221,43 @@ pub fn block_on(db: &Db, id: &str, blocked_on: &[String]) -> Result<()> { } /// Re-check blocked builds whenever a publish lands (§10.4). +/// Requeue blocked builds whose blocking packages have since arrived (§10.4). +/// +/// Not "requeue everything that is blocked": the dispatcher calls this every +/// pass, and requeueing a build that will immediately block again is a busy loop +/// that burns a claim and a plan step each tick. A build only goes back on the +/// queue when every name it is waiting for is actually in the index now. pub fn requeue_blocked(db: &Db) -> Result { - db.writer.tx(|tx| { - let n = tx.execute( - "UPDATE build SET state='queued', updated_at=?1 WHERE state='blocked_missing_dep'", - params![time::now()], - )?; + let now = time::now(); + db.writer.tx(move |tx| { + let rows: Vec<(String, String)> = { + let mut stmt = tx.prepare("SELECT id, blocked_on_json FROM build WHERE state='blocked_missing_dep'")?; + let out = stmt + .query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))? + .filter_map(|x| x.ok()) + .collect(); + out + }; + let mut n = 0; + for (id, blocked_on) in rows { + let waiting: Vec = serde_json::from_str(&blocked_on).unwrap_or_default(); + let satisfied = waiting.iter().all(|name| { + tx.query_row( + "SELECT count(*) FROM package WHERE name=?1 AND state='in_index'", + params![name], + |r| r.get::<_, i64>(0), + ) + .unwrap_or(0) + > 0 + }); + if satisfied && !waiting.is_empty() { + tx.execute( + "UPDATE build SET state='queued', blocked_on_json='[]', updated_at=?1 WHERE id=?2", + params![now, id], + )?; + n += 1; + } + } Ok(n) }) } diff --git a/src/http/render.rs b/src/http/render.rs index 057ea14..ca3ba51 100644 --- a/src/http/render.rs +++ b/src/http/render.rs @@ -140,6 +140,9 @@ pub struct ReviewHead { pub risk: String, pub signals: Vec, pub missing_deps: Vec, + /// §10.3: "approving this marks N packages stale" — the packages of ours + /// whose own recipes name one of the packages this candidate produces. + pub dependents: Vec, pub revision: i64, pub aur_commit: String, pub aur_commit_short: String, diff --git a/src/http/routes.rs b/src/http/routes.rs index 177ffcd..26aaa89 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -284,6 +284,7 @@ fn review_body( risk: c.risk_level.clone(), signals: c.risk_signals(), missing_deps: c.missing_deps(), + dependents: crate::watch::staleness::dependents_of(db, &c.pkgbase).unwrap_or_default(), revision: c.revision, aur_commit: snapshot.as_ref().map(|s| s.aur_commit.clone()).unwrap_or_default(), aur_commit_short: snapshot diff --git a/src/watch/detect.rs b/src/watch/detect.rs index 55b7543..3134e19 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -258,6 +258,35 @@ fn score( if let Ok(a) = crate::review::risk::assess(db, cfg, pb, recipe, digests, accepted) { let _ = crate::review::candidates::set_risk(db, id, &a.level, &a.signals); } + // Record now what would block the build later, using the same rule the plan + // step uses. A reviewer approving a package whose dependencies we have not + // published yet should see that before they approve it, not as a blocked + // build afterwards (§10.4). + let missing = missing_deps(db, pb, recipe); + let _ = crate::review::candidates::set_missing_deps(db, id, &missing); +} + +/// Dependencies that are ours to publish but are not in the index yet. +fn missing_deps(db: &Db, pb: &Pkgbase, recipe: &Recipe) -> Vec { + let ours = match db::our_package_names(db) { + Ok(o) => o, + Err(_) => return Vec::new(), + }; + let mut out = Vec::new(); + for dep in crate::pkgver::dep_names(&recipe.depends) { + if ours.contains(&dep) || dep == pb.name || recipe.pkgnames.contains(&dep) { + continue; + } + let ours_to_publish = db::get_subscription(db, &dep) + .map(|s| s.is_some()) + .unwrap_or(false) + || db::get_pkgbase(db, &dep).map(|p| p.is_some()).unwrap_or(false); + if ours_to_publish { + out.push(dep); + } + } + out.sort(); + out } fn outcome_of(up: Upsert) -> Outcome { -- cgit v1.2.3