← Commit history
Merge PR #684: 0.2.150: follow a batch with one wait (follow-batch-one-wait -> main) merge
Showing changes introduced by the merge (against its first parent).
7 files changed
+100−22
Cargo.lock+11−11@@ -4,7 +4,7 @@ version = 4 [[package]] name = "adom-aiflow"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-analyze", "aiflow-board",@@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "aiflow-analyze"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-board", "aiflow-sys",@@ -39,7 +39,7 @@ dependencies = [ [[package]] name = "aiflow-board"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-sys", "roxmltree",@@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aiflow-bridge"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-board", "aiflow-sys",@@ -59,7 +59,7 @@ dependencies = [ [[package]] name = "aiflow-copper"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-board", "aiflow-grid",@@ -70,7 +70,7 @@ dependencies = [ [[package]] name = "aiflow-grid"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-board", "serde",@@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "aiflow-place"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-board", "aiflow-sys",@@ -89,7 +89,7 @@ dependencies = [ [[package]] name = "aiflow-pours"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-board", "aiflow-copper",@@ -100,7 +100,7 @@ dependencies = [ [[package]] name = "aiflow-router"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-board", "aiflow-grid",@@ -111,7 +111,7 @@ dependencies = [ [[package]] name = "aiflow-run"-version = "0.2.149"+version = "0.2.150" dependencies = [ "aiflow-sys", "serde",@@ -120,7 +120,7 @@ dependencies = [ [[package]] name = "aiflow-sys"-version = "0.2.149"+version = "0.2.150" dependencies = [ "serde_json", ]
Cargo.toml+1−1@@ -15,7 +15,7 @@ members = [ ] [workspace.package]-version = "0.2.149"+version = "0.2.150" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
crates/adom-aiflow/src/part_follow.rs+78−7@@ -5,7 +5,9 @@ //! - `part-request --missing` sends every part `parts` found with no page, and no attempt yet, as ONE batch named //! for the board (`--ref`), so five boards on five Mesh boxes each follow only their own batch; //! - `part-request --follow` (under the Monitor tool) waits on the run's open requests and prints one line per-//! change, ending when every one is built, refused or past its deadline. It only reads run.json (another+//! change, ending when every one is built, refused or past its deadline. A batch's parts share ONE wait on the+//! batch (the wiki holds at most 8 waits per account, and five boards' threads may share one); a part the batch+//! read leaves out, and a part asked for alone, is read by its own status API. It only reads run.json (another //! command may be writing it) and appends to the ledger; `part-request --refresh` records the answers. use serde_json::{json, Value}; use std::sync::mpsc;@@ -105,14 +107,14 @@ pub fn refresh_by_status_api(data: &mut Value) -> usize { /// An open request to follow. #[derive(Clone, Debug)]-pub struct Target { pub mpn: String, pub attempt: usize, pub status_api: Option<String>, pub state: String }+pub struct Target { pub mpn: String, pub attempt: usize, pub status_api: Option<String>, pub batch: Option<String>, pub state: String } /// The run's requests still inside their deadline. pub fn targets(data: &Value) -> Vec<Target> { let mut out = Vec::new(); for (m, list) in data["partRequests"].as_object().into_iter().flatten() { for (i, a) in list.as_array().into_iter().flatten().enumerate().filter(|(_, a)| supply::waiting(a)) {- out.push(Target { mpn: m.clone(), attempt: i + 1, status_api: a["statusApi"].as_str().map(str::to_string), state: a["state"].as_str().unwrap_or("sent").to_string() });+ out.push(Target { mpn: m.clone(), attempt: i + 1, status_api: a["statusApi"].as_str().map(str::to_string), batch: a["batchId"].as_str().filter(|b| b.starts_with("b_")).map(str::to_string), state: a["state"].as_str().unwrap_or("sent").to_string() }); } } out@@ -171,6 +173,47 @@ fn wait_on(t: Target, path: String, wait: u64, stop: Instant, tx: mpsc::Sender<R } } +/// A batch read's item as a status answer: the batch names the state `outcome` (or `state`).+pub fn item_answer(it: &Value) -> Value {+ let state = it["outcome"].as_str().or(it["state"].as_str()).or(it["status"].as_str());+ json!({"request": {"state": state, "deadline_passed": it["deadline_passed"], "page_url": it["page_url"], "reason": it["reason"]}})+}++/// One wait for all of a batch's open parts; a part the batch read does not list is read by its own status API.+fn wait_batch(ts: Vec<Target>, id: String, stop: Instant, tx: mpsc::Sender<Result<Change, String>>) {+ let mut open: Vec<(Target, bool)> = ts.into_iter().map(|t| (t, false)).collect();+ let mut errors = 0;+ while !open.is_empty() && Instant::now() < stop {+ let asked = Instant::now();+ let v = match api(&format!("/api/part-request/batches/{id}?wait={WAIT_S}"), "GET", None) {+ Ok(v) => { errors = 0; v }+ Err(e) => {+ errors += 1;+ if errors >= 5 { for (t, _) in &open { let _ = tx.send(Err(format!("{} (attempt {}): could not read batch {id} ({e}); `part-request --refresh` reads it later", t.mpn, t.attempt))); } return; }+ std::thread::sleep(Duration::from_secs(20));+ continue;+ }+ };+ let items = v["items"].as_array().cloned().unwrap_or_default();+ let mut moved = false;+ open.retain_mut(|(t, late)| {+ let ans = match items.iter().find(|i| supply::item_mpn(i).map(|m| m.eq_ignore_ascii_case(&t.mpn)).unwrap_or(false)) {+ Some(i) => item_answer(i),+ None => match t.status_api.as_deref().map(|p| api(p, "GET", None)) { Some(Ok(v)) => v, _ => return true },+ };+ let Some(c) = change_of(t, *late, &ans) else { return true };+ moved = true;+ let done = c.done;+ t.state = c.to.clone();+ *late = c.late;+ let _ = tx.send(Ok(c));+ !done+ });+ // a batch read that answers at once with nothing new (finished, or the account's 8 waits taken): never a tight loop+ if !moved && asked.elapsed() < Duration::from_secs(5) { std::thread::sleep(Duration::from_secs(10)); }+ }+}+ /// Requests with no status API (a wiki older than 2026-12-04): poll `part status --json` and compare. fn poll_list(ts: Vec<Target>, data: Value, stop: Instant, tx: mpsc::Sender<Result<Change, String>>) { let mut data = data;@@ -198,9 +241,17 @@ pub fn follow(data: &Value, minutes: u64, mut each: impl FnMut(&Result<Change, S let ts = targets(data); let stop = Instant::now() + Duration::from_secs(minutes.max(1) * 60); let (tx, rx) = mpsc::channel();- let (with_api, without): (Vec<Target>, Vec<Target>) = ts.iter().cloned().partition(|t| t.status_api.is_some());- let wait = if with_api.len() <= MAX_WAITERS { WAIT_S } else { 0 };- for t in with_api {+ let (with_api, without): (Vec<Target>, Vec<Target>) = ts.iter().cloned().partition(|t| t.status_api.is_some() || t.batch.is_some());+ // one wait per batch, then one per request asked for alone+ let mut batches: std::collections::BTreeMap<String, Vec<Target>> = Default::default();+ let mut alone = Vec::new();+ for t in with_api { match t.batch.clone() { Some(b) => batches.entry(b).or_default().push(t), None => alone.push(t) } }+ let wait = if alone.len() + batches.len() <= MAX_WAITERS { WAIT_S } else { 0 };+ for (id, ts) in batches {+ let tx = tx.clone();+ std::thread::spawn(move || wait_batch(ts, id, stop, tx));+ }+ for t in alone.into_iter().filter(|t| t.status_api.is_some()) { let (tx, path) = (tx.clone(), t.status_api.clone().unwrap()); std::thread::spawn(move || wait_on(t, path, wait, stop, tx)); }@@ -281,7 +332,7 @@ mod tests { #[test] fn a_status_answer_is_a_change_only_when_it_moved() {- let t = Target { mpn: "U7".into(), attempt: 1, status_api: Some("/s".into()), state: "queued".into() };+ let t = Target { mpn: "U7".into(), attempt: 1, status_api: Some("/s".into()), batch: None, state: "queued".into() }; assert_eq!(change_of(&t, false, &json!({"request": {"state": "queued"}})), None); let c = change_of(&t, false, &json!({"request": {"state": "building"}})).unwrap(); assert!(!c.done);@@ -291,6 +342,26 @@ mod tests { assert!(built.done && built.line().contains("/adom/u7")); } + #[test]+ fn a_batchs_parts_share_one_wait_and_its_items_read_as_answers() {+ let mut d = json!({"partRequests": {+ "U7": [{"state": "queued", "statusApi": "/s/7", "batchId": "b_1"}],+ "Q2": [{"state": "queued", "statusApi": "/s/2", "batchId": "b_1"}],+ "J9": [{"state": "queued", "statusApi": "/s/9"}],+ "X1": [{"state": "queued", "batchId": "8"}]}});+ let ts = targets(&d);+ let b: Vec<&str> = ts.iter().filter(|t| t.batch.as_deref() == Some("b_1")).map(|t| t.mpn.as_str()).collect();+ assert_eq!(b, vec!["Q2", "U7"]);+ assert!(ts.iter().find(|t| t.mpn == "X1").unwrap().batch.is_none(), "an older server's factory batch number is not a wiki batch to wait on");+ let t = ts.iter().find(|t| t.mpn == "U7").unwrap();+ let c = change_of(t, false, &item_answer(&json!({"mpn": "U7", "outcome": "built", "page_url": "/adom/u7", "deadline_passed": false}))).unwrap();+ assert!(c.done && c.to == "built" && c.page.as_deref() == Some("/adom/u7"));+ let late = change_of(t, false, &item_answer(&json!({"mpn": "U7", "outcome": "queued", "deadline_passed": true}))).unwrap();+ assert!(late.done && late.late);+ d["partRequests"]["U7"][0]["state"] = json!("built");+ assert_eq!(targets(&d).len(), 3);+ }+ #[test] fn the_thread_options_go_in_the_body() { let mut b = json!({"mpn": "U7"});
docs/release-0.2.150.mdadded+7@@ -0,0 +1,7 @@+# adom-aiflow 0.2.150++`part-request --follow` waits on a board's batch with one wait (the wiki, 2026-12-04). The wiki holds at most 8 waits open per account, and five boards' threads may share one account; 0.2.149 opened one wait per request, so a few boards could use them up, and every further wait would answer at once.++- **One wait per batch.** The parts `part-request --missing` sent together are followed through the batch (`/api/part-request/batches/<id>?wait=50`), not one by one. A part the batch read does not list (one that was already built when the batch was sent, for example) is read by its own status API.+- A request sent alone still waits on its own status API; more than six open waits still poll every 30 seconds.+- A read that answers at once with nothing new (a finished batch, or the account's waits all taken) pauses 10 seconds before the next.
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow", "type": "app",- "version": "0.2.149",+ "version": "0.2.150", "title": "AI Flow", "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.", "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",
page.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow", "type": "app",- "version": "0.2.149",+ "version": "0.2.150", "title": "AI Flow", "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.", "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",
skills/aiflow-sourcing/SKILL.md+1−1@@ -168,7 +168,7 @@ Verified example, 2026-10-08: Pup showed Mouser Access Denied for MF40200V1-1000 1. **Ask the factory, then retry once with better inputs.** Ask for the board's parts together: `adom-aiflow part-request --missing [--ref "<board>"]` sends every part `parts` found with no page as one batch named for the board (default: the board's file name), and keeps each attempt in the run (`partRequests`, the batch in `partBatches`). One part on its own: `adom-aiflow part-request <MPN> [--datasheet <link>]`. A refusal (`cannot_build`, `review`, `unknown`) gets exactly one retry, one part at a time, that changes at least one input. AI Flow does not send the same inputs twice. Pick the change from the refusal (the list below). **The answer comes back to this thread, not to the human's inbox.** A request from AI Flow carries the thread's token, so the wiki sends the human no email about it (an inbox item still records how it ended) and gives it a deadline, 20 minutes by default. Never block the run on the factory:- - after asking, keep working on the rest of the board, and start `adom-aiflow part-request --follow` under the Monitor tool. It waits on the run's open requests (each one's `statusApi`, a read the wiki holds until the state changes), prints one line per change and ends when every request is built, refused or past its deadline. It only reads run.json; then run `part-request --refresh` to record the answers and `parts` to use the new pages. Without Monitor: `adom-wiki api "<statusApi>?wait=50"` answers as soon as the state changes;+ - after asking, keep working on the rest of the board, and start `adom-aiflow part-request --follow` under the Monitor tool. It waits on the run's open requests (one wait per batch, each part asked for alone by its own `statusApi`; the wiki holds the read until something changes), prints one line per change and ends when every request is built, refused or past its deadline. It only reads run.json; then run `part-request --refresh` to record the answers and `parts` to use the new pages. Without Monitor: `adom-wiki api "<statusApi>?wait=50"` answers as soon as the state changes; - a request past its deadline (`deadlinePassed`, the `PART_REQUEST_DEADLINE_PASSED` hint) is planned for as a refusal: retry once with a changed input, build the page yourself (build-a-component-page skill), or go on to step 2. The factory keeps going, and a page that lands later is still picked up by `parts`; - `--deadline <minutes>` (1 to 1440) when the run can wait longer or must move sooner; `--email` only when the human asked to be emailed; - five boards on several Mesh boxes: each thread requests its own board's batch and follows only its own run's requests.