Browse Source

Release 0.8.1.28: remove .165/.166 cross-host failover, isolate transient Qt stage overrides from persistent baseline, and add full causal debuglog

XJKJ STL 1 week ago
parent
commit
a04ca36a16

+ 1 - 1
Dockerfile

@@ -14,7 +14,7 @@ COPY config/ ./config/
 COPY build/native/stl_native_server /usr/local/bin/stl_native_server
 COPY build/native/stl_native_server /usr/local/bin/stl_native_server
 
 
 ARG STL_BUILD_COMMIT=vd012-native
 ARG STL_BUILD_COMMIT=vd012-native
-ARG STL_VERSION=0.8.1.27
+ARG STL_VERSION=0.8.1.28
 ENV STL_BUILD_COMMIT=${STL_BUILD_COMMIT} \
 ENV STL_BUILD_COMMIT=${STL_BUILD_COMMIT} \
     STL_VERSION=${STL_VERSION}
     STL_VERSION=${STL_VERSION}
 
 

File diff suppressed because it is too large
+ 1 - 1
README.md


+ 1 - 1
VERSION

@@ -1 +1 @@
-0.8.1.27
+0.8.1.28

+ 3 - 2
docker-compose.yml

@@ -3,9 +3,9 @@ services:
     build:
     build:
       context: .
       context: .
       args:
       args:
-        STL_VERSION: ${STL_VERSION:-0.8.1.27}
+        STL_VERSION: ${STL_VERSION:-0.8.1.28}
         STL_BUILD_COMMIT: ${STL_BUILD_COMMIT:-vd012-native}
         STL_BUILD_COMMIT: ${STL_BUILD_COMMIT:-vd012-native}
-    image: xjkj-stl:0.8.1.27
+    image: xjkj-stl:0.8.1.28
     container_name: xjkj-stl-backend
     container_name: xjkj-stl-backend
     restart: unless-stopped
     restart: unless-stopped
     stop_grace_period: 30s
     stop_grace_period: 30s
@@ -27,6 +27,7 @@ services:
       STL_BMC_S1_PASSWORD: ${STL_BMC_S1_PASSWORD:-Admin123@pl}
       STL_BMC_S1_PASSWORD: ${STL_BMC_S1_PASSWORD:-Admin123@pl}
       STL_BMC_S2_PASSWORD: ${STL_BMC_S2_PASSWORD:-Admin123@pl}
       STL_BMC_S2_PASSWORD: ${STL_BMC_S2_PASSWORD:-Admin123@pl}
       STL_BMC_S3_PASSWORD: ${STL_BMC_S3_PASSWORD:-Admin123@pl}
       STL_BMC_S3_PASSWORD: ${STL_BMC_S3_PASSWORD:-Admin123@pl}
+      STL_BMC_S4_PASSWORD: ${STL_BMC_S4_PASSWORD:-Admin123@pl}
     command:
     command:
       - /usr/local/bin/stl_native_server
       - /usr/local/bin/stl_native_server
       - --config
       - --config

+ 79 - 31
native/stl_accel/src/actors.rs

@@ -7,7 +7,7 @@ use crate::commands::{
 };
 };
 use crate::devices::{
 use crate::devices::{
     close_station_pty, flush_tx_pacer, open_station_pty, poll_station_listener, poll_station_pty,
     close_station_pty, flush_tx_pacer, open_station_pty, poll_station_listener, poll_station_pty,
-    probe_tcp_port, resolve_reachable_bmc_host, run_ipmi_with_session, update_dimms_from_bmc_sdr,
+    probe_tcp_port, run_ipmi_with_session, update_dimms_from_bmc_sdr,
     PersistentIpmiSession,
     PersistentIpmiSession,
 };
 };
 use crate::firmware::FirmwareContract;
 use crate::firmware::FirmwareContract;
