From b1cfdca4772d0fc87bfb10f118b0b22618eea820 Mon Sep 17 00:00:00 2001 From: agent Date: Fri, 13 Nov 2026 03:38:51 -0600 Subject: [PATCH] feat(fleet-queue): second_pass packet kind + review payload block (#2310) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements design #2025 sections 5.1-5.2 and 7.2 (D2 ruled 2026-11-11) in the repo-task/v1 packet validator: - KINDS gains second_pass. - New dedupe family second-pass: repo-health:v1:second-pass:::pass-, cross-checked against payload.issue.number and payload.review.pass, and the only family valid for kind second_pass — one live packet per (artifact, pass) by construction, so a second commissioning collides on the key instead of double-commissioning. - The review payload block (verdict, verdict_note_url, artifact, pass, pass_cap, gap_list, goal_context_refs, producer, route_floor) is required for second_pass and shape-checked whenever any packet carries one (the Stage B interim small_fix representation): gap_list and verdict_note_url are required, pass/pass_cap must be positive, and pass > pass_cap is rejected at enqueue — the termination cap is arithmetic, not restraint. - Result outcomes: no result-outcome allowlist exists in the validator or the broker (checked validate.rs, turso_queue.rs, queue_broker.rs), so superseded_by_second_pass / second_pass_complete need no recognition change; the acceptance item was conditional on one existing. Mirrored the same change into the two laptop-local copies the packet evidence named (fleet-brokers-src validate.rs — compiles; ~/tools/repo-task-v1.schema.json kind enum + review block), which deploy outside this repo. Tests: cargo test -p fleet-queue --features queue-broker — 298 passed, 0 failed, including 6 new second_pass tests (well-formed packet validates; missing gap_list, missing verdict_note_url, pass > pass_cap, and missing review block all rejected; dedupe family matches issue+pass and rejects the family for other kinds). --- pkgs/fleet/crates/fleet-queue/src/validate.rs | 287 +++++++++++++++++- 1 file changed, 284 insertions(+), 3 deletions(-) diff --git a/pkgs/fleet/crates/fleet-queue/src/validate.rs b/pkgs/fleet/crates/fleet-queue/src/validate.rs index 8d3c763033..5f49a7c39e 100644 --- a/pkgs/fleet/crates/fleet-queue/src/validate.rs +++ b/pkgs/fleet/crates/fleet-queue/src/validate.rs @@ -50,7 +50,13 @@ use serde_json::{Value, json}; use std::time::{SystemTime, UNIX_EPOCH}; pub const PRIORITY_SCALE: [i64; 7] = [10, 20, 30, 40, 50, 70, 90]; -pub const KINDS: [&str; 4] = ["pr_shepherd", "triage", "small_fix", "ci_investigation"]; +pub const KINDS: [&str; 5] = [ + "pr_shepherd", + "triage", + "small_fix", + "ci_investigation", + "second_pass", +]; // Both the old and the current names of the two repos that moved to the // developing-today-forks org (2026-11-04) stay allowlisted: in-flight queue // tasks carry dedupe keys with the old names and must keep validating, @@ -75,7 +81,8 @@ triage: repo-health:v1:triage::issue:\n\ pr: repo-health:v1:pr::pr:\n\ pr-set: repo-health:v1:pr-set::-[-...] (sorted)\n\ set: repo-health:v1:set::owed:\n\ -maintenance: repo-health:v1:maintenance:::"; +maintenance: repo-health:v1:maintenance:::\n\ +second-pass: repo-health:v1:second-pass:::pass-"; fn manual_schema_errors(p: &Value) -> Vec { let mut errs = Vec::new(); @@ -222,6 +229,92 @@ fn manual_schema_errors(p: &Value) -> Vec { .to_string(), ); } + errs.extend(review_errors(p)); + errs +} + +/// The review payload block (design #2025 section 5.2; #2310): required +/// for kind second_pass, and shape-checked whenever a packet of any +/// kind carries one (the Stage B interim representation attaches it to +/// small_fix packets). gap_list and verdict_note_url are required, and +/// pass may not exceed pass_cap — the termination cap is enforced +/// here, in the enqueue code path, not by reviewer restraint. +fn review_errors(p: &Value) -> Vec { + let mut errs = Vec::new(); + let kind = p.get("kind").and_then(|k| k.as_str()).unwrap_or(""); + let review = p.get("review"); + if kind != "second_pass" && review.is_none() { + return errs; + } + let Some(review) = review.and_then(|r| r.as_object()) else { + errs.push( + "payload.review: required object for kind second_pass (design #2025 section 5.2)" + .to_string(), + ); + return errs; + }; + match review.get("verdict_note_url") { + Some(Value::String(u)) if !u.is_empty() => {} + _ => errs.push( + "payload.review.verdict_note_url: required non-empty string for second_pass packets" + .to_string(), + ), + } + match review.get("gap_list") { + Some(Value::Array(a)) + if !a.is_empty() + && a.iter() + .all(|g| matches!(g, Value::String(s) if !s.is_empty())) => {} + _ => errs.push( + "payload.review.gap_list: required non-empty list of checkable gap strings for second_pass packets" + .to_string(), + ), + } + let pass = review.get("pass").and_then(|v| v.as_i64()); + let pass_cap = review.get("pass_cap").and_then(|v| v.as_i64()); + match pass { + Some(n) if n >= 1 => {} + _ => errs.push( + "payload.review.pass: required positive integer (the pass being commissioned; the original work is pass 0)" + .to_string(), + ), + } + match pass_cap { + Some(n) if n >= 1 => {} + _ => errs.push("payload.review.pass_cap: required positive integer".to_string()), + } + if let (Some(pass), Some(cap)) = (pass, pass_cap) { + if pass > cap { + errs.push(format!( + "payload.review.pass: pass {pass} exceeds pass_cap {cap} — the termination cap is enforced at enqueue (design #2025 section 5.1)" + )); + } + } + if let Some(verdict) = review.get("verdict") { + if !matches!(verdict, Value::String(_)) { + errs.push("payload.review.verdict: must be a string".to_string()); + } + } + if let Some(artifact) = review.get("artifact") { + if !artifact.is_object() { + errs.push("payload.review.artifact: must be an object {pr, issue, merged}".to_string()); + } + } + if let Some(producer) = review.get("producer") { + if !producer.is_object() { + errs.push("payload.review.producer: must be an object {task_id, session, pr}".to_string()); + } + } + if let Some(refs) = review.get("goal_context_refs") { + if !matches!(refs, Value::Array(a) if a.iter().all(|r| matches!(r, Value::String(_)))) { + errs.push("payload.review.goal_context_refs: must be a list of strings".to_string()); + } + } + if let Some(floor) = review.get("route_floor") { + if !matches!(floor, Value::String(_)) { + errs.push("payload.review.route_floor: must be a string".to_string()); + } + } errs } @@ -240,6 +333,9 @@ pub struct DedupeMatch { pub num: Option, pub nums: Option>, pub origin: Option, + /// The commissioned pass for the second-pass family (#2310); + /// None for every other family. + pub pass: Option, } fn all_digits(s: &str) -> bool { @@ -277,12 +373,13 @@ fn match_dedupe(key: &str) -> Option { num: None, nums: None, origin: Some(origin), + pass: None, }); } } return None; } - for fam in ["fix", "triage", "pr-set", "pr", "maintenance"] { + for fam in ["fix", "triage", "pr-set", "pr", "maintenance", "second-pass"] { let Some(after) = rest.strip_prefix(&format!("{fam}:")) else { continue; }; @@ -300,6 +397,27 @@ fn match_dedupe(key: &str) -> Option { num: Some(num), nums: None, origin: None, + pass: None, + }); + } + } + } + "second-pass" => { + // repo-health:v1:second-pass:::pass- + // (design #2025 section 5.2): one live packet per + // (artifact, pass) by construction. + if let Some((issue_s, pass_s)) = tail.split_once(":pass-") { + if let (Some(num), Some(pass)) = ( + canonical_number(issue_s), + canonical_number(pass_s), + ) { + return Some(DedupeMatch { + family: fam.into(), + repo: repo.to_string(), + num: Some(num), + nums: None, + origin: None, + pass: Some(pass), }); } } @@ -313,6 +431,7 @@ fn match_dedupe(key: &str) -> Option { num: Some(num), nums: None, origin: None, + pass: None, }); } } @@ -335,6 +454,7 @@ fn match_dedupe(key: &str) -> Option { num: None, nums: Some(nums), origin: None, + pass: None, }); } } @@ -372,6 +492,7 @@ fn match_dedupe(key: &str) -> Option { num: None, nums: None, origin: None, + pass: None, }); } } @@ -392,6 +513,7 @@ fn kind_families(kind: &str) -> Option<&'static [&'static str]> { "triage" => Some(&["triage", "maintenance"]), "pr_shepherd" => Some(&["pr", "pr-set", "set"]), "ci_investigation" => Some(&["fix", "triage", "pr"]), + "second_pass" => Some(&["second-pass"]), _ => None, } } @@ -478,6 +600,40 @@ fn dedupe_errors(packet: &Value, payload: &Value) -> Vec { } } } + "second-pass" => { + let n = m.num.unwrap_or(0); + match issue_no { + Some(ino) if n != ino => { + errors.push(format!( + "packet.dedupe_key: issue {n} in key does not match payload.issue.number {ino}" + )); + } + Some(_) => {} + None => { + errors.push(format!( + "packet.dedupe_key: family 'second-pass' requires payload.issue.number {n} matching the key issue, but the payload carries no issue.number (#6446)" + )); + } + } + let key_pass = m.pass.unwrap_or(0); + let review_pass = payload + .get("review") + .and_then(|r| r.get("pass")) + .and_then(|v| v.as_i64()); + match review_pass { + Some(rp) if rp != key_pass => { + errors.push(format!( + "packet.dedupe_key: pass {key_pass} in key does not match payload.review.pass {rp}" + )); + } + Some(_) => {} + None => { + errors.push(format!( + "packet.dedupe_key: family 'second-pass' requires payload.review.pass {key_pass} matching the key pass, but the payload carries no review.pass" + )); + } + } + } "pr" => { let n = m.num.unwrap_or(0); if !pr_numbers.is_empty() { @@ -1542,4 +1698,129 @@ mod tests { let _ = validate_not_before_at(&json!(s), "packet.not_before", 1_762_700_000); } } + + fn second_pass_payload(review: serde_json::Value) -> Value { + let mut payload = payload_with(json!({"issue": {"number": 2310}})); + let obj = payload.as_object_mut().expect("payload object"); + obj.insert("kind".to_string(), json!("second_pass")); + obj.insert("review".to_string(), review); + payload + } + + fn valid_review() -> serde_json::Value { + json!({ + "verdict": "second-pass", + "verdict_note_url": "https://github.com/developing-today/code/issues/2025#issuecomment-1", + "artifact": {"pr": 9001, "issue": 2310, "merged": false}, + "pass": 1, + "pass_cap": 2, + "gap_list": ["ring-2 gap: no test pins the cap"], + "goal_context_refs": ["https://github.com/developing-today/code/issues/2025"], + "producer": {"task_id": 7325, "session": "ses_x", "pr": 9001}, + "route_floor": "specialist", + }) + } + + #[test] + fn second_pass_packet_validates() { + let packet = json!({ + "title": "Second pass 1 on #2310", + "priority": 20, + "dedupe_key": "repo-health:v1:second-pass:developing-today/code:2310:pass-1", + "payload": second_pass_payload(valid_review()), + }); + let (errors, _warnings) = validate_packet(&packet); + assert!(errors.is_empty(), "well-formed second_pass packet must validate; got {errors:?}"); + } + + #[test] + fn second_pass_rejects_missing_gap_list() { + let mut review = valid_review(); + review.as_object_mut().unwrap().remove("gap_list"); + let errors = manual_schema_errors(&second_pass_payload(review)); + assert!( + errors.iter().any(|e| e.contains("review.gap_list")), + "missing gap_list must be rejected; got {errors:?}" + ); + } + + #[test] + fn second_pass_rejects_missing_verdict_note_url() { + let mut review = valid_review(); + review.as_object_mut().unwrap().remove("verdict_note_url"); + let errors = manual_schema_errors(&second_pass_payload(review)); + assert!( + errors.iter().any(|e| e.contains("review.verdict_note_url")), + "missing verdict_note_url must be rejected; got {errors:?}" + ); + } + + #[test] + fn second_pass_rejects_pass_above_cap() { + let mut review = valid_review(); + review["pass"] = json!(3); + let errors = manual_schema_errors(&second_pass_payload(review)); + assert!( + errors.iter().any(|e| e.contains("exceeds pass_cap")), + "pass > pass_cap must be rejected at enqueue; got {errors:?}" + ); + } + + #[test] + fn second_pass_requires_the_review_block() { + let mut payload = payload_with(json!({"issue": {"number": 2310}})); + payload + .as_object_mut() + .unwrap() + .insert("kind".to_string(), json!("second_pass")); + let errors = manual_schema_errors(&payload); + assert!( + errors.iter().any(|e| e.contains("payload.review")), + "second_pass without a review block must be rejected; got {errors:?}" + ); + } + + #[test] + fn second_pass_dedupe_family_matches_issue_and_pass() { + let identity = json!({"issue": {"number": 2310}, "review": {"pass": 1}}); + assert!( + dedupe_errs( + "repo-health:v1:second-pass:developing-today/code:2310:pass-1", + "second_pass", + identity.clone(), + ) + .is_empty() + ); + // Same (issue, pass) is the same key by construction: a second + // commissioning collides on it instead of double-commissioning. + let m = match_dedupe("repo-health:v1:second-pass:developing-today/code:2310:pass-1") + .expect("second-pass key parses"); + assert_eq!(m.family, "second-pass"); + assert_eq!(m.num, Some(2310)); + assert_eq!(m.pass, Some(1)); + // Pass disagreement between key and payload is an error. + let errors = dedupe_errs( + "repo-health:v1:second-pass:developing-today/code:2310:pass-2", + "second_pass", + identity, + ); + assert!( + errors.iter().any(|e| e.contains("pass 2 in key")), + "key pass must match review.pass; got {errors:?}" + ); + // The second-pass family is not valid for other kinds, and + // other families are not valid for second_pass. + assert!(!dedupe_errs( + "repo-health:v1:second-pass:developing-today/code:2310:pass-1", + "small_fix", + json!({"issue": {"number": 2310}}), + ) + .is_empty()); + assert!(!dedupe_errs( + "repo-health:v1:fix:developing-today/code:issue:2310", + "second_pass", + json!({"issue": {"number": 2310}}), + ) + .is_empty()); + } }