fix(app): Windows stop check, size-based download progress, APPDATA in the data folder

Found running the app's admin commands on the game PC (Windows, RTX 5070
Ti): the full install, Strata started by the app downloading the 22.9 GB
model, the worker and Discord up, five spoken questions all answered.

- Windows refuses a connection to a closed local port only after about
  2 s, so the 2 s request timeout made every stop "not confirmed". The
  check now waits up to 10 s to connect and still counts only a refusal
  (not a timeout) as stopped.
- Strata 0.1.59 reports the model download as "X of Y GB"; percent()
  reads that, and the dashboard shows the current line's progress only
  (it had stayed on the engine download's 80 %).
- Strata and the NVIDIA shader cache write under %APPDATA% whatever
  STRATA_* says: the layout sets APPDATA inside the data folder on
  Windows, next to LOCALAPPDATA.

Roadmap: M5 step 5 done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-12 18:51:12 +09:00
parent ac8c30022d
commit 76144fb19b
4 changed files with 55 additions and 17 deletions

View File

@@ -33,7 +33,8 @@ pub struct LlmStatus {
pub state: LlmState,
/// Strata's own server (false: `llm.url`).
pub managed: bool,
/// The last percentage Strata printed while starting (the model download).
/// How far Strata's current line says it got while starting (a percentage, or the model
/// download's `X of Y GB`); none on a line without progress.
pub percent: Option<f64>,
/// Strata's last line while starting, or why it failed.
pub note: Option<String>,
@@ -62,8 +63,22 @@ pub fn launch_args(layout: &Layout, settings: &Settings) -> Vec<String> {
a
}
/// The last `NN%` or `NN.N%` in a line.
/// How far a line says Strata got: its last `NN%` or `NN.N%`, else `X of Y GB` (or MB), which is
/// how Strata 0.1.59 reports the model download.
pub fn percent(line: &str) -> Option<f64> {
percent_sign(line).or_else(|| size_progress(line))
}
fn size_progress(line: &str) -> Option<f64> {
let words: Vec<&str> = line.split_whitespace().collect();
words.windows(4).rev().find_map(|w| {
let (done, total) = (w[0].parse::<f64>().ok()?, w[2].parse::<f64>().ok()?);
(w[1] == "of" && matches!(w[3].trim_end_matches([',', '.', ')']), "GB" | "MB") && total > 0.0 && done <= total)
.then(|| (done / total * 1000.0).round() / 10.0)
})
}
fn percent_sign(line: &str) -> Option<f64> {
let b = line.as_bytes();
let mut found = None;
for (i, _) in line.match_indices('%') {
@@ -161,11 +176,8 @@ impl Llm {
let mut s = self.status.lock().unwrap().clone();
if let Some(ctx) = self.active.lock().unwrap().as_ref() {
s.note = ctx.last_note();
if let Some(p) = s.note.as_deref().and_then(percent) {
// Kept in the status, so the bar does not vanish on a line without one.
self.status.lock().unwrap().percent = Some(p);
}
s.percent = self.status.lock().unwrap().percent;
// From the current line only: a percentage from an earlier stage would mislead.
s.percent = s.note.as_deref().and_then(percent);
}
s
}
@@ -301,11 +313,14 @@ impl Llm {
/// status (a server still loading answers 503) or an answer it cannot read is not a confirmed stop,
/// so it keeps checking until the deadline.
async fn wait_gone(base: &str, timeout: Duration) -> bool {
let Ok(client) = reqwest::Client::builder().timeout(Duration::from_secs(2)).build() else { return false };
// Windows answers a connection to a closed local port only after about 2 s of retries, so the
// connect wait is long enough for that refusal to arrive as a refusal, not as a timeout.
let Ok(client) = reqwest::Client::builder().connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(12)).build() else { return false };
let until = Instant::now() + timeout;
loop {
if let Err(e) = client.get(format!("{base}/models")).send().await {
if e.is_connect() {
if e.is_connect() && !e.is_timeout() {
return true;
}
}
@@ -352,6 +367,9 @@ mod tests {
assert_eq!(percent("Downloading 3 of 5: 41.5% (9.6 GB of 23.1 GB)"), Some(41.5));
assert_eq!(percent("50% done, now 75%"), Some(75.0));
assert_eq!(percent("Loading the model… 15 s"), None);
// Strata 0.1.59's model download prints sizes, not a percentage.
assert_eq!(percent("Downloading the model files: 2.4 of 22.9 GB"), Some(10.5));
assert_eq!(percent("Downloading the model files: 22.9 of 22.9 GB"), Some(100.0));
}
#[test]
@@ -462,7 +480,7 @@ mod tests {
async fn strata_starts_reports_its_download_waits_for_the_model_and_stops() {
let l = layout("llm5");
let port = models_server_until("qwen-test", Duration::from_millis(300), Some(l.data.join("gone"))).await;
let exe = fake_strata(&l, "echo 'Downloading: 12.5%'; sleep 1; echo 'Downloading: 100%'; echo 'Strata is serving.'");
let exe = fake_strata(&l, "echo 'Downloading the engine: 80%'; sleep 1; echo 'Downloading the model files: 2.4 of 22.9 GB'; sleep 1; echo 'Starting the engine'; sleep 1; echo 'Strata is serving.'");
let llm = Arc::new(Llm::with_exe(l.clone(), exe));
let s = parse_settings(&json!({"llm": {"port": port}})).unwrap();
let l2 = llm.clone();
@@ -478,7 +496,17 @@ mod tests {
}
}
let st = seen.expect("progress while starting");
assert_eq!((st.state, st.percent), (LlmState::Starting, Some(12.5)));
assert_eq!((st.state, st.percent), (LlmState::Starting, Some(80.0)));
// The bar follows the current line: the model download's sizes, then nothing (no stale 80 %).
let mut later = vec![];
for _ in 0..60 {
tokio::time::sleep(Duration::from_millis(50)).await;
let st = llm.status();
if st.state != LlmState::Starting { break; }
later.push((st.note.clone().unwrap_or_default(), st.percent));
}
assert!(later.iter().any(|(n, p)| n.contains("2.4 of 22.9") && *p == Some(10.5)), "{later:?}");
assert!(later.iter().any(|(n, p)| n.contains("Starting the engine") && p.is_none()), "{later:?}");
let (base, model) = run.await.unwrap().unwrap();
assert_eq!((base, model.as_str()), (format!("http://127.0.0.1:{port}/v1"), "qwen-test"));
assert_eq!(llm.status().state, LlmState::Ready);