@@ -1256,6 +1256,7 @@ pub fn spawn_station_actor(
                         notify_actor();
                         notify_actor();
 
 
                         // Step 2: Hardware discharge / settle wait before powering back on
                         // Step 2: Hardware discharge / settle wait before powering back on
+                        log_pwr("STEP2_DISCHARGE_WAIT_MS=2000");
                         thread::sleep(Duration::from_millis(2000));
                         thread::sleep(Duration::from_millis(2000));
 
 
                         // Step 3: Ensure verified POWER ON (up to 4 retries, 35s timeout)
                         // Step 3: Ensure verified POWER ON (up to 4 retries, 35s timeout)
@@ -1328,26 +1329,21 @@ pub fn spawn_station_actor(
                         let host_reachable = !host.is_empty()
                         let host_reachable = !host.is_empty()
                             && (probe_tcp_port(&host, 22, 180) || probe_tcp_port(&host, 2200, 150));
                             && (probe_tcp_port(&host, 22, 180) || probe_tcp_port(&host, 2200, 150));
                         if !host_reachable {
                         if !host_reachable {
-                            let alt = resolve_reachable_bmc_host(&host, 22);
-                            let alt_reachable = alt != host
-                                && (probe_tcp_port(&alt, 22, 180) || probe_tcp_port(&alt, 2200, 150));
-                            if !alt_reachable {
-                                if !host.is_empty() {
-                                    let _ = actor_tx_for_ipmi.send(StationMsg::IpmiTelemetry {
-                                        resolved_host: None,
-                                        power: Some("unknown".to_string()),
-                                        sdr_output: None,
-                                        bmc_state: Some("offline".to_string()),
-                                    });
-                                    if ev_fd_for_ipmi >= 0 {
-                                        unsafe {
-                                            lib::stl_eventfd_notify(ev_fd_for_ipmi);
-                                        }
+                            if !host.is_empty() {
+                                let _ = actor_tx_for_ipmi.send(StationMsg::IpmiTelemetry {
+                                    resolved_host: None,
+                                    power: Some("unknown".to_string()),
+                                    sdr_output: None,
+                                    bmc_state: Some("offline".to_string()),
+                                });
+                                if ev_fd_for_ipmi >= 0 {
+                                    unsafe {
+                                        lib::stl_eventfd_notify(ev_fd_for_ipmi);
                                     }
                                     }
                                 }
                                 }
-                                ipmi_poll_inflight_worker.store(false, Ordering::Release);
-                                continue;
                             }
                             }
+                            ipmi_poll_inflight_worker.store(false, Ordering::Release);
+                            continue;
                         }
                         }
                         let pwr_res = run_ipmi_with_session(
                         let pwr_res = run_ipmi_with_session(
                             Some(&mut session),
                             Some(&mut session),
@@ -1856,12 +1852,20 @@ pub fn spawn_station_actor(
                                     state_dirty = true;
                                     state_dirty = true;
                                 }
                                 }
                                 if st.bmc_state != bs {
                                 if st.bmc_state != bs {
+                                    st.log_debug(
+                                        "IPMI",
+                                        &format!(
+                                            "BMC_STATE_CHANGE prev={} new={} host={}",
+                                            st.bmc_state, bs, st.bmc_host
+                                        ),
+                                    );
                                     st.bmc_state = bs;
                                     st.bmc_state = bs;
                                     state_dirty = true;
                                     state_dirty = true;
                                 }
                                 }
                             }
                             }
                             if let Some(rh) = resolved_host {
                             if let Some(rh) = resolved_host {
                                 if !rh.is_empty() && rh != st.bmc_host {
                                 if !rh.is_empty() && rh != st.bmc_host {
+                                    let prev_host = st.bmc_host.clone();
                                     if st.console_host == st.bmc_host {
                                     if st.console_host == st.bmc_host {
                                         st.console_host = rh.clone();
                                         st.console_host = rh.clone();
                                     }
                                     }
@@ -1871,6 +1875,13 @@ pub fn spawn_station_actor(
                                     } else if st.bmc_host == "192.168.2.166" {
                                     } else if st.bmc_host == "192.168.2.166" {
                                         st.hot.fw_family = 1;
                                         st.hot.fw_family = 1;
                                     }
                                     }
+                                    st.log_debug(
+                                        "CONN",
+                                        &format!(
+                                            "IPMI_RESOLVED_HOST_CHANGE prev={} new={} console_host={} fw_family={}",
+                                            prev_host, st.bmc_host, st.console_host, st.hot.fw_family
+                                        ),
+                                    );
                                 }
                                 }
                             }
                             }
                             if let Some(pwr) = power {
                             if let Some(pwr) = power {
@@ -1885,6 +1896,17 @@ pub fn spawn_station_actor(
                                     st.clear_bmc_sdr_temps();
                                     st.clear_bmc_sdr_temps();
                                 }
                                 }
                                 if st.server_power != pwr {
                                 if st.server_power != pwr {
+                                    st.log_debug(
+                                        "IPMI",
+                                        &format!(
+                                            "POWER_CHANGE prev={} new={} observed_phase={} run_active={} pwr_seq={}",
+                                            prev_power,
+                                            pwr,
+                                            st.observed_phase,
+                                            st.is_run_active(),
+                                            st.power_seq_in_progress
+                                        ),
+                                    );
                                     st.server_power = pwr.clone();
                                     st.server_power = pwr.clone();
                                     state_dirty = true;
                                     state_dirty = true;
                                 }
                                 }
@@ -1916,6 +1938,13 @@ pub fn spawn_station_actor(
                                     // Never abort an already active test run (e.g. during Training/AMT/MT)
                                     // Never abort an already active test run (e.g. during Training/AMT/MT)
                                     // just because a BMC IPMI power poll recovered/delivered late `off->on` past 20s.
                                     // just because a BMC IPMI power poll recovered/delivered late `off->on` past 20s.
                                     if !st.is_run_active() || was_blocked_or_terminal {
                                     if !st.is_run_active() || was_blocked_or_terminal {
+                                        st.log_debug(
+                                            "IPMI",
+                                            &format!(
+                                                "EXTERNAL_POWER_ON_RESTART prev_power={} bp_state={} was_terminal={}",
+                                                prev_power, bp_state_now, was_blocked_or_terminal
+                                            ),
+                                        );
                                         st.clear_for_external_restart(now_ms(), "power_on", true);
                                         st.clear_for_external_restart(now_ms(), "power_on", true);
                                         st.cleaner.clear_halfline();
                                         st.cleaner.clear_halfline();
                                     } else if st.observed_phase == "powered_off" {
                                     } else if st.observed_phase == "powered_off" {
@@ -2091,6 +2120,15 @@ pub fn spawn_station_actor(
                             full_path,
                             full_path,
                             force,
                             force,
                         } => {
                         } => {
+                            st.log_debug(
+                                "PXE",
+                                &format!(
+                                    "MT_REPORT_MSG_RX force={} verdict={} path={}",
+                                    force,
+                                    report.get_str_or("verdict", ""),
+                                    full_path
+                                ),
+                            );
                             st.apply_mt_html_report(&report, &full_path, force);
                             st.apply_mt_html_report(&report, &full_path, force);
                             step_boot_plan(&mut st, &contract);
                             step_boot_plan(&mut st, &contract);
                             step_task_batch(
                             step_task_batch(
@@ -2111,7 +2149,11 @@ pub fn spawn_station_actor(
                                 push_hub.broadcast_task_complete(&sig);
                                 push_hub.broadcast_task_complete(&sig);
                             }
                             }
                         }
                         }
-                        StationMsg::MtReportSyncDone { fetched: _ } => {
+                        StationMsg::MtReportSyncDone { fetched } => {
+                            st.log_debug(
+                                "PXE",
+                                &format!("MT_REPORT_SYNC_DONE fetched={}", fetched),
+                            );
                             st.mt_report_sync_pending = false;
                             st.mt_report_sync_pending = false;
                             st.mt_report_fetched_for_boot = true;
                             st.mt_report_fetched_for_boot = true;
                             st.mt_waiting_report_until_ms = 0;
                             st.mt_waiting_report_until_ms = 0;
@@ -2398,11 +2440,26 @@ fn handle_actor_start_test(
     }
     }
     st.next_reconnect_probe_ms = 0;
     st.next_reconnect_probe_ms = 0;
 
 
+    let has_task_params = params.get("memory_params").is_some()
+        || params.get("uip_overrides").is_some()
+        || params.get("rmt").is_some()
+        || params.get("amt").is_some()
+        || params.get("mt").is_some()
+        || params.get("ecc").is_some()
+        || params.get("debuglog").is_some()
+        || params.get("target_temp").is_some()
+        || params.get_bool("auto_plan") == Some(true);
+
     st.log_debug(
     st.log_debug(
         "TASK",
         "TASK",
         &format!(
         &format!(
-            "StartTest continue_timer={} prev_boot={} prev_power={} prev_started={}",
-            continue_timer, prev_boot_id, prev_power, preserved_started
+            "StartTest continue_timer={} has_task_params={} keep_saved_boot_plan={} prev_boot={} prev_power={} prev_started={}",
+            continue_timer,
+            has_task_params,
+            params.get_bool("keep_saved_boot_plan").unwrap_or(false),
+            prev_boot_id,
+            prev_power,
+            preserved_started
         ),
         ),
     );
     );
     if params.get("profiles").is_some() || params.get("tasks").is_some() {
     if params.get("profiles").is_some() || params.get("tasks").is_some() {
@@ -2441,16 +2498,6 @@ fn handle_actor_start_test(
         }
         }
     }
     }
 
 
-    let has_task_params = params.get("memory_params").is_some()
-        || params.get("uip_overrides").is_some()
-        || params.get("rmt").is_some()
-        || params.get("amt").is_some()
-        || params.get("mt").is_some()
-        || params.get("ecc").is_some()
-        || params.get("debuglog").is_some()
-        || params.get("target_temp").is_some()
-        || params.get_bool("auto_plan") == Some(true);
-
     if has_task_params {
     if has_task_params {
         if let Err(e) =
         if let Err(e) =
             apply_profile_to_station(st, params, contract, pxe_state, data_dir, pxe_tftp_dir)
             apply_profile_to_station(st, params, contract, pxe_state, data_dir, pxe_tftp_dir)
@@ -2460,6 +2507,7 @@ fn handle_actor_start_test(
     } else {
     } else {
         st.single_run_profile = strip_private_keys_recursive(params);
         st.single_run_profile = strip_private_keys_recursive(params);
         if params.get_bool("keep_saved_boot_plan") != Some(true) {
         if params.get_bool("keep_saved_boot_plan") != Some(true) {
+            st.ensure_persistent_baseline();
             let mut manual_stages = JsonVal::obj();
             let mut manual_stages = JsonVal::obj();
             manual_stages.set("uip1", JsonVal::Str("manual".to_string()));
             manual_stages.set("uip1", JsonVal::Str("manual".to_string()));
             manual_stages.set("amt", JsonVal::Str("manual".to_string()));
             manual_stages.set("amt", JsonVal::Str("manual".to_string()));

+ 120 - 3
native/stl_accel/src/api.rs

@@ -15,8 +15,8 @@ use crate::lib;
 use crate::pxe::build_pxe_snapshot;
 use crate::pxe::build_pxe_snapshot;
 use crate::results::{now_ms, patch_timing_fields, StationState};
 use crate::results::{now_ms, patch_timing_fields, StationState};
 use crate::storage::{
 use crate::storage::{
-    load_audit_logs, load_pxe_state, load_station_settings, record_audit_log,
-    strip_private_keys_recursive,
+    append_debug_log_path, append_system_debug_log, load_audit_logs, load_pxe_state,
+    load_station_settings, record_audit_log, strip_private_keys_recursive,
 };
 };
 use std::collections::{BTreeMap, HashMap};
 use std::collections::{BTreeMap, HashMap};
 use std::env;
 use std::env;
@@ -244,6 +244,32 @@ impl AppHub {
         // Prime initial zero-copy QtClean state snapshot immediately
         // Prime initial zero-copy QtClean state snapshot immediately
         hub.refresh_and_broadcast_qt_state();
         hub.refresh_and_broadcast_qt_state();
 
 
+        let mut st_desc = Vec::new();
+        for (sid, handle) in &hub.stations {
+            if let Ok(v) = handle.view.read() {
+                st_desc.push(format!(
+                    "{}:bmc({}@{})/con({}@{})",
+                    sid,
+                    if v.bmc_enabled { "on" } else { "off" },
+                    v.bmc_host,
+                    if v.console_enabled { "on" } else { "off" },
+                    v.console_host
+                ));
+            }
+        }
+        append_system_debug_log(
+            &hub.data_dir,
+            "SYS",
+            &format!(
+                "SERVER_INIT version={} commit={} web_auth={} bg_probes={} stations=[{}]",
+                hub.version,
+                hub.commit,
+                hub.web_password.is_some(),
+                enable_hw_bg_probes,
+                st_desc.join(", ")
+            ),
+        );
+
         if enable_hw_bg_probes {
         if enable_hw_bg_probes {
             let bg_hub = Arc::clone(&hub);
             let bg_hub = Arc::clone(&hub);
             thread::Builder::new()
             thread::Builder::new()
@@ -352,6 +378,16 @@ impl AppHub {
             sess.set("connect_count", JsonVal::Num((prev_count + 1) as f64));
             sess.set("connect_count", JsonVal::Num((prev_count + 1) as f64));
             sess.set("last_connected_unix_ms", JsonVal::Num(now as f64));
             sess.set("last_connected_unix_ms", JsonVal::Num(now as f64));
             book.client_sessions.insert(client_id.to_string(), sess);
             book.client_sessions.insert(client_id.to_string(), sess);
+            append_system_debug_log(
+                &self.data_dir,
+                "WS",
+                &format!(
+                    "WS_CONNECT client_id={} view={} connect_count={}",
+                    client_id,
+                    view_mode,
+                    prev_count + 1
+                ),
+            );
         }
         }
     }
     }
 
 
@@ -852,6 +888,69 @@ impl AppHub {
         method: &str,
         method: &str,
         params: &JsonVal,
         params: &JsonVal,
         is_qt_clean: bool,
         is_qt_clean: bool,
+    ) -> Result<JsonVal, (String, String)> {
+        let res = self.dispatch_rpc_inner(method, params, is_qt_clean);
+        let is_polling = matches!(
+            method,
+            "GetState"
+                | "ListStations"
+                | "GetStation"
+                | "GetStationControl"
+                | "GetDiagnostic"
+                | "ReadCleanedUart"
+                | "ReadBiosUart"
+                | "ReadDiagnosticSol"
+                | "ReadSol"
+                | "GetTaskStatus"
+                | "GetTaskBatch"
+                | "GetCommand"
+                | "GetQueue"
+                | "GetQueueItem"
+                | "GetThermalConsole"
+                | "GetFirmwareCatalog"
+                | "ReadAuditLogs"
+                | "QueryAuditLogs"
+                | "ReadEventQueue"
+        );
+        if !is_polling || res.is_err() {
+            let sid = params.get_str_or("station_id", "");
+            let sub = if method == "EnqueueCommand" {
+                params.get_str_or("method", "")
+            } else {
+                params.get_str_or("action", "")
+            };
+            let stage = params.get_str_or("stage", "");
+            let status_str = match &res {
+                Ok(_) => "ok=true".to_string(),
+                Err((code, msg)) => format!("ok=false err={}:{}", code, msg),
+            };
+            let msg = format!(
+                "view={} method={} sid={} sub={} stage={} {}",
+                if is_qt_clean { "qt-clean" } else { "web" },
+                method,
+                sid,
+                sub,
+                stage,
+                status_str
+            );
+            append_system_debug_log(&self.data_dir, "RPC", &msg);
+            if !sid.is_empty() && self.stations.contains_key(&sid) {
+                append_debug_log_path(
+                    &self.data_dir.join("debug").join(format!("{}.log", sid)),
+                    &sid,
+                    "RPC",
+                    &msg,
+                );
+            }
+        }
+        res
+    }
+
+    fn dispatch_rpc_inner(
+        &self,
+        method: &str,
+        params: &JsonVal,
+        is_qt_clean: bool,
     ) -> Result<JsonVal, (String, String)> {
     ) -> Result<JsonVal, (String, String)> {
         if is_qt_clean {
         if is_qt_clean {
             match method {
             match method {
@@ -1673,6 +1772,7 @@ fn handle_ws_loop(
     write_stream: Arc<Mutex<TcpStream>>,
     write_stream: Arc<Mutex<TcpStream>>,
     hub: Arc<AppHub>,
     hub: Arc<AppHub>,
     is_qt_clean: bool,
     is_qt_clean: bool,
+    client_id: &str,
 ) {
 ) {
     let closed = Arc::new(AtomicBool::new(false));
     let closed = Arc::new(AtomicBool::new(false));
     let closed_for_push = Arc::clone(&closed);
     let closed_for_push = Arc::clone(&closed);
@@ -1843,6 +1943,15 @@ fn handle_ws_loop(
     }
     }
 
 
     closed.store(true, Ordering::Release);
     closed.store(true, Ordering::Release);
+    append_system_debug_log(
+        &hub.data_dir,
+        "WS",
+        &format!(
+            "WS_DISCONNECT client_id={} view={}",
+            client_id,
+            if is_qt_clean { "qt-clean" } else { "full" }
+        ),
+    );
 }
 }
 
 
 const WEB_SESSION_COOKIE: &str = "stl_auth";
 const WEB_SESSION_COOKIE: &str = "stl_auth";
@@ -2230,6 +2339,7 @@ pub fn handle_http_client(mut stream: TcpStream, hub: Arc<AppHub>) {
         };
         };
 
 
         if hub.verify_web_password(&candidate) {
         if hub.verify_web_password(&candidate) {
+            append_system_debug_log(&hub.data_dir, "AUTH", "WEB_LOGIN ok=true");
             let set_cookie = if hub.web_password.is_some() {
             let set_cookie = if hub.web_password.is_some() {
                 let token = hub.issue_web_session();
                 let token = hub.issue_web_session();
                 format!(
                 format!(
@@ -2248,6 +2358,7 @@ pub fn handle_http_client(mut stream: TcpStream, hub: Arc<AppHub>) {
             );
             );
             let _ = stream.write_all(resp.as_bytes());
             let _ = stream.write_all(resp.as_bytes());
         } else {
         } else {
+            append_system_debug_log(&hub.data_dir, "AUTH", "WEB_LOGIN ok=false");
             let err_body = r#"{"ok":false,"error":{"code":"UNAUTHORIZED","message":"管理密码错误"}}"#;
             let err_body = r#"{"ok":false,"error":{"code":"UNAUTHORIZED","message":"管理密码错误"}}"#;
             let resp = format!(
             let resp = format!(
                 "HTTP/1.1 401 Unauthorized\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: {}\r\nCache-Control: no-store\r\nConnection: close\r\n\r\n{}",
                 "HTTP/1.1 401 Unauthorized\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: {}\r\nCache-Control: no-store\r\nConnection: close\r\n\r\n{}",
@@ -2261,6 +2372,7 @@ pub fn handle_http_client(mut stream: TcpStream, hub: Arc<AppHub>) {
     }
     }
 
 
     if method == "POST" && path_only == "/api/auth/logout" {
     if method == "POST" && path_only == "/api/auth/logout" {
+        append_system_debug_log(&hub.data_dir, "AUTH", "WEB_LOGOUT");
         if let Some(tok) = parse_cookie_value(&cookie_header, WEB_SESSION_COOKIE) {
         if let Some(tok) = parse_cookie_value(&cookie_header, WEB_SESSION_COOKIE) {
             hub.revoke_web_session(&tok);
             hub.revoke_web_session(&tok);
         }
         }
@@ -2280,6 +2392,11 @@ pub fn handle_http_client(mut stream: TcpStream, hub: Arc<AppHub>) {
         let view_val = parse_query_view(raw_target);
         let view_val = parse_query_view(raw_target);
         let is_qt_clean = view_val == "qt-clean";
         let is_qt_clean = view_val == "qt-clean";
         if !is_qt_clean && !hub.is_http_authorized(&auth_header, &cookie_header) {
         if !is_qt_clean && !hub.is_http_authorized(&auth_header, &cookie_header) {
+            append_system_debug_log(
+                &hub.data_dir,
+                "AUTH",
+                &format!("WS_UNAUTHORIZED target={} client_id={}", raw_target, client_id),
+            );
             let err_body = r#"{"ok":false,"error":{"code":"UNAUTHORIZED","message":"WebSocket /ws 需要先通过管理密码认证"}}"#;
             let err_body = r#"{"ok":false,"error":{"code":"UNAUTHORIZED","message":"WebSocket /ws 需要先通过管理密码认证"}}"#;
             let resp = format!(
             let resp = format!(
                 "HTTP/1.1 401 Unauthorized\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: {}\r\nCache-Control: no-store\r\nConnection: close\r\n\r\n{}",
                 "HTTP/1.1 401 Unauthorized\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: {}\r\nCache-Control: no-store\r\nConnection: close\r\n\r\n{}",
@@ -2306,7 +2423,7 @@ pub fn handle_http_client(mut stream: TcpStream, hub: Arc<AppHub>) {
             if let Ok(write_tcp) = stream.try_clone() {
             if let Ok(write_tcp) = stream.try_clone() {
                 let _ = write_tcp.set_nodelay(true);
                 let _ = write_tcp.set_nodelay(true);
                 let write_stream = Arc::new(Mutex::new(write_tcp));
                 let write_stream = Arc::new(Mutex::new(write_tcp));
-                handle_ws_loop(stream, write_stream, hub, is_qt_clean);
+                handle_ws_loop(stream, write_stream, hub, is_qt_clean, &client_id);
             }
             }
         }
         }
         return;
         return;

+ 82 - 9
native/stl_accel/src/commands.rs

@@ -184,7 +184,21 @@ pub fn handle_station_command_nonblocking(
             } else {
             } else {
                 args.get_str_or("action", "enable").to_ascii_lowercase()
                 args.get_str_or("action", "enable").to_ascii_lowercase()
             };
             };
+            st.ensure_persistent_baseline();
             let seq = st.set_stage_intent(&stage, &action, args);
             let seq = st.set_stage_intent(&stage, &action, args);
+            st.log_debug(
+                "INTENT",
+                &format!(
+                    "SET_STAGE_INTENT stage={} action={} seq={} operator={} has_mem_params={} has_amt={} has_mt={}",
+                    stage,
+                    action,
+                    seq,
+                    operator,
+                    args.get("memory_params").is_some(),
+                    args.get("amt").is_some() || args.get("settings").is_some(),
+                    args.get("mt").is_some() || args.get("selection").is_some(),
+                ),
+            );
             match stage.as_str() {
             match stage.as_str() {
                 "uip" | "uip1" | "uip2" => {
                 "uip" | "uip1" | "uip2" => {
                     if let Some(ovs) = args.get_arr("uip_overrides") {
                     if let Some(ovs) = args.get_arr("uip_overrides") {
@@ -370,7 +384,7 @@ pub fn handle_station_command_nonblocking(
                 }
                 }
                 _ => {}
                 _ => {}
             }
             }
-            save_station_settings(data_dir, st);
+            // Transient in-memory intent update only — never overwrite persistent Web baseline on disk!
             let mut res = JsonVal::obj();
             let mut res = JsonVal::obj();
             res.set("stage", JsonVal::Str(stage.clone()));
             res.set("stage", JsonVal::Str(stage.clone()));
             res.set("action", JsonVal::Str(action.clone()));
             res.set("action", JsonVal::Str(action.clone()));
@@ -418,6 +432,7 @@ pub fn handle_station_command_nonblocking(
                     }
                     }
                 }
                 }
             }
             }
+            st.clear_persistent_baseline();
             save_station_settings(data_dir, st);
             save_station_settings(data_dir, st);
             let preset_label = found
             let preset_label = found
                 .get_str("label")
                 .get_str("label")
@@ -469,6 +484,7 @@ pub fn handle_station_command_nonblocking(
                 {
                 {
                     extra_lines.extend(built);
                     extra_lines.extend(built);
                 }
                 }
+                st.ensure_persistent_baseline();
                 if !ovs.is_empty() {
                 if !ovs.is_empty() {
                     st.uip_overrides = ovs;
                     st.uip_overrides = ovs;
                 }
                 }
@@ -477,8 +493,12 @@ pub fn handle_station_command_nonblocking(
                 }
                 }
             }
             }
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uip" {
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uip" {
+                st.ensure_persistent_baseline();
                 let seq = st.set_stage_intent("uip", "continue_uip", args);
                 let seq = st.set_stage_intent("uip", "continue_uip", args);
-                save_station_settings(data_dir, st);
+                st.log_debug(
+                    "INTENT",
+                    &format!("QUEUED method=ContinueUip stage=uip seq={} operator={}", seq, operator),
+                );
                 let mut res = JsonVal::obj();
                 let mut res = JsonVal::obj();
                 res.set("action", JsonVal::Str("ContinueUip".to_string()));
                 res.set("action", JsonVal::Str("ContinueUip".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
@@ -550,12 +570,17 @@ pub fn handle_station_command_nonblocking(
                 })
                 })
                 .unwrap_or(false);
                 .unwrap_or(false);
             if !(st.prompt_ready && st.prompt_kind == "amt" && this_cpu_done) {
             if !(st.prompt_ready && st.prompt_kind == "amt" && this_cpu_done) {
+                st.ensure_persistent_baseline();
                 st.amt_settings
                 st.amt_settings
                     .set("action", JsonVal::Str("skip".to_string()));
                     .set("action", JsonVal::Str("skip".to_string()));
             }
             }
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
+                st.ensure_persistent_baseline();
                 let seq = st.set_stage_intent("amt", "skip_amt", args);
                 let seq = st.set_stage_intent("amt", "skip_amt", args);
-                save_station_settings(data_dir, st);
+                st.log_debug(
+                    "INTENT",
+                    &format!("QUEUED method=SkipAmt stage=amt seq={} operator={}", seq, operator),
+                );
                 let mut res = JsonVal::obj();
                 let mut res = JsonVal::obj();
                 res.set("action", JsonVal::Str("SkipAmt".to_string()));
                 res.set("action", JsonVal::Str("SkipAmt".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
@@ -599,6 +624,7 @@ pub fn handle_station_command_nonblocking(
                 let pxe_host = pxe_state.get_str_or("pxe_host", "");
                 let pxe_host = pxe_state.get_str_or("pxe_host", "");
                 sync_mt86_cfg_all_candidates(&pxe_host, pxe_tftp_dir, &cfg_text);
                 sync_mt86_cfg_all_candidates(&pxe_host, pxe_tftp_dir, &cfg_text);
             }
             }
+            st.clear_persistent_baseline();
             save_station_settings(data_dir, st);
             save_station_settings(data_dir, st);
             let mut details = JsonVal::obj();
             let mut details = JsonVal::obj();
             details.set(
             details.set(
@@ -663,11 +689,15 @@ pub fn handle_station_command_nonblocking(
                     Ok(c) => c,
                     Ok(c) => c,
                     Err(e) => return StationCmdExec::Immediate(Err(e), None),
                     Err(e) => return StationCmdExec::Immediate(Err(e), None),
                 };
                 };
+            st.ensure_persistent_baseline();
             st.uip_overrides = ovs;
             st.uip_overrides = ovs;
             st.uip_raw_commands = raws;
             st.uip_raw_commands = raws;
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uip" {
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uip" {
                 let seq = st.set_stage_intent("uip", "apply_uip", args);
                 let seq = st.set_stage_intent("uip", "apply_uip", args);
-                save_station_settings(data_dir, st);
+                st.log_debug(
+                    "INTENT",
+                    &format!("QUEUED method=ApplyUipParameters stage=uip seq={} lines={} operator={}", seq, lines.len(), operator),
+                );
                 let mut res = JsonVal::obj();
                 let mut res = JsonVal::obj();
                 res.set(
                 res.set(
                     "commands",
                     "commands",
@@ -745,6 +775,7 @@ pub fn handle_station_command_nonblocking(
                 Err(e) => return StationCmdExec::Immediate(Err(e), None),
                 Err(e) => return StationCmdExec::Immediate(Err(e), None),
             };
             };
             st.amt_settings = settings.clone();
             st.amt_settings = settings.clone();
+            st.clear_persistent_baseline();
             save_station_settings(data_dir, st);
             save_station_settings(data_dir, st);
             let mut details = JsonVal::obj();
             let mut details = JsonVal::obj();
             details.set("amt_settings", settings.clone());
             details.set("amt_settings", settings.clone());
@@ -785,9 +816,13 @@ pub fn handle_station_command_nonblocking(
                 Err(e) => return StationCmdExec::Immediate(Err(e), None),
                 Err(e) => return StationCmdExec::Immediate(Err(e), None),
             };
             };
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
+                st.ensure_persistent_baseline();
                 st.amt_settings = settings;
                 st.amt_settings = settings;
                 let seq = st.set_stage_intent("amt", "enable", args);
                 let seq = st.set_stage_intent("amt", "enable", args);
-                save_station_settings(data_dir, st);
+                st.log_debug(
+                    "INTENT",
+                    &format!("QUEUED method=ApplyAmtSettings stage=amt seq={} cmds={} operator={}", seq, cmds.len(), operator),
+                );
                 let mut res = JsonVal::obj();
                 let mut res = JsonVal::obj();
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("sequence", JsonVal::Num(seq as f64));
                 res.set("sequence", JsonVal::Num(seq as f64));
@@ -885,11 +920,15 @@ pub fn handle_station_command_nonblocking(
             if args.get_bool("run_amt") == Some(false)
             if args.get_bool("run_amt") == Some(false)
                 || args.get("amt").and_then(|a| a.get_bool("enabled")) == Some(false)
                 || args.get("amt").and_then(|a| a.get_bool("enabled")) == Some(false)
             {
             {
+                st.ensure_persistent_baseline();
                 st.amt_settings
                 st.amt_settings
                     .set("action", JsonVal::Str("skip".to_string()));
                     .set("action", JsonVal::Str("skip".to_string()));
                 if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
                 if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
                     let seq = st.set_stage_intent("amt", "skip_amt", args);
                     let seq = st.set_stage_intent("amt", "skip_amt", args);
-                    save_station_settings(data_dir, st);
+                    st.log_debug(
+                        "INTENT",
+                        &format!("QUEUED method=StartAmt_skip stage=amt seq={} operator={}", seq, operator),
+                    );
                     let mut res = JsonVal::obj();
                     let mut res = JsonVal::obj();
                     res.set("action", JsonVal::Str("SkipAmt".to_string()));
                     res.set("action", JsonVal::Str("SkipAmt".to_string()));
                     res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                     res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
@@ -918,10 +957,14 @@ pub fn handle_station_command_nonblocking(
                 .unwrap_or_default();
                 .unwrap_or_default();
             let mut merged_amt = effective_settings.clone();
             let mut merged_amt = effective_settings.clone();
             merged_amt.set("action", JsonVal::Str("run".to_string()));
             merged_amt.set("action", JsonVal::Str("run".to_string()));
+            st.ensure_persistent_baseline();
             st.amt_settings = merged_amt;
             st.amt_settings = merged_amt;
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "amt" {
                 let seq = st.set_stage_intent("amt", "start_amt", args);
                 let seq = st.set_stage_intent("amt", "start_amt", args);
-                save_station_settings(data_dir, st);
+                st.log_debug(
+                    "INTENT",
+                    &format!("QUEUED method=StartAmt stage=amt seq={} cmds={} operator={}", seq, setup_cmds.len(), operator),
+                );
                 let mut res = JsonVal::obj();
                 let mut res = JsonVal::obj();
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("sequence", JsonVal::Num(seq as f64));
                 res.set("sequence", JsonVal::Num(seq as f64));
@@ -977,11 +1020,15 @@ pub fn handle_station_command_nonblocking(
             if let Some(err) = input_id_mismatch_err(st, args) {
             if let Some(err) = input_id_mismatch_err(st, args) {
                 return StationCmdExec::Immediate(Err(err), None);
                 return StationCmdExec::Immediate(Err(err), None);
             }
             }
+            st.ensure_persistent_baseline();
             st.boot_plan.set("mt_enabled", JsonVal::Bool(false));
             st.boot_plan.set("mt_enabled", JsonVal::Bool(false));
             st.boot_plan.set("run_mt", JsonVal::Bool(false));
             st.boot_plan.set("run_mt", JsonVal::Bool(false));
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uefi" {
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uefi" {
                 let seq = st.set_stage_intent("mt", "skip_mt", args);
                 let seq = st.set_stage_intent("mt", "skip_mt", args);
-                save_station_settings(data_dir, st);
+                st.log_debug(
+                    "INTENT",
+                    &format!("QUEUED method=SkipMt stage=mt seq={} operator={}", seq, operator),
+                );
                 let mut res = JsonVal::obj();
                 let mut res = JsonVal::obj();
                 res.set("action", JsonVal::Str("SkipMt".to_string()));
                 res.set("action", JsonVal::Str("SkipMt".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
@@ -1024,6 +1071,7 @@ pub fn handle_station_command_nonblocking(
             let pxe_host = pxe_state.get_str_or("pxe_host", "");
             let pxe_host = pxe_state.get_str_or("pxe_host", "");
             sync_mt86_cfg_all_candidates(&pxe_host, pxe_tftp_dir, &cfg_text);
             sync_mt86_cfg_all_candidates(&pxe_host, pxe_tftp_dir, &cfg_text);
 
 
+            st.ensure_persistent_baseline();
             st.mt_selection = sel.clone();
             st.mt_selection = sel.clone();
             st.boot_plan.set("mt_enabled", JsonVal::Bool(true));
             st.boot_plan.set("mt_enabled", JsonVal::Bool(true));
             st.boot_plan.set("run_mt", JsonVal::Bool(true));
             st.boot_plan.set("run_mt", JsonVal::Bool(true));
@@ -1035,7 +1083,10 @@ pub fn handle_station_command_nonblocking(
                 .replace('/', "\\");
                 .replace('/', "\\");
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uefi" {
             if st.diag_state != "online" || !st.prompt_ready || st.prompt_kind != "uefi" {
                 let seq = st.set_stage_intent("mt", "start_mt", args);
                 let seq = st.set_stage_intent("mt", "start_mt", args);
-                save_station_settings(data_dir, st);
+                st.log_debug(
+                    "INTENT",
+                    &format!("QUEUED method=StartMt stage=mt seq={} operator={}", seq, operator),
+                );
                 let mut res = JsonVal::obj();
                 let mut res = JsonVal::obj();
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("confirmation", JsonVal::Str("queued_intent".to_string()));
                 res.set("sequence", JsonVal::Num(seq as f64));
                 res.set("sequence", JsonVal::Num(seq as f64));
@@ -1136,6 +1187,7 @@ pub fn handle_station_command_nonblocking(
             };
             };
             let norm = normalize_boot_plan(raw_plan);
             let norm = normalize_boot_plan(raw_plan);
             st.boot_plan = norm.clone();
             st.boot_plan = norm.clone();
+            st.clear_persistent_baseline();
             save_station_settings(data_dir, st);
             save_station_settings(data_dir, st);
             let audit = AuditRecordDraft {
             let audit = AuditRecordDraft {
                 category: "boot_plan".to_string(),
                 category: "boot_plan".to_string(),
@@ -1289,6 +1341,8 @@ pub fn handle_station_command_nonblocking(
             {
             {
                 return StationCmdExec::Immediate(Err(e), None);
                 return StationCmdExec::Immediate(Err(e), None);
             }
             }
+            st.clear_persistent_baseline();
+            save_station_settings(data_dir, st);
             let audit = AuditRecordDraft {
             let audit = AuditRecordDraft {
                 category: "profile_library".to_string(),
                 category: "profile_library".to_string(),
                 action: "load_profile_to_workspace".to_string(),
                 action: "load_profile_to_workspace".to_string(),
@@ -1424,6 +1478,7 @@ pub fn handle_station_command_nonblocking(
                 "clear" => {
                 "clear" => {
                     st.confirm_dimm_replacement();
                     st.confirm_dimm_replacement();
                     st.single_run_active = false;
                     st.single_run_active = false;
+                    st.restore_persistent_baseline("control_task_batch_clear");
                     let now = now_ms();
                     let now = now_ms();
                     st.task_batch.set("batch_id", JsonVal::Str(String::new()));
                     st.task_batch.set("batch_id", JsonVal::Str(String::new()));
                     st.task_batch.set("state", JsonVal::Str("idle".to_string()));
                     st.task_batch.set("state", JsonVal::Str("idle".to_string()));
@@ -1451,6 +1506,16 @@ pub fn handle_station_command_nonblocking(
                 }
                 }
             }
             }
             save_station_settings(data_dir, st);
             save_station_settings(data_dir, st);
+            st.log_debug(
+                "BATCH",
+                &format!(
+                    "CONTROL_TASK_BATCH action={} batch_id={} state={} operator={}",
+                    act,
+                    st.task_batch.get_str_or("batch_id", ""),
+                    st.task_batch.get_str_or("state", ""),
+                    operator
+                ),
+            );
             let audit = AuditRecordDraft {
             let audit = AuditRecordDraft {
                 category: "task_batch".to_string(),
                 category: "task_batch".to_string(),
                 action: format!("control_task_batch_{}", act),
                 action: format!("control_task_batch_{}", act),
@@ -1559,6 +1624,13 @@ pub fn handle_station_command_nonblocking(
             };
             };
             crate::devices::register_station_host_claim(&st.station_id, claimed);
             crate::devices::register_station_host_claim(&st.station_id, claimed);
             save_station_settings(data_dir, st);
             save_station_settings(data_dir, st);
+            st.log_debug(
+                "CONN",
+                &format!(
+                    "CONFIGURE_CONNECTIONS bmc_enabled={} bmc_host={} console_enabled={} console={}:{}({}) operator={}",
+                    st.bmc_enabled, st.bmc_host, st.console_enabled, st.console_host, st.console_port, st.console_transport, operator
+                ),
+            );
             // Online one-click switch & auto-reconnect without manual disconnect!
             // Online one-click switch & auto-reconnect without manual disconnect!
             if st.console_enabled
             if st.console_enabled
                 && (!st.console_host.is_empty()
                 && (!st.console_host.is_empty()
@@ -1608,6 +1680,7 @@ pub fn handle_station_command_nonblocking(
                             st.uip_raw_commands.push(cmd.to_string());
                             st.uip_raw_commands.push(cmd.to_string());
                         }
                         }
                     }
                     }
+                    st.clear_persistent_baseline();
                     save_station_settings(data_dir, st);
                     save_station_settings(data_dir, st);
                 }
                 }
                 let audit = AuditRecordDraft {
                 let audit = AuditRecordDraft {

+ 52 - 22
native/stl_accel/src/devices.rs

@@ -53,28 +53,10 @@ pub fn probe_tcp_port(host: &str, port: u16, timeout_ms: u64) -> bool {
     TcpStream::connect_timeout(&addr, Duration::from_millis(timeout_ms)).is_ok()
     TcpStream::connect_timeout(&addr, Duration::from_millis(timeout_ms)).is_ok()
 }
 }
 
 
-/// Auto-probe failover between 192.168.2.166 and 192.168.2.165 when preferred BMC is unreachable,
-/// while strictly preventing an offline station from hijacking a sibling host already claimed by another station.
-pub fn resolve_reachable_bmc_host(preferred: &str, port: u16) -> String {
-    let trimmed = preferred.trim();
-    if trimmed.is_empty() || trimmed.starts_with("/dev/") {
-        return trimmed.to_string();
-    }
-    let check_port = if port > 0 { port } else { 22 };
-    if probe_tcp_port(trimmed, check_port, 80) {
-        return trimmed.to_string();
-    }
-    let sibling = match trimmed {
-        "192.168.2.165" => Some("192.168.2.166"),
-        "192.168.2.166" => Some("192.168.2.165"),
-        _ => None,
-    };
-    if let Some(alt) = sibling {
-        if !is_host_claimed_by_other(trimmed, alt) && probe_tcp_port(alt, check_port, 80) {
-            return alt.to_string();
-        }
-    }
-    trimmed.to_string()
+/// Strictly resolve to the explicitly configured host (cross-host .165 <-> .166 failover removed
+/// so multi-backend deployments never silently hijack another host's SUT).
+pub fn resolve_reachable_bmc_host(preferred: &str, _port: u16) -> String {
+    preferred.trim().to_string()
 }
 }
 
 
 pub fn close_station_listener(st: &mut StationState) {
 pub fn close_station_listener(st: &mut StationState) {
@@ -86,6 +68,7 @@ pub fn close_station_listener(st: &mut StationState) {
 }
 }
 
 
 pub fn open_station_pty(st: &mut StationState, data_dir: &Path) -> Result<(), String> {
 pub fn open_station_pty(st: &mut StationState, data_dir: &Path) -> Result<(), String> {
+    let prev_diag_err = st.diag_last_error.clone();
     close_station_pty(st);
     close_station_pty(st);
     st.diag_last_error.clear();
     st.diag_last_error.clear();
     if !st.console_enabled {
     if !st.console_enabled {
@@ -194,6 +177,15 @@ pub fn open_station_pty(st: &mut StationState, data_dir: &Path) -> Result<(), St
             st.console_online = false;
             st.console_online = false;
             st.hot.console_online = false;
             st.hot.console_online = false;
             st.diag_last_error = format!("目标串口 {}:{} 当前不可达", st.console_host, port_u16);
             st.diag_last_error = format!("目标串口 {}:{} 当前不可达", st.console_host, port_u16);
+            if prev_diag_err != st.diag_last_error {
+                st.log_debug(
+                    "CONN",
+                    &format!(
+                        "PTY_PROBE_UNREACHABLE host={} port={} err={}",
+                        st.console_host, port_u16, st.diag_last_error
+                    ),
+                );
+            }
             return Err(st.diag_last_error.clone());
             return Err(st.diag_last_error.clone());
         }
         }
         let primary_pass = if st.bmc_password.is_empty() {
         let primary_pass = if st.bmc_password.is_empty() {
@@ -251,6 +243,13 @@ pub fn open_station_pty(st: &mut StationState, data_dir: &Path) -> Result<(), St
         if st.diag_last_error.is_empty() {
         if st.diag_last_error.is_empty() {
             st.diag_last_error = "无法建立串口会话".to_string();
             st.diag_last_error = "无法建立串口会话".to_string();
         }
         }
+        st.log_debug(
+            "CONN",
+            &format!(
+                "PTY_OPEN_FAIL host={} port={} transport={} err={}",
+                st.console_host, st.console_port, st.console_transport, st.diag_last_error
+            ),
+        );
         return Err(st.diag_last_error.clone());
         return Err(st.diag_last_error.clone());
     }
     }
     let now = now_ms();
     let now = now_ms();
@@ -266,11 +265,25 @@ pub fn open_station_pty(st: &mut StationState, data_dir: &Path) -> Result<(), St
     }
     }
     st.diag_last_error.clear();
     st.diag_last_error.clear();
     st.tx_pacer.clear();
     st.tx_pacer.clear();
+    st.log_debug(
+        "CONN",
+        &format!(
+            "PTY_OPEN_OK host={} port={} transport={} fd={} pid={} session={}",
+            st.console_host, st.console_port, st.console_transport, mfd, cpid, st.diag_session_id
+        ),
+    );
     Ok(())
     Ok(())
 }
 }
 
 
 pub fn close_station_pty(st: &mut StationState) {
 pub fn close_station_pty(st: &mut StationState) {
     if st.pty_master_fd >= 0 {
     if st.pty_master_fd >= 0 {
+        st.log_debug(
+            "CONN",
+            &format!(
+                "PTY_CLOSE fd={} pid={} rx_bytes={} last_err={}",
+                st.pty_master_fd, st.pty_child_pid, st.pty_rx_bytes_this_session, st.diag_last_error
+            ),
+        );
         unsafe { lib::c_pty_close(st.pty_master_fd, st.pty_child_pid) };
         unsafe { lib::c_pty_close(st.pty_master_fd, st.pty_child_pid) };
         st.pty_master_fd = -1;
         st.pty_master_fd = -1;
         st.pty_child_pid = -1;
         st.pty_child_pid = -1;
@@ -308,6 +321,10 @@ pub fn poll_station_listener(st: &mut StationState) -> bool {
     }
     }
     st.diag_last_error.clear();
     st.diag_last_error.clear();
     st.tx_pacer.clear();
     st.tx_pacer.clear();
+    st.log_debug(
+        "CONN",
+        &format!("TCP_LISTENER_ACCEPT fd={} port={}", accepted, st.tcp_listener_port),
+    );
     true
     true
 }
 }
 
 
@@ -342,6 +359,18 @@ pub fn poll_station_pty(st: &mut StationState) -> isize {
             {
             {
                 st.ssh_alt_password = !st.ssh_alt_password;
                 st.ssh_alt_password = !st.ssh_alt_password;
             }
             }
+            st.log_debug(
+                "CONN",
+                &format!(
+                    "PTY_EOF n={} alive_check={} elapsed_ms={} rx_bytes={} auth_failed={} ssh_alt_pw={}",
+                    n,
+                    if st.pty_child_pid <= -100 { 0 } else { 1 },
+                    elapsed,
+                    st.pty_rx_bytes_this_session,
+                    auth_failed,
+                    st.ssh_alt_password
+                ),
+            );
             close_station_pty(st);
             close_station_pty(st);
             return -1;
             return -1;
         } else {
         } else {
@@ -410,6 +439,7 @@ pub fn flush_tx_pacer(st: &mut StationState, now: i64) -> Result<(), String> {
         }
         }
         let rc = unsafe { lib::c_pty_write_bytes(st.pty_master_fd, chunk.as_ptr(), take_capped) };
         let rc = unsafe { lib::c_pty_write_bytes(st.pty_master_fd, chunk.as_ptr(), take_capped) };
         if rc < 0 {
         if rc < 0 {
+            st.log_debug("TX", &format!("TX_WRITE_ERR rc={} queued_rem={}", rc, st.tx_pacer.queue.len()));
             close_station_pty(st);
             close_station_pty(st);
             return Err("串口写入失败,连接已断开".to_string());
             return Err("串口写入失败,连接已断开".to_string());
         }
         }

+ 150 - 0
native/stl_accel/src/main.rs

@@ -4053,4 +4053,154 @@ FS0:\\EFI\\> \r\n",
         let _ = try_ingest_local_pxe_report(&tftp_dir, 0, "");
         let _ = try_ingest_local_pxe_report(&tftp_dir, 0, "");
         let _ = std::fs::remove_dir_all(&tmp_dir);
         let _ = std::fs::remove_dir_all(&tmp_dir);
     }
     }
+
+    #[test]
+    fn test_v28_no_cross_host_failover_baseline_isolation_and_debug_log() {
+        lib::init_hardware();
+        assert_eq!(crate::devices::resolve_reachable_bmc_host("192.168.2.165", 2200), "192.168.2.165");
+        assert_eq!(crate::devices::resolve_reachable_bmc_host("192.168.2.166", 2200), "192.168.2.166");
+        assert_eq!(crate::devices::resolve_reachable_bmc_host("192.168.2.167", 2200), "192.168.2.167");
+
+        let tmp_dir = env::temp_dir().join(format!(
+            "stl-v28-baseline-{}",
+            now_ms()
+        ));
+        let args = ServerArgs {
+            config_path: Path::new("config/backend.example.json").to_path_buf(),
+            data_dir: tmp_dir.clone(),
+            web_listen: "127.0.0.1:0".to_string(),
+            tftp_listen: "disabled".to_string(),
+            web_dir: Path::new("web").to_path_buf(),
+            contracts_path: Path::new("contracts/firmware-vd012.json").to_path_buf(),
+            web_password: Some("xjkj123456!".to_string()),
+            version: "0.8.1.28".to_string(),
+            commit: "unit-test".to_string(),
+        };
+        let hub = AppHub::init_for_test(&args);
+        assert!(hub.verify_web_password("xjkj123456!"));
+        assert!(!hub.verify_web_password("wrong"));
+
+        // 1. Explicit Web baseline save on S1 (debuglog=on, vol mem vddq 1100, mt_enabled=false)
+        let save_fw = hub
+            .dispatch_rpc(
+                "EnqueueCommand",
+                &parse_json(
+                    r#"{
+                        "station_id":"S1",
+                        "method":"SaveFirmwareSettings",
+                        "arguments":{"uip_overrides":[{"id":"debuglog","mode":"override","value":"on"}],"uip_raw_commands":["vol mem vddq 1100"]}
+                    }"#,
+                )
+                .unwrap(),
+                false,
+            )
+            .unwrap();
+        assert_eq!(save_fw.get_str_or("state", ""), "succeeded");
+        let save_bp = hub
+            .dispatch_rpc(
+                "EnqueueCommand",
+                &parse_json(
+                    r#"{
+                        "station_id":"S1",
+                        "method":"SaveBootPlan",
+                        "arguments":{"plan":{"preset":"manual","mt_enabled":false,"stages":{"uip1":"manual","amt":"manual","uip2":"manual","uefi":"manual"}}}
+                    }"#,
+                )
+                .unwrap(),
+                false,
+            )
+            .unwrap();
+        assert_eq!(save_bp.get_str_or("state", ""), "succeeded");
+
+        let disk_s1_path = tmp_dir.join("station-controls").join("S1.json");
+        let saved_before = parse_json(&std::fs::read_to_string(&disk_s1_path).unwrap()).unwrap();
+        let ov_before = saved_before
+            .get("firmware_settings")
+            .and_then(|f| f.get_arr("uip_overrides"))
+            .unwrap();
+        assert_eq!(ov_before.len(), 1);
+        assert_eq!(ov_before[0].get_str_or("value", ""), "on");
+
+        // 2. Transient Qt SetStageIntent pushes temporary overrides (`1070`, `ecc:false`, `amt only_tests:[0]`) + MT
+        hub.dispatch_rpc(
+            "SetStageIntent",
+            &parse_json(
+                r#"{
+                    "station_id":"S1",
+                    "stage":"uip1",
+                    "uip_overrides":[{"id":"debuglog","mode":"override","value":"off"},{"id":"vol","mode":"override","value":"mem vddq 1070"}]
+                }"#,
+            )
+            .unwrap(),
+            true,
+        )
+        .unwrap();
+        hub.dispatch_rpc(
+            "SetStageIntent",
+            &parse_json(
+                r#"{
+                    "station_id":"S1",
+                    "stage":"amt",
+                    "enabled":true,
+                    "amt":{"only_tests":[0],"tp_end_step":0}
+                }"#,
+            )
+            .unwrap(),
+            true,
+        )
+        .unwrap();
+
+        // In-memory control reflects transient overrides for current run, while disk S1.json preserves baseline!
+        let ram_ctl = hub.build_station_control("S1").unwrap();
+        let ram_ov = ram_ctl
+            .get("firmware_settings")
+            .and_then(|f| f.get_arr("uip_overrides"))
+            .unwrap();
+        assert!(ram_ov.iter().any(|x| x.get_str_or("value", "") == "mem vddq 1070"));
+
+        let disk_during = parse_json(&std::fs::read_to_string(&disk_s1_path).unwrap()).unwrap();
+        let disk_ov = disk_during
+            .get("firmware_settings")
+            .and_then(|f| f.get_arr("uip_overrides"))
+            .unwrap();
+        assert_eq!(disk_ov.len(), 1);
+        assert_eq!(disk_ov[0].get_str_or("value", ""), "on");
+        assert!(!disk_ov.iter().any(|x| x.get_str_or("value", "").contains("1070")));
+
+        // 3. Stopping the plan restores RAM back to the Web baseline (`debuglog=on`)
+        let stop_res = hub
+            .dispatch_rpc(
+                "EnqueueCommand",
+                &parse_json(
+                    r#"{
+                        "station_id":"S1",
+                        "method":"ControlBootPlan",
+                        "arguments":{"action":"stop"}
+                    }"#,
+                )
+                .unwrap(),
+                false,
+            )
+            .unwrap();
+        assert_eq!(stop_res.get_str_or("state", ""), "succeeded");
+        let ram_after_stop = hub.build_station_control("S1").unwrap();
+        let ram_ov_after = ram_after_stop
+            .get("firmware_settings")
+            .and_then(|f| f.get_arr("uip_overrides"))
+            .unwrap();
+        assert_eq!(ram_ov_after.len(), 1);
+        assert_eq!(ram_ov_after[0].get_str_or("value", ""), "on");
+
+        // 4. Verify detailed debug logs written in UTC to both system.log and S1.log
+        let sys_log = std::fs::read_to_string(tmp_dir.join("debug").join("system.log")).unwrap();
+        assert!(sys_log.contains("[SYS] SERVER_INIT"));
+        assert!(sys_log.contains("[RPC]"));
+        let s1_log = std::fs::read_to_string(tmp_dir.join("debug").join("S1.log")).unwrap();
+        assert!(s1_log.contains("[INTENT] SET_STAGE_INTENT"));
+        assert!(s1_log.contains("[BASELINE] RESTORE"));
+        assert!(s1_log.contains("[PLAN] STOP"));
+        assert!(s1_log.contains("Z][S1]["));
+
+        let _ = std::fs::remove_dir_all(&tmp_dir);
+    }
 }
 }

+ 73 - 0
native/stl_accel/src/pxe.rs

@@ -5,6 +5,7 @@ use crate::actors::StationMsg;
 use crate::json::JsonVal;
 use crate::json::JsonVal;
 use crate::lib;
 use crate::lib;
 use crate::results::now_ms;
 use crate::results::now_ms;
+use crate::storage::{append_debug_log_path, append_system_debug_log};
 use std::fs;
 use std::fs;
 use std::io::ErrorKind;
 use std::io::ErrorKind;
 use std::net::{SocketAddr, TcpStream, UdpSocket};
 use std::net::{SocketAddr, TcpStream, UdpSocket};
@@ -574,6 +575,18 @@ pub fn apply_pxe_configuration(
         );
         );
     }
     }
     let _ = fs::write(data_dir.join("pxe_control_state.json"), pxe_state.to_json());
     let _ = fs::write(data_dir.join("pxe_control_state.json"), pxe_state.to_json());
+    append_system_debug_log(
+        data_dir,
+        "PXE",
+        &format!(
+            "PXE_CONFIG_UPDATE stage1_pxe_enabled={} pxe_host={} server_ip={} client_ip={} remote_synced={}",
+            stage1_en,
+            pxe_host,
+            pxe_server_ip,
+            pxe_state.get_str_or("pxe_client_ip", ""),
+            pxe_state.get_bool("remote_synced").unwrap_or(false)
+        ),
+    );
     Ok(build_pxe_snapshot(pxe_state))
     Ok(build_pxe_snapshot(pxe_state))
 }
 }
 
 
@@ -1728,9 +1741,24 @@ fn handle_tftp_rrq(
         return;
         return;
     };
     };
     let Some(data) = resolve_tftp_rrq_bytes(&hub, &filename) else {
     let Some(data) = resolve_tftp_rrq_bytes(&hub, &filename) else {
+        append_system_debug_log(
+            &hub.data_dir,
+            "PXE",
+            &format!("TFTP_RRQ_NOT_FOUND peer={} file={}", peer, filename),
+        );
         send_tftp_error(&sock, peer, 1, "File not found");
         send_tftp_error(&sock, peer, 1, "File not found");
         return;
         return;
     };
     };
+    append_system_debug_log(
+        &hub.data_dir,
+        "PXE",
+        &format!(
+            "TFTP_RRQ_BEGIN peer={} file={} bytes={}",
+            peer,
+            filename,
+            data.len()
+        ),
+    );
     let (blksize, timeout_secs, oack_pairs) = negotiate_tftp_options(&opts, Some(data.len()));
     let (blksize, timeout_secs, oack_pairs) = negotiate_tftp_options(&opts, Some(data.len()));
     let _ = sock.set_read_timeout(Some(Duration::from_secs(timeout_secs)));
     let _ = sock.set_read_timeout(Some(Duration::from_secs(timeout_secs)));
 
 
@@ -1791,6 +1819,16 @@ fn handle_tftp_rrq(
         offset = end;
         offset = end;
         block_num = block_num.wrapping_add(1);
         block_num = block_num.wrapping_add(1);
     }
     }
+    append_system_debug_log(
+        &hub.data_dir,
+        "PXE",
+        &format!(
+            "TFTP_RRQ_DONE peer={} file={} bytes={}",
+            peer,
+            filename,
+            data.len()
+        ),
+    );
 }
 }
 
 
 fn handle_tftp_wrq(
 fn handle_tftp_wrq(
@@ -1896,6 +1934,16 @@ fn handle_tftp_wrq(
     let is_html = looks_like_html_payload(&lower_name, &payload);
     let is_html = looks_like_html_payload(&lower_name, &payload);
     let is_xml = !is_html && looks_like_xml_payload(&lower_name, &payload);
     let is_xml = !is_html && looks_like_xml_payload(&lower_name, &payload);
     if !is_html && !is_xml {
     if !is_html && !is_xml {
+        append_system_debug_log(
+            &hub.data_dir,
+            "PXE",
+            &format!(
+                "TFTP_WRQ_NON_REPORT peer={} file={} bytes={}",
+                peer,
+                clean_name,
+                payload.len()
+            ),
+        );
         return;
         return;
     }
     }
 
 
@@ -1983,7 +2031,32 @@ fn handle_tftp_wrq(
         Vec::new()
         Vec::new()
     };
     };
 
 
+    append_system_debug_log(
+        &hub.data_dir,
+        "PXE",
+        &format!(
+            "TFTP_WRQ_RX peer={} file={} bytes={} verdict={} targets={}",
+            peer,
+            clean_name,
+            payload.len(),
+            report.get_str_or("verdict", ""),
+            force_targets.join(",")
+        ),
+    );
+
     for sid in force_targets {
     for sid in force_targets {
+        append_debug_log_path(
+            &hub.data_dir.join("debug").join(format!("{}.log", sid)),
+            &sid,
+            "PXE",
+            &format!(
+                "TFTP_WRQ_MATCHED peer={} file={} bytes={} verdict={}",
+                peer,
+                clean_name,
+                payload.len(),
+                report.get_str_or("verdict", "")
+            ),
+        );
         if let Some(handle) = hub.stations.get(&sid) {
         if let Some(handle) = hub.stations.get(&sid) {
             let _ = handle.send(StationMsg::MtReportUploaded {
             let _ = handle.send(StationMsg::MtReportUploaded {
                 report: report.clone(),
                 report: report.clone(),

+ 126 - 1
native/stl_accel/src/results.rs

@@ -387,6 +387,15 @@ impl AsyncCommandScript {
     }
     }
 }
 }
 
 
+#[derive(Clone, Debug)]
+pub struct StationBaselineSnapshot {
+    pub uip_overrides: Vec<JsonVal>,
+    pub uip_raw_commands: Vec<String>,
+    pub amt_settings: JsonVal,
+    pub mt_selection: JsonVal,
+    pub boot_plan: JsonVal,
+}
+
 pub struct StationState {
 pub struct StationState {
     pub hot: StationHotState,
     pub hot: StationHotState,
     pub dimm_soa: DimmSoA24,
     pub dimm_soa: DimmSoA24,
@@ -507,6 +516,7 @@ pub struct StationState {
     pub power_seq_in_progress: bool,
     pub power_seq_in_progress: bool,
     pub power_seq_started_ms: i64,
     pub power_seq_started_ms: i64,
     pub debug_log_path: Option<PathBuf>,
     pub debug_log_path: Option<PathBuf>,
+    pub persistent_baseline: Option<StationBaselineSnapshot>,
     pub dimm_seen_in_boot: [bool; 24],
     pub dimm_seen_in_boot: [bool; 24],
     pub had_bmc_sdr: [bool; 24],
     pub had_bmc_sdr: [bool; 24],
     pub sdr_absent_streak: [u8; 24],
     pub sdr_absent_streak: [u8; 24],
@@ -705,6 +715,7 @@ impl StationState {
             power_seq_in_progress: false,
             power_seq_in_progress: false,
             power_seq_started_ms: 0,
             power_seq_started_ms: 0,
             debug_log_path: None,
             debug_log_path: None,
+            persistent_baseline: None,
             dimm_seen_in_boot: [false; 24],
             dimm_seen_in_boot: [false; 24],
             had_bmc_sdr: [false; 24],
             had_bmc_sdr: [false; 24],
             sdr_absent_streak: [0; 24],
             sdr_absent_streak: [0; 24],
@@ -809,6 +820,65 @@ impl StationState {
         }
         }
     }
     }
 
 
+    pub fn ensure_persistent_baseline(&mut self) {
+        if self.persistent_baseline.is_some() {
+            return;
+        }
+        let snap = StationBaselineSnapshot {
+            uip_overrides: self.uip_overrides.clone(),
+            uip_raw_commands: self.uip_raw_commands.clone(),
+            amt_settings: self.amt_settings.clone(),
+            mt_selection: self.mt_selection.clone(),
+            boot_plan: self.boot_plan.clone(),
+        };
+        self.log_debug(
+            "BASELINE",
+            &format!(
+                "CAPTURE_PERSISTENT ovs={} raws={} amt_action={} bp_preset={} run_rmt={} run_amt={} run_mt={}",
+                snap.uip_overrides.len(),
+                snap.uip_raw_commands.len(),
+                snap.amt_settings.get_str_or("action", ""),
+                snap.boot_plan.get_str_or("preset", ""),
+                snap.boot_plan.get_bool("run_rmt").unwrap_or(false),
+                snap.boot_plan.get_bool("run_amt").unwrap_or(false),
+                snap.boot_plan.get_bool("run_mt").unwrap_or(false),
+            ),
+        );
+        self.persistent_baseline = Some(snap);
+    }
+
+    pub fn clear_persistent_baseline(&mut self) {
+        if self.persistent_baseline.take().is_some() {
+            self.log_debug("BASELINE", "CLEAR_PERSISTENT reason=explicit_web_save");
+        }
+    }
+
+    pub fn restore_persistent_baseline(&mut self, reason: &str) -> bool {
+        let Some(snap) = self.persistent_baseline.take() else {
+            return false;
+        };
+        self.uip_overrides = snap.uip_overrides;
+        self.uip_raw_commands = snap.uip_raw_commands;
+        self.amt_settings = snap.amt_settings;
+        self.mt_selection = snap.mt_selection;
+        self.boot_plan = snap.boot_plan;
+        self.log_debug(
+            "BASELINE",
+            &format!(
+                "RESTORE_PERSISTENT reason={} ovs={} raws={} amt_action={} bp_preset={} run_rmt={} run_amt={} run_mt={}",
+                reason,
+                self.uip_overrides.len(),
+                self.uip_raw_commands.len(),
+                self.amt_settings.get_str_or("action", ""),
+                self.boot_plan.get_str_or("preset", ""),
+                self.boot_plan.get_bool("run_rmt").unwrap_or(false),
+                self.boot_plan.get_bool("run_amt").unwrap_or(false),
+                self.boot_plan.get_bool("run_mt").unwrap_or(false),
+            ),
+        );
+        true
+    }
+
     pub fn clear_for_external_restart(
     pub fn clear_for_external_restart(
         &mut self,
         &mut self,
         now: i64,
         now: i64,
@@ -908,6 +978,7 @@ impl StationState {
         if !keep_active_run {
         if !keep_active_run {
             self.task_status = "not_started".to_string();
             self.task_status = "not_started".to_string();
             self.stage_intents.clear();
             self.stage_intents.clear();
+            self.restore_persistent_baseline(&format!("external_restart:{}", reason_detail));
             self.last_uip_apply = None;
             self.last_uip_apply = None;
             self.last_amt_apply = None;
             self.last_amt_apply = None;
             self.last_amt_start = None;
             self.last_amt_start = None;
@@ -1048,6 +1119,7 @@ impl StationState {
         self.hot.awaiting_dimm_replacement = false;
         self.hot.awaiting_dimm_replacement = false;
         self.task_status = "not_started".to_string();
         self.task_status = "not_started".to_string();
         self.stage_intents.clear();
         self.stage_intents.clear();
+        self.restore_persistent_baseline("reset_on_disconnect");
         self.last_uip_apply = None;
         self.last_uip_apply = None;
         self.last_amt_apply = None;
         self.last_amt_apply = None;
         self.last_amt_start = None;
         self.last_amt_start = None;
@@ -1783,6 +1855,19 @@ impl StationState {
         self.mt_result.set("errors", JsonVal::Num(max_errors as f64));
         self.mt_result.set("errors", JsonVal::Num(max_errors as f64));
         self.mt_result.set("complete", JsonVal::Bool(true));
         self.mt_result.set("complete", JsonVal::Bool(true));
         self.mt_result.set("observed_unix_ms", JsonVal::Str(now.to_string()));
         self.mt_result.set("observed_unix_ms", JsonVal::Str(now.to_string()));
+        self.log_debug(
+            "REPORT",
+            &format!(
+                "MT_HTML_INGESTED file={} verdict={} html_errs={} serial_errs={} max_errs={} has_mt_err={} path={}",
+                filename,
+                report.get_str_or("verdict", ""),
+                html_errors,
+                serial_errors,
+                max_errors,
+                has_mt_err,
+                full_path
+            ),
+        );
 
 
         if has_mt_err {
         if has_mt_err {
             self.hot.mt_fail_complete = true;
             self.hot.mt_fail_complete = true;
@@ -3234,7 +3319,14 @@ impl StationState {
             return;
             return;
         }
         }
         if ev.fw_family == 1 || ev.fw_family == 2 {
         if ev.fw_family == 1 || ev.fw_family == 2 {
-            self.hot.fw_family = ev.fw_family;
+            if self.hot.fw_family != ev.fw_family {
+                let prev_fam = self.fw_family_name().to_string();
+                self.hot.fw_family = ev.fw_family;
+                self.log_debug(
+                    "FW_FAMILY",
+                    &format!("{}->{}", prev_fam, self.fw_family_name()),
+                );
+            }
         }
         }
         let text = String::from_utf8_lossy(raw_bytes).trim().to_string();
         let text = String::from_utf8_lossy(raw_bytes).trim().to_string();
         match ev.kind {
         match ev.kind {
@@ -3253,6 +3345,17 @@ impl StationState {
                 self.hot.prompt_uip_stage = stg as u8;
                 self.hot.prompt_uip_stage = stg as u8;
                 let tag = if self.fw_family_name() == "cxmt" { "CxmtDdrTest" } else { "Hovsee" };
                 let tag = if self.fw_family_name() == "cxmt" { "CxmtDdrTest" } else { "Hovsee" };
                 self.prompt_evidence = format!("[{}][{}]Please input your command:", cpu, tag);
                 self.prompt_evidence = format!("[{}][{}]Please input your command:", cpu, tag);
+                self.log_debug(
+                    "PROMPT",
+                    &format!(
+                        "ready kind=uip stage=uip{} cpu={} boot_id={} intents={} plan_preset={}",
+                        stg,
+                        cpu,
+                        self.boot_id,
+                        self.stage_intents.keys().cloned().collect::<Vec<_>>().join(","),
+                        self.boot_plan.get_str_or("preset", "manual")
+                    ),
+                );
             }
             }
             lib::STL_LK_AMT_PROMPT => {
             lib::STL_LK_AMT_PROMPT => {
                 self.hot.ict_stage1_complete = true;
                 self.hot.ict_stage1_complete = true;
@@ -3284,6 +3387,16 @@ impl StationState {
                 } else {
                 } else {
                     format!("[{}][AMT #]", cpu)
                     format!("[{}][AMT #]", cpu)
                 };
                 };
+                self.log_debug(
+                    "PROMPT",
+                    &format!(
+                        "ready kind=amt cpu={} boot_id={} intents={} plan_run_amt={}",
+                        cpu,
+                        self.boot_id,
+                        self.stage_intents.keys().cloned().collect::<Vec<_>>().join(","),
+                        self.boot_plan.get_bool("run_amt").unwrap_or(true)
+                    ),
+                );
             }
             }
             lib::STL_LK_UEFI_PROMPT_EFI | lib::STL_LK_UEFI_PROMPT_ROOT => {
             lib::STL_LK_UEFI_PROMPT_EFI | lib::STL_LK_UEFI_PROMPT_ROOT => {
                 self.mark_present_channels_training_pass();
                 self.mark_present_channels_training_pass();
@@ -3370,6 +3483,18 @@ impl StationState {
                 self.prompt_evidence = text;
                 self.prompt_evidence = text;
                 self.observed_unix_ms = now;
                 self.observed_unix_ms = now;
                 self.hot.observed_unix_ms = now;
                 self.hot.observed_unix_ms = now;
+                self.log_debug(
+                    "PROMPT",
+                    &format!(
+                        "ready kind=uefi detail={} boot_id={} intents={} mt_banner={} mt_started={} mt_done={}",
+                        self.observed_detail,
+                        self.boot_id,
+                        self.stage_intents.keys().cloned().collect::<Vec<_>>().join(","),
+                        self.hot.mt_banner_seen,
+                        self.plan_mt_started,
+                        self.mt_result.get_bool("complete").unwrap_or(false)
+                    ),
+                );
             }
             }
             _ => {}
             _ => {}
         }
         }

+ 94 - 20
native/stl_accel/src/storage.rs

@@ -7,6 +7,37 @@ use std::collections::BTreeMap;
 use std::fs;
 use std::fs;
 use std::io::Write;
 use std::io::Write;
 use std::path::Path;
 use std::path::Path;
+use std::sync::{Mutex, OnceLock};
+
+static DEBUG_LOG_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
+
+#[inline]
+fn unix_ms_to_utc_string(ts: i64) -> String {
+    let clamped = ts.max(0);
+    let total_secs = clamped / 1000;
+    let ms = clamped % 1000;
+    let days = total_secs / 86_400;
+    let rem = total_secs % 86_400;
+    let hh = rem / 3600;
+    let mm = (rem % 3600) / 60;
+    let ss = rem % 60;
+
+    // Howard Hinnant civil-from-days algorithm (pure integer, UTC)
+    let z = days + 719_468;
+    let era = if z >= 0 { z } else { z - 146_096 } / 146_097;
+    let doe = z - era * 146_097;
+    let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365;
+    let y = yoe + era * 400;
+    let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
+    let mp = (5 * doy + 2) / 153;
+    let d = doy - (153 * mp + 2) / 5 + 1;
+    let m = mp + if mp < 10 { 3 } else { -9 };
+    let year = y + if m <= 2 { 1 } else { 0 };
+    format!(
+        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:03}Z",
+        year, m, d, hh, mm, ss, ms
+    )
+}
 
 
 const QT_CLEAN_PRIVATE_KEYS: &[&str] = &[
 const QT_CLEAN_PRIVATE_KEYS: &[&str] = &[
     "password",
     "password",
@@ -46,31 +77,33 @@ pub fn strip_private_keys_recursive(val: &JsonVal) -> JsonVal {
 }
 }
 
 
 pub fn append_debug_log_path(path: &Path, sid: &str, category: &str, msg: &str) {
 pub fn append_debug_log_path(path: &Path, sid: &str, category: &str, msg: &str) {
+    let _guard = DEBUG_LOG_LOCK
+        .get_or_init(|| Mutex::new(()))
+        .lock()
+        .unwrap_or_else(|e| e.into_inner());
     if let Some(parent) = path.parent() {
     if let Some(parent) = path.parent() {
         let _ = fs::create_dir_all(parent);
         let _ = fs::create_dir_all(parent);
     }
     }
     if let Ok(meta) = fs::metadata(path) {
     if let Ok(meta) = fs::metadata(path) {
-        if meta.len() > 10 * 1024 * 1024 {
+        if meta.len() > 20 * 1024 * 1024 {
             let bak = path.with_extension("log.1");
             let bak = path.with_extension("log.1");
             let _ = fs::rename(path, &bak);
             let _ = fs::rename(path, &bak);
         }
         }
     }
     }
     let ts = now_ms();
     let ts = now_ms();
-    let secs = (ts / 1000).max(0);
-    let ms = (ts % 1000).max(0);
-    let hh = (secs / 3600) % 24;
-    let mm = (secs / 60) % 60;
-    let ss = secs % 60;
+    let utc = unix_ms_to_utc_string(ts);
     let clean_msg = msg.replace('\r', "\\r").replace('\n', " | ");
     let clean_msg = msg.replace('\r', "\\r").replace('\n', " | ");
-    let line = format!(
-        "[{} {:02}:{:02}:{:02}.{:03}][{}][{}] {}\n",
-        ts, hh, mm, ss, ms, sid, category, clean_msg
-    );
+    let line = format!("[{} {}][{}][{}] {}\n", ts, utc, sid, category, clean_msg);
     if let Ok(mut f) = fs::OpenOptions::new().create(true).append(true).open(path) {
     if let Ok(mut f) = fs::OpenOptions::new().create(true).append(true).open(path) {
         let _ = f.write_all(line.as_bytes());
         let _ = f.write_all(line.as_bytes());
     }
     }
 }
 }
 
 
+pub fn append_system_debug_log(data_dir: &Path, category: &str, msg: &str) {
+    let p = data_dir.join("debug").join("system.log");
+    append_debug_log_path(&p, "SYS", category, msg);
+}
+
 pub fn load_station_settings(data_dir: &Path, stations: &mut BTreeMap<String, StationState>) {
 pub fn load_station_settings(data_dir: &Path, stations: &mut BTreeMap<String, StationState>) {
     let dir = data_dir.join("station-controls");
     let dir = data_dir.join("station-controls");
     let _ = fs::create_dir_all(&dir);
     let _ = fs::create_dir_all(&dir);
@@ -228,24 +261,41 @@ pub fn load_station_settings(data_dir: &Path, stations: &mut BTreeMap<String, St
         if let Some(sp) = saved.get_arr("saved_profiles") {
         if let Some(sp) = saved.get_arr("saved_profiles") {
             st.saved_profiles = sp.clone();
             st.saved_profiles = sp.clone();
         }
         }
+        st.log_debug(
+            "STORAGE",
+            &format!(
+                "LOAD_SETTINGS bmc_enabled={} bmc_host={} console_enabled={} console={}:{}({}) ovs={} amt_action={} bp_preset={}",
+                st.bmc_enabled,
+                st.bmc_host,
+                st.console_enabled,
+                st.console_host,
+                st.console_port,
+                st.console_transport,
+                st.uip_overrides.len(),
+                st.amt_settings.get_str_or("action", ""),
+                st.boot_plan.get_str_or("preset", "")
+            ),
+        );
     }
     }
 }
 }
 
 
 pub fn save_station_settings(data_dir: &Path, st: &StationState) {
 pub fn save_station_settings(data_dir: &Path, st: &StationState) {
     let dir = data_dir.join("station-controls");
     let dir = data_dir.join("station-controls");
     let _ = fs::create_dir_all(&dir);
     let _ = fs::create_dir_all(&dir);
+    let base = st.persistent_baseline.as_ref();
+    let ovs = base.map(|b| &b.uip_overrides).unwrap_or(&st.uip_overrides);
+    let raws = base.map(|b| &b.uip_raw_commands).unwrap_or(&st.uip_raw_commands);
+    let mt_sel = base.map(|b| &b.mt_selection).unwrap_or(&st.mt_selection);
+    let amt_cfg = base.map(|b| &b.amt_settings).unwrap_or(&st.amt_settings);
+    let bp_cfg = base.map(|b| &b.boot_plan).unwrap_or(&st.boot_plan);
+
     let mut fw = JsonVal::obj();
     let mut fw = JsonVal::obj();
-    fw.set("uip_overrides", JsonVal::Arr(st.uip_overrides.clone()));
+    fw.set("uip_overrides", JsonVal::Arr(ovs.clone()));
     fw.set(
     fw.set(
         "uip_raw_commands",
         "uip_raw_commands",
-        JsonVal::Arr(
-            st.uip_raw_commands
-                .iter()
-                .map(|s| JsonVal::Str(s.clone()))
-                .collect(),
-        ),
+        JsonVal::Arr(raws.iter().map(|s| JsonVal::Str(s.clone())).collect()),
     );
     );
-    fw.set("mt_selection", st.mt_selection.clone());
+    fw.set("mt_selection", mt_sel.clone());
 
 
     let mut conn_bmc = JsonVal::obj();
     let mut conn_bmc = JsonVal::obj();
     conn_bmc.set("enabled", JsonVal::Bool(st.bmc_enabled));
     conn_bmc.set("enabled", JsonVal::Bool(st.bmc_enabled));
@@ -284,13 +334,25 @@ pub fn save_station_settings(data_dir: &Path, st: &StationState) {
     let mut root = JsonVal::obj();
     let mut root = JsonVal::obj();
     root.set("connections", conns);
     root.set("connections", conns);
     root.set("firmware_settings", fw);
     root.set("firmware_settings", fw);
-    root.set("amt_settings", st.amt_settings.clone());
-    root.set("boot_plan", st.boot_plan.clone());
+    root.set("amt_settings", amt_cfg.clone());
+    root.set("boot_plan", bp_cfg.clone());
     root.set("task_batch", st.task_batch.clone());
     root.set("task_batch", st.task_batch.clone());
     root.set("task_history", JsonVal::Arr(st.task_history.clone()));
     root.set("task_history", JsonVal::Arr(st.task_history.clone()));
     root.set("saved_profiles", JsonVal::Arr(st.saved_profiles.clone()));
     root.set("saved_profiles", JsonVal::Arr(st.saved_profiles.clone()));
     let p = dir.join(format!("{}.json", st.station_id));
     let p = dir.join(format!("{}.json", st.station_id));
     let _ = fs::write(p, root.to_json());
     let _ = fs::write(p, root.to_json());
+    st.log_debug(
+        "STORAGE",
+        &format!(
+            "SAVE_SETTINGS baseline_shield={} ovs={} amt_action={} bp_preset={} bmc_enabled={} bmc_host={}",
+            base.is_some(),
+            ovs.len(),
+            amt_cfg.get_str_or("action", ""),
+            bp_cfg.get_str_or("preset", ""),
+            st.bmc_enabled,
+            st.bmc_host
+        ),
+    );
 }
 }
 
 
 #[allow(clippy::too_many_arguments)]
 #[allow(clippy::too_many_arguments)]
@@ -398,6 +460,18 @@ pub fn archive_task_run(
     let sum_path_str = sum_path.to_string_lossy().to_string();
     let sum_path_str = sum_path.to_string_lossy().to_string();
     disk_summary.set("summary_path", JsonVal::Str(sum_path_str.clone()));
     disk_summary.set("summary_path", JsonVal::Str(sum_path_str.clone()));
     let _ = fs::write(&sum_path, disk_summary.to_json());
     let _ = fs::write(&sum_path, disk_summary.to_json());
+    st.log_debug(
+        "ARCHIVE",
+        &format!(
+            "RUN_ARCHIVED run_id={} batch_id={} verdict={} elapsed_ms={} bytes={} dir={}",
+            run_id,
+            batch_id,
+            verdict,
+            (ended_ms - started_ms).max(0),
+            raw_vec.len(),
+            dir.display()
+        ),
+    );
 
 
     let state_summary = strip_private_keys_recursive(&disk_summary);
     let state_summary = strip_private_keys_recursive(&disk_summary);
     (
     (

+ 106 - 0
native/stl_accel/src/workflow.rs

@@ -81,6 +81,21 @@ pub fn start_async_script(
     st.async_script.command_lines = command_lines;
     st.async_script.command_lines = command_lines;
     st.async_script.extra_meta = extra_meta;
     st.async_script.extra_meta = extra_meta;
     st.async_script.completion_tx = completion_tx;
     st.async_script.completion_tx = completion_tx;
+    st.log_debug(
+        "SCRIPT",
+        &format!(
+            "START tag={} steps={} preview_cmds={} boot_id={}",
+            context_tag,
+            st.async_script.steps.len(),
+            st.async_script
+                .steps
+                .iter()
+                .map(|s| s.line.as_str())
+                .collect::<Vec<_>>()
+                .join("; "),
+            st.boot_id
+        ),
+    );
     tick_async_script(st);
     tick_async_script(st);
 }
 }
 
 
@@ -219,6 +234,25 @@ pub fn tick_async_script(st: &mut StationState) {
         }
         }
 
 
         let fw_rejected = has_firmware_error(&out_str);
         let fw_rejected = has_firmware_error(&out_str);
+        let resp_preview: String = out_str
+            .trim()
+            .replace('\r', " ")
+            .replace('\n', " | ")
+            .chars()
+            .take(180)
+            .collect();
+        st.log_debug(
+            "SCRIPT",
+            &format!(
+                "STEP_DONE tag={} cmd='{}' matched={} timed_out={} fw_rejected={} resp='{}'",
+                st.async_script.context_tag,
+                st.async_script.step_sent_line,
+                matched,
+                timed_out,
+                fw_rejected,
+                resp_preview
+            ),
+        );
 
 
         let mut entry = JsonVal::obj();
         let mut entry = JsonVal::obj();
         entry.set("command", JsonVal::Str(st.async_script.step_sent_line.clone()));
         entry.set("command", JsonVal::Str(st.async_script.step_sent_line.clone()));
@@ -442,6 +476,17 @@ fn finish_async_script(st: &mut StationState, now: i64) {
     } else {
     } else {
         "submitted"
         "submitted"
     };
     };
+    st.log_debug(
+        "SCRIPT",
+        &format!(
+            "FINISH tag={} confirmation={} any_rejected={} steps_collected={} boot_id={}",
+            tag,
+            confirmation,
+            any_rejected,
+            responses.len(),
+            st.boot_id
+        ),
+    );
 
 
     if matches!(
     if matches!(
         tag.as_str(),
         tag.as_str(),
@@ -785,6 +830,14 @@ pub fn control_boot_plan_impl(
             st.plan_paused = false;
             st.plan_paused = false;
             st.single_run_active = false;
             st.single_run_active = false;
             st.freeze_run_timing(now);
             st.freeze_run_timing(now);
+            st.restore_persistent_baseline("control_boot_plan_stop");
+            st.log_debug(
+                "PLAN",
+                &format!(
+                    "STOP boot_id={} started={} ended={}",
+                    st.boot_id, st.run_started_unix_ms, st.run_ended_unix_ms
+                ),
+            );
             if matches!(st.task_status.as_str(), "running" | "queued") {
             if matches!(st.task_status.as_str(), "running" | "queued") {
                 st.task_status = "interrupted".to_string();
                 st.task_status = "interrupted".to_string();
             }
             }
@@ -1235,6 +1288,14 @@ pub fn step_boot_plan(st: &mut StationState, contract: &FirmwareContract) {
         .unwrap_or("manual");
         .unwrap_or("manual");
 
 
     if stage_mode == "manual" {
     if stage_mode == "manual" {
+        let prev_bp_state = st.boot_execution.get_str_or("state", "idle");
+        let prev_bp_stage = st.boot_execution.get_str_or("current_stage", "");
+        if prev_bp_state != "waiting_user" || prev_bp_stage != stage {
+            st.log_debug(
+                "PLAN",
+                &format!("MANUAL_WAIT stage={} cpu={} boot_id={}", stage, cpu, st.boot_id),
+            );
+        }
         st.boot_execution
         st.boot_execution
             .set("state", JsonVal::Str("waiting_user".to_string()));
             .set("state", JsonVal::Str("waiting_user".to_string()));
         st.boot_execution.set(
         st.boot_execution.set(
@@ -1568,6 +1629,13 @@ fn consume_pending_stage_intent(st: &mut StationState, contract: &FirmwareContra
         st.boot_execution.get_str_or("state", "idle").as_str(),
         st.boot_execution.get_str_or("state", "idle").as_str(),
         "running" | "waiting_user"
         "running" | "waiting_user"
     );
     );
+    st.log_debug(
+        "INTENT",
+        &format!(
+            "CONSUME stage={} action={} boot_id={} plan_active={} fw_fam={}",
+            stage_key, action, st.boot_id, plan_active, fw_fam
+        ),
+    );
 
 
     match (stage_key, action.as_str()) {
     match (stage_key, action.as_str()) {
         ("uip1" | "uip2", "continue_uip" | "apply_uip" | "enable") => {
         ("uip1" | "uip2", "continue_uip" | "apply_uip" | "enable") => {
@@ -1843,6 +1911,7 @@ pub fn apply_profile_to_station(
     data_dir: &Path,
     data_dir: &Path,
     pxe_tftp_dir: &Path,
     pxe_tftp_dir: &Path,
 ) -> Result<(), String> {
 ) -> Result<(), String> {
+    st.ensure_persistent_baseline();
     let run_rmt = profile
     let run_rmt = profile
         .get_bool("run_rmt")
         .get_bool("run_rmt")
         .or_else(|| profile.get("rmt").and_then(|r| r.get_bool("enabled")))
         .or_else(|| profile.get("rmt").and_then(|r| r.get_bool("enabled")))
@@ -2140,6 +2209,17 @@ pub fn submit_task_batch(
     tb.set("runs", JsonVal::Arr(runs_arr));
     tb.set("runs", JsonVal::Arr(runs_arr));
     st.task_batch = tb.clone();
     st.task_batch = tb.clone();
     save_station_settings(data_dir, st);
     save_station_settings(data_dir, st);
+    st.log_debug(
+        "BATCH",
+        &format!(
+            "SUBMIT_TASK_BATCH batch_id={} planned={} auto_start={} stop_on_fail={} continue_timer={}",
+            tb.get_str_or("batch_id", ""),
+            total_planned,
+            auto_start,
+            stop_on_fail,
+            continue_timer
+        ),
+    );
     Ok(tb)
     Ok(tb)
 }
 }
 
 
@@ -2252,6 +2332,16 @@ pub fn step_task_batch(
                 st.task_history.drain(0..50);
                 st.task_history.drain(0..50);
             }
             }
             emit_complete_signal(st, &run_id, "", verdict, &summary_obj, true);
             emit_complete_signal(st, &run_id, "", verdict, &summary_obj, true);
+            st.log_debug(
+                "BATCH",
+                &format!(
+                    "SINGLE_RUN_DONE run_id={} verdict={} elapsed_ms={}",
+                    run_id,
+                    verdict,
+                    (ended_ms - started_ms).max(0)
+                ),
+            );
+            st.restore_persistent_baseline("single_run_complete");
             save_station_settings(data_dir, st);
             save_station_settings(data_dir, st);
         }
         }
         return;
         return;
@@ -2331,6 +2421,14 @@ pub fn step_task_batch(
         st.plan_paused = true;
         st.plan_paused = true;
         st.freeze_run_timing(now);
         st.freeze_run_timing(now);
         emit_complete_signal(st, &run_id, &batch_id, verdict, &summary_obj, true);
         emit_complete_signal(st, &run_id, &batch_id, verdict, &summary_obj, true);
+        st.log_debug(
+            "BATCH",
+            &format!(
+                "BATCH_STOP_ON_FAIL batch_id={} run_id={} completed={}",
+                batch_id, run_id, completed_total
+            ),
+        );
+        st.restore_persistent_baseline("task_batch_failed");
         save_station_settings(data_dir, st);
         save_station_settings(data_dir, st);
         return;
         return;
     }
     }
@@ -2348,6 +2446,14 @@ pub fn step_task_batch(
         st.task_status = "completed".to_string();
         st.task_status = "completed".to_string();
         st.freeze_run_timing(now);
         st.freeze_run_timing(now);
         emit_complete_signal(st, &run_id, &batch_id, verdict, &summary_obj, true);
         emit_complete_signal(st, &run_id, &batch_id, verdict, &summary_obj, true);
+        st.log_debug(
+            "BATCH",
+            &format!(
+                "BATCH_COMPLETED batch_id={} last_run_id={} completed={}",
+                batch_id, run_id, completed_total
+            ),
+        );
+        st.restore_persistent_baseline("task_batch_completed");
         save_station_settings(data_dir, st);
         save_station_settings(data_dir, st);
         return;
         return;
     }
     }