← Commit history

0.2.96: a failed process_list (ab 2.1.189 process_query_failed, or a timeout) no longer reads as Altium not running; fall back to Windows' own process list

Colby Knox ·f86ef9a7cb · ·parent c5d29c2
8 files changed +64−7
CHANGELOG.md+5
@@ -1,5 +1,10 @@ # Changelog +## 0.2.96++- **A failed process query no longer reads as "Altium is not running".** Adom Bridge 2.1.189 limits its `process_list` query to 20 s and answers `process_query_failed` when it does not finish, where it used to return an empty list. A query slower than the bridge's own 15 s wait came back as `ab_unreachable`. In both cases the bridge saw no Altium, so verbs refused with `altium_not_running` while Altium was open. When `process_list` returns no list, the bridge now reads Altium's processes and executable paths from Windows itself, and the instance keys (`AD26`, `ADDevelop`) come out the same.+- Tested on Altium Designer 26.11.1 with Adom Bridge 2.1.189: a build forced onto the Windows path found the running instance with the same key and exe, and 13 lifecycle and board verbs passed on the release build.+ ## 0.2.95  - **The health check no longer calls back into Adom Bridge** (#30, adom/adom-bridge#260). Adom Bridge probes every bridge's `/health` every few seconds. The altium bridge answered it by asking Adom Bridge for Altium's processes and windows, so the answer depended on Adom Bridge being free at that moment. `/health` now reads whether Altium runs straight from Windows, and reports the licence the last verb saw (up to two minutes old) instead of asking. It answers in about 45 ms with the same light: green when Altium runs and is licensed, yellow when it is not running.
bridge-rs/src/instance.rs+36−1
@@ -82,7 +82,7 @@ fn snapshot() -> (Vec<Value>, Vec<Value>) {     }     let pl = ab::call("process_list", json!({"nameFilter": "X2"}), &[], 15);     let ab_down = pl.get("errorCode").and_then(|c| c.as_str()) == Some("ab_unreachable");-    let procs = pl.get("processes").and_then(|a| a.as_array()).cloned().unwrap_or_default();+    let procs = procs_or_native(&pl, native_x2);     let pids: Vec<u64> = procs.iter().filter_map(|p| p.get("pid").and_then(|v| v.as_u64())).collect();     let windows = if pids.is_empty() {         Vec::new()@@ -99,6 +99,26 @@ fn snapshot() -> (Vec<Value>, Vec<Value>) {     (procs, windows) } +/// The X2 processes from ab's `process_list` reply, or from Windows itself when that reply carries no list. ab 2.1.189+/// answers `process_query_failed` when its PowerShell query overruns, and a query slower than our timeout comes back as+/// `ab_unreachable`: in both an empty list would read as "Altium is not running" and every verb would refuse with+/// `altium_not_running` while Altium is up. Pure over the reply; `native` is the fallback.+pub fn procs_or_native(pl: &Value, native: impl Fn() -> Vec<Value>) -> Vec<Value> {+    match pl.get("processes").and_then(|a| a.as_array()) {+        Some(a) => a.clone(),+        None => native(),+    }+}++/// Every X2.EXE from Windows' own process list, with the image path as the command line so the instance key+/// (`AD26`, `ADDevelop`) comes out the same as from ab.+fn native_x2() -> Vec<Value> {+    crate::win32::pids_of("X2.EXE").unwrap_or_default().into_iter().map(|pid| {+        let cl = crate::win32::process_image(pid).map(|p| format!("\"{p}\"")).unwrap_or_default();+        json!({"pid": pid, "commandLine": cl, "source": "windows"})+    }).collect()+}+ /// Every live X2.exe pid (main window or not) — the close watchdog needs "process alive, /// window gone", which instances() alone cannot express. pub fn x2_pids() -> Vec<u64> {@@ -339,6 +359,21 @@ fn licence_state_read() -> Value { mod tests {     use super::*; +    #[test]+    fn a_failed_process_query_is_not_altium_gone() {+        let native = || vec![json!({"pid": 7, "commandLine": r#""C:\Program Files\Altium\AD26\X2.EXE""#})];+        // ab 2.1.189 when its PowerShell query overruns, and our own timeout: ask Windows instead+        for failed in [json!({"success": false, "errorCode": "process_query_failed"}),+                       json!({"success": false, "errorCode": "ab_unreachable"})] {+            let p = procs_or_native(&failed, native);+            assert_eq!(p.len(), 1);+            let exe = p[0]["commandLine"].as_str().and_then(exe_from_command_line);+            assert_eq!(key_for(exe.as_deref(), 7), "AD26");+        }+        // a real empty list is believed+        assert!(procs_or_native(&json!({"success": true, "processes": []}), native).is_empty());+    }+     #[test]     fn key_from_install_folder_survives_restart() {         assert_eq!(key_for(Some(r"C:\Program Files\Altium\AD26\X2.EXE"), 1), "AD26");
bridge-rs/src/main.rs+1−1
@@ -80,7 +80,7 @@ use tiny_http::{Header, Method, Response, Server}; /// Attached to every failed reply (see the /command handler). const REPORT_ISSUES: &str = "If this looks like an altium-bridge BUG (not a refusal you expected), report it: check for a duplicate with `adom-wiki issue list adom/altium-bridge`, then `adom-wiki issue create adom/altium-bridge --title \"<verb>: <one-line symptom>\" --category bug-report --body \"<what you ran, what you expected, what happened, the VERBATIM response JSON (and errorShot if present), bridgeVersion, the Altium version from altium_status, the OS>\"`. A relay, routing, toast or lifecycle problem belongs on adom/adom-bridge instead. Reports from real machines are how this bridge gets correct: three different Altium builds behaved three different ways in one weekend."; -pub const BRIDGE_VERSION: &str = "0.2.95";+pub const BRIDGE_VERSION: &str = "0.2.96";  fn json_response(status: u16, body: &serde_json::Value) -> Response<std::io::Cursor<Vec<u8>>> {     let data = serde_json::to_vec(body).unwrap_or_else(|_| b"{}".to_vec());
bridge-rs/src/win32.rs+18−1
@@ -176,6 +176,7 @@ mod proc_imp {     extern "system" {         fn GetProcessTimes(h: isize, create: *mut FileTime, exit: *mut FileTime, kernel: *mut FileTime, user: *mut FileTime) -> i32;         fn SetStdHandle(id: u32, h: isize) -> i32;+        fn QueryFullProcessImageNameW(h: isize, flags: u32, buf: *mut u16, size: *mut u32) -> i32;     }     const PROCESS_QUERY_LIMITED_INFORMATION: u32 = 0x1000; @@ -195,6 +196,20 @@ mod proc_imp {         }     } +    /// The full path of `pid`'s executable, read from Windows. `None` when it cannot be opened.+    pub fn process_image(pid: u32) -> Option<String> {+        unsafe {+            let h = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid);+            if h == 0 { return None; }+            let mut buf = [0u16; 1024];+            let mut len = buf.len() as u32;+            let ok = QueryFullProcessImageNameW(h, 0, buf.as_mut_ptr(), &mut len);+            CloseHandle(h);+            if ok == 0 { return None; }+            Some(String::from_utf16_lossy(&buf[..len as usize]))+        }+    }+     /// Point this process's stderr at `file`. Rust's own fatal messages (a stack overflow, an allocation failure)     /// go to stderr and then end the process with no panic hook; ab rewrites the bridge's console log on every     /// respawn, so they were lost (#30). The file must stay open for the life of the process.@@ -280,11 +295,13 @@ pub fn child_windows(_parent: i64) -> Vec<ChildWin> { vec![] } #[cfg(windows)] pub use imp::{post_message_close, post_quit_to_thread, visible_windows, WinRow}; #[cfg(windows)]-pub use proc_imp::{kill, pids_of, process_start_time, redirect_stderr};+pub use proc_imp::{kill, pids_of, process_image, process_start_time, redirect_stderr};  #[cfg(not(windows))] pub fn process_start_time(_pid: u32) -> Option<std::time::SystemTime> { None } #[cfg(not(windows))]+pub fn process_image(_pid: u32) -> Option<String> { None }+#[cfg(not(windows))] pub fn redirect_stderr(_file: &std::fs::File) -> bool { false }  #[cfg(not(windows))]
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "altium-bridge",-  "version": "0.2.95",+  "version": "0.2.96",   "type": "app",   "description": "Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.",   "tags": [
page.json+1−1
@@ -4,7 +4,7 @@   "type": "app",   "title": "Altium Bridge: AI for Altium Designer",   "brief": "Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.",-  "version": "0.2.95",+  "version": "0.2.96",   "hero": {     "type": "image",     "path": "screenshots/hero.png"
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-0.2.95+0.2.96
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "altium",   "displayName": "Altium Designer",-  "version": "0.2.95",+  "version": "0.2.96",   "description": "Drive Altium Designer from Adom: a resident DelphiScript agent (eval + the 1,100-command process launcher), the X2 -R command line, UIA over the VCL shell, dialogs by PID, screenshots of every Altium window, and Altium 365.",   "homepage": "https://wiki.adom.inc/adom/altium-bridge",   "docs": "https://wiki.adom.inc/adom/altium-bridge",