From 062efa6583b7fea292a4f485659661d266461611 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 15:48:02 +0000 Subject: review: a database failure is never reported to a reviewer as a stale review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `approve()` returned `Result` and then collapsed every inner failure into `Stale::NotPending { state: e.to_string() }`, so a SQLite error reached the human as "review is no longer pending (state: sqlite: …)". That is the one message that tells a reviewer to look again when the truth is that the write failed — and the transaction had already rolled back, so their review was still pending and nothing on screen explained why. `bulk()` bent the same variant to mean "high risk", "unknown decision" and "the database failed", and handed back a fabricated `Approval { id: 0 }` for a rejection that recorded no approval at all. `approve()` now returns `Result` with two families: `Stale(Stale)` — what is stored is not what was displayed, look again — and `System(Error)` — the write failed, nothing about the review is at fault. The UI answers the first with the 409 and fresh diff it already gave, and the second with a 500 that names the cause; the CLI exits 2 for the first and propagates the second as an error. `bulk()` got its own vocabulary — `BulkOutcome::{Approved, Rejected, Refused(BulkRefusal)}` with `HighRiskUnconfirmed`, `UnknownDecision`, `NotFound`, `Stale` and `System` — and returns no approval row for a rejection, because there is none. The invented `id: 0` is gone. The web handler had its own copy of the bulk loop; it now calls `approve::bulk`, so the page and the library cannot disagree about what §7.4 says. Three tests: a dropped `audit` table mid-transaction must surface as `System` and must leave the review pending and the approval table empty; bulk refusals must name the risk, the unknown decision, and (after a real approval) the genuine staleness as three different things; a bulk rejection must record a `rejected` row and hand back nothing. --- src/http/routes.rs | 59 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 22 deletions(-) (limited to 'src/http') diff --git a/src/http/routes.rs b/src/http/routes.rs index f4ab2ca..d3b184b 100644 --- a/src/http/routes.rs +++ b/src/http/routes.rs @@ -362,7 +362,16 @@ fn review_approve(state: &State, req: &Req, id: &str) -> Res { } page_to_res(ReviewsPage { page, rows: review_rows(state) }, 200) } - Err(stale) => { + Err(ap::ApproveError::System(e)) => { + // The database refused. Telling the reviewer their review went stale + // would be a lie about the one thing they cannot check themselves. + let mut page = chrome(state, req, "Review failed", "nav_reviews"); + page.flash = format!("the approval could not be recorded: {e}"); + page.has_flash = true; + page.flash_err = true; + page_to_res(ReviewsPage { page, rows: review_rows(state) }, 500) + } + Err(ap::ApproveError::Stale(stale)) => { // §7.1a: refuse, re-render what it is now, and say why. Never // silently retarget the approval onto the newer state. let mut page = chrome(state, req, "Review changed", "nav_reviews"); @@ -441,7 +450,7 @@ fn reviews_bulk(state: &State, req: &Req) -> Res { .find(|(k, _)| k == "decision") .map(|(_, v)| v.clone()) .unwrap_or_default(); - let confirmed: std::collections::BTreeSet = form + let confirmed: Vec = form .iter() .filter(|(k, _)| k == "confirm") .filter_map(|(_, v)| v.parse().ok()) @@ -453,30 +462,36 @@ fn reviews_bulk(state: &State, req: &Req) -> Res { page.flash_err = true; return page_to_res(ReviewsPage { page, rows: review_rows(state) }, 400); } + // The rule itself lives in `review::approve::bulk`, so the page and the + // library cannot disagree about what a bulk decision means (§7.4). + let items: Vec<(i64, String, String)> = ids + .iter() + .filter_map(|id| { + candidates::candidate_by_id(db, *id).ok().flatten().map(|c| (*id, c.identity_hash, c.diff_digest)) + }) + .collect(); + let outcomes = match ap::bulk(db, actor(state, req), &items, &decision, &confirmed) { + Ok(outcomes) => outcomes, + Err(e) => { + let mut page = chrome(state, req, "Reviews", "nav_reviews"); + page.flash = format!("the decisions could not be recorded: {e}"); + page.has_flash = true; + page.flash_err = true; + return page_to_res(ReviewsPage { page, rows: review_rows(state) }, 500); + } + }; let mut done = Vec::new(); let mut refused = Vec::new(); - for id in ids { - let Some(c) = candidates::candidate_by_id(db, id).unwrap_or(None) else { continue }; - if decision == "approve" && c.risk_level == risk::level::HIGH && !confirmed.contains(&id) { - refused.push(format!("{} (high risk: confirm it individually)", c.pkgbase)); - continue; - } - let res = if decision == "approve" { - ap::approve(db, actor(state, req), id, &c.identity_hash, &c.diff_digest, Some("bulk")) - .map(|_| ()) - .map_err(|e| e.to_string()) - } else { - let note = req.form_get("note").unwrap_or_else(|| "bulk reject".into()); - ap::reject(db, actor(state, req), id, ¬e).map_err(|e| e.to_string()) - }; - match res { - Ok(()) => { - if decision == "approve" { - let _ = pipeline::enqueue_for_candidate(&state.cfg, db, &c); + for item in outcomes { + match &item.outcome { + ap::BulkOutcome::Approved(_) => { + if let Some(c) = &item.candidate { + let _ = pipeline::enqueue_for_candidate(&state.cfg, db, c); + done.push(c.pkgbase.clone()); } - done.push(c.pkgbase); } - Err(e) => refused.push(format!("{}: {e}", c.pkgbase)), + ap::BulkOutcome::Rejected => done.push(item.pkgbase().to_string()), + ap::BulkOutcome::Refused(r) => refused.push(format!("{}: {r}", item.pkgbase())), } } let mut page = chrome(state, req, "Reviews", "nav_reviews"); -- cgit v1.2.3