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

@@ -130,8 +130,9 @@ reaches the screen.
- `system`: memory in use and total, and per NVIDIA GPU its use and VRAM (from `nvidia-smi`, - `system`: memory in use and total, and per NVIDIA GPU its use and VRAM (from `nvidia-smi`,
missing when there is none); sampled when the snapshot is taken, at most once a second. missing when there is none); sampled when the snapshot is taken, at most once a second.
- `llm`: the LLM's state (`off`, `starting`, `ready`, `failed`), whether the app runs it - `llm`: the LLM's state (`off`, `starting`, `ready`, `failed`), whether the app runs it
(`managed`), and while starting Strata's last line and last percentage (the model download), (`managed`), and while starting Strata's last line and how far that line says it got (its
also before the services are up; a failure's reason in `note`. percentage, or `X of Y GB` for the model download; none on a line without progress), also before
the services are up; a failure's reason in `note`.
- `performance`: the performance stage (normal, gaming, paused, and why) comes with game - `performance`: the performance stage (normal, gaming, paused, and why) comes with game
detection in M7; until then `null`. detection in M7; until then `null`.
@@ -162,8 +163,9 @@ The LLM itself (Qwen3.6-35B-A3B, about 23 GB) is downloaded by Strata on its fir
also while a server sends nothing (a download's part file stays, so the next try continues it). also while a server sends nothing (a download's part file stays, so the next try continues it).
- Folders go to commands as arguments or as the working folder, never inside a script's text. - Folders go to commands as arguments or as the working folder, never inside a script's text.
- Every command runs with the layout's environment: `uv`'s cache and Pythons, `HF_HOME` - Every command runs with the layout's environment: `uv`'s cache and Pythons, `HF_HOME`
(`models/hf`), `NLTK_DATA` (`models/nltk`), temp files (`cache/tmp`) and Strata's folders, all (`models/hf`), `NLTK_DATA` (`models/nltk`), temp files (`cache/tmp`) and Strata's folders (on
inside the data folder. Python comes from `uv` only. Output lines go to the `install` log tab. Windows also `APPDATA` and `LOCALAPPDATA`, where Strata and the NVIDIA shader cache write
whatever `STRATA_*` says), all inside the data folder. Python comes from `uv` only. Output lines go to the `install` log tab.
- Downloads go to `<file>.part`, continue with an HTTP range after a break (a server without ranges - Downloads go to `<file>.part`, continue with an HTTP range after a break (a server without ranges
starts over), and are checked against the pinned SHA-256; a wrong checksum deletes the part. starts over), and are checked against the pinned SHA-256; a wrong checksum deletes the part.
- When every step is done, `uv`'s download cache is cleaned (the venvs hold copies). - When every step is done, `uv`'s download cache is cleaned (the venvs hold copies).
@@ -188,7 +190,8 @@ start it first, so nothing answers before the brain can, and stop it last.
behind voice answers. Pictures are off until something in v2 sends one. Stopping the services behind voice answers. Pictures are off until something in v2 sends one. Stopping the services
runs `strata launch --stop` (ended after 2 minutes, with everything it started) and then checks runs `strata launch --stop` (ended after 2 minutes, with everything it started) and then checks
that the port refuses connections; so does a failed or cancelled start, so nothing half-started that the port refuses connections; so does a failed or cancelled start, so nothing half-started
keeps graphics memory. Stopped means the port refuses connections (a stop command that fails keeps graphics memory (each check waits up to 10 s to connect: Windows refuses a closed local
port only after about 2 s). Stopped means the port refuses connections (a stop command that fails
while it does counts as stopped); a timeout, an error status (a server still loading answers while it does counts as stopped); a timeout, an error status (a server still loading answers
503) or an answer that cannot be read is not a confirmed stop: the LLM is `failed` with the 503) or an answer that cannot be read is not a confirmed stop: the LLM is `failed` with the
reason, and the stop or the start reports it. The start's cancel is armed when the controller reason, and the stop or the start reports it. The start's cancel is armed when the controller

View File

@@ -91,7 +91,10 @@ impl Layout {
("STRATA_COMPONENTS_DIR".into(), s(self.strata_home().join("components"))), ("STRATA_COMPONENTS_DIR".into(), s(self.strata_home().join("components"))),
]; ];
if cfg!(windows) { if cfg!(windows) {
// Strata keeps state under %APPDATA%\Strata and the NVIDIA driver its shader cache under
// %APPDATA% too, whatever STRATA_* says (game PC, 2026-11-12): both go in the data folder.
env.push(("LOCALAPPDATA".into(), s(self.strata_home().join("localappdata")))); env.push(("LOCALAPPDATA".into(), s(self.strata_home().join("localappdata"))));
env.push(("APPDATA".into(), s(self.strata_home().join("appdata"))));
} else { } else {
// On Windows the worker adds the pip CUDA wheels' DLL folders itself; on Linux the loader // On Windows the worker adds the pip CUDA wheels' DLL folders itself; on Linux the loader
// needs them in LD_LIBRARY_PATH before the process starts. // needs them in LD_LIBRARY_PATH before the process starts.
@@ -194,6 +197,10 @@ impl Ctx {
#[cfg(unix)] #[cfg(unix)]
cmd.process_group(0); cmd.process_group(0);
let _ = std::fs::create_dir_all(self.layout.data.join("cache").join("tmp")); let _ = std::fs::create_dir_all(self.layout.data.join("cache").join("tmp"));
#[cfg(windows)]
for d in ["appdata", "localappdata"] {
let _ = std::fs::create_dir_all(self.layout.strata_home().join(d));
}
let name = program.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(); let name = program.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
crate::info_log!(self.tab, "run {name} {}", args.first().copied().unwrap_or("")); crate::info_log!(self.tab, "run {name} {}", args.first().copied().unwrap_or(""));
let mut child = cmd.spawn().map_err(|e| format!("{name}을(를) 실행하지 못했습니다: {e}"))?; let mut child = cmd.spawn().map_err(|e| format!("{name}을(를) 실행하지 못했습니다: {e}"))?;

View File

@@ -33,7 +33,8 @@ pub struct LlmStatus {
pub state: LlmState, pub state: LlmState,
/// Strata's own server (false: `llm.url`). /// Strata's own server (false: `llm.url`).
pub managed: bool, 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>, pub percent: Option<f64>,
/// Strata's last line while starting, or why it failed. /// Strata's last line while starting, or why it failed.
pub note: Option<String>, pub note: Option<String>,
@@ -62,8 +63,22 @@ pub fn launch_args(layout: &Layout, settings: &Settings) -> Vec<String> {
a 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> { 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 b = line.as_bytes();
let mut found = None; let mut found = None;
for (i, _) in line.match_indices('%') { for (i, _) in line.match_indices('%') {
@@ -161,11 +176,8 @@ impl Llm {
let mut s = self.status.lock().unwrap().clone(); let mut s = self.status.lock().unwrap().clone();
if let Some(ctx) = self.active.lock().unwrap().as_ref() { if let Some(ctx) = self.active.lock().unwrap().as_ref() {
s.note = ctx.last_note(); s.note = ctx.last_note();
if let Some(p) = s.note.as_deref().and_then(percent) { // From the current line only: a percentage from an earlier stage would mislead.
// Kept in the status, so the bar does not vanish on a line without one. s.percent = s.note.as_deref().and_then(percent);
self.status.lock().unwrap().percent = Some(p);
}
s.percent = self.status.lock().unwrap().percent;
} }
s 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, /// 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. /// so it keeps checking until the deadline.
async fn wait_gone(base: &str, timeout: Duration) -> bool { 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; let until = Instant::now() + timeout;
loop { loop {
if let Err(e) = client.get(format!("{base}/models")).send().await { if let Err(e) = client.get(format!("{base}/models")).send().await {
if e.is_connect() { if e.is_connect() && !e.is_timeout() {
return true; 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("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("50% done, now 75%"), Some(75.0));
assert_eq!(percent("Loading the model… 15 s"), None); 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] #[test]
@@ -462,7 +480,7 @@ mod tests {
async fn strata_starts_reports_its_download_waits_for_the_model_and_stops() { async fn strata_starts_reports_its_download_waits_for_the_model_and_stops() {
let l = layout("llm5"); let l = layout("llm5");
let port = models_server_until("qwen-test", Duration::from_millis(300), Some(l.data.join("gone"))).await; 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 llm = Arc::new(Llm::with_exe(l.clone(), exe));
let s = parse_settings(&json!({"llm": {"port": port}})).unwrap(); let s = parse_settings(&json!({"llm": {"port": port}})).unwrap();
let l2 = llm.clone(); let l2 = llm.clone();
@@ -478,7 +496,17 @@ mod tests {
} }
} }
let st = seen.expect("progress while starting"); 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(); 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!((base, model.as_str()), (format!("http://127.0.0.1:{port}/v1"), "qwen-test"));
assert_eq!(llm.status().state, LlmState::Ready); assert_eq!(llm.status().state, LlmState::Ready);

File diff suppressed because one or more lines are too long