Enhance generation logging and status reporting for map generation

This commit is contained in:
2026-05-07 11:17:37 +02:00
parent 54c6521875
commit b1ee6611b8

View File

@@ -390,44 +390,79 @@ async fn generate_map(
let out_dir = output_dir(&root)?; let out_dir = output_dir(&root)?;
let script = script_path(&root)?; let script = script_path(&root)?;
let python = python_binary(&root); let python = python_binary(&root);
let log_path = generation_log_path(&root, &prompt_clone)?;
let log_path_display = log_path.to_string_lossy().to_string();
let mut log_file = File::create(&log_path)
.map_err(|e| format!("Failed to create generation log: {e}"))?;
let mut cmd = Command::new(python); let mut args = vec![
cmd.current_dir(&root) script.to_string_lossy().to_string(),
.arg(script.as_os_str()) "--prompt".to_string(),
.arg("--prompt") prompt_clone.clone(),
.arg(prompt_clone) "--output-dir".to_string(),
.arg("--output-dir") out_dir.to_string_lossy().to_string(),
.arg(&out_dir) "--work-dir".to_string(),
.arg("--work-dir") root.to_string_lossy().to_string(),
.arg(root.to_string_lossy().to_string()) "--upscale".to_string(),
.arg("--upscale") upscale,
.arg(upscale) "--steps".to_string(),
.arg("--steps") steps.to_string(),
.arg(steps.to_string()) "--guidance".to_string(),
.arg("--guidance") guidance.to_string(),
.arg(guidance.to_string()) "--width".to_string(),
.arg("--width") width.to_string(),
.arg(width.to_string()) "--height".to_string(),
.arg("--height") height.to_string(),
.arg(height.to_string()) "--scheduler".to_string(),
.arg("--scheduler") scheduler,
.arg(scheduler) "--model-path".to_string(),
.arg("--model-path") model_path,
.arg(model_path) "--base-model".to_string(),
.arg("--base-model") base_model,
.arg(base_model) "--vae-model".to_string(),
.arg("--vae-model") vae_model,
.arg(vae_model) ];
.stdout(Stdio::piped())
.stderr(Stdio::piped());
if seam_inpaint { if seam_inpaint {
cmd.arg("--seam-inpaint"); args.push("--seam-inpaint".to_string());
}
write_log_line(&mut log_file, "SkymapGen generation log");
write_log_line(
&mut log_file,
format!("started_unix_ms: {}", unix_timestamp_millis()),
);
write_log_line(&mut log_file, format!("cwd: {}", root.to_string_lossy()));
write_log_line(&mut log_file, format!("log_path: {log_path_display}"));
write_log_line(&mut log_file, format!("prompt: {prompt_clone}"));
write_log_line(&mut log_file, format!("steps: {steps}"));
write_log_line(&mut log_file, format!("guidance: {guidance}"));
write_log_line(&mut log_file, format!("size: {width}x{height}"));
write_log_line(&mut log_file, format!("seam_inpaint: {seam_inpaint}"));
write_log_line(&mut log_file, "command:");
write_log_line(
&mut log_file,
format!(" program: {}", python.to_string_lossy()),
);
for arg in &args {
write_log_line(&mut log_file, format!(" arg: {arg}"));
}
write_log_line(&mut log_file, "");
let mut cmd = Command::new(&python);
cmd.current_dir(&root)
.stdout(Stdio::piped())
.stderr(Stdio::piped());
for arg in &args {
cmd.arg(arg);
} }
let mut child = cmd let mut child = cmd
.spawn() .spawn()
.map_err(|e| format!("Failed to start generator: {e}"))?; .map_err(|e| format!("Failed to start generator: {e}"))?;
write_log_line(&mut log_file, format!("pid: {}", child.id()));
write_log_line(&mut log_file, "");
write_log_line(&mut log_file, "stdout:");
{ {
let mut active = active_generation_pid let mut active = active_generation_pid
@@ -466,6 +501,7 @@ async fn generate_map(
> 0 > 0
{ {
let trimmed = line.trim_end().to_string(); let trimmed = line.trim_end().to_string();
write_log_line(&mut log_file, format!(" {trimmed}"));
if let Some(json_str) = trimmed.strip_prefix("PROGRESS ") { if let Some(json_str) = trimmed.strip_prefix("PROGRESS ") {
if let Ok(val) = serde_json::from_str::<Value>(json_str) { if let Ok(val) = serde_json::from_str::<Value>(json_str) {
let _ = window.emit("gen-progress", val); let _ = window.emit("gen-progress", val);
@@ -480,13 +516,24 @@ async fn generate_map(
.wait() .wait()
.map_err(|e| format!("Failed to wait for generator: {e}"))?; .map_err(|e| format!("Failed to wait for generator: {e}"))?;
let stderr_output = stderr_handle.join().unwrap_or_default(); let stderr_output = stderr_handle.join().unwrap_or_default();
write_log_line(&mut log_file, "");
write_log_line(&mut log_file, "stderr:");
for line in stderr_output.lines() {
write_log_line(&mut log_file, format!(" {line}"));
}
write_log_line(&mut log_file, "");
write_log_line(&mut log_file, format!("exit_status: {status}"));
if cancel_generation_requested.load(Ordering::SeqCst) { if cancel_generation_requested.load(Ordering::SeqCst) {
return Err("Generation cancelled".to_string()); write_log_line(&mut log_file, "result: cancelled");
return Err(format!("Generation cancelled. Log: {log_path_display}"));
} }
if !status.success() { if !status.success() {
return Err(format!("Generator failed: {stderr_output}")); write_log_line(&mut log_file, "result: failed");
return Err(format!(
"Generator failed. Log: {log_path_display}\n{stderr_output}"
));
} }
let path_line = let path_line =
@@ -497,8 +544,14 @@ async fn generate_map(
} else { } else {
out_dir.join(path) out_dir.join(path)
}; };
write_log_line(&mut log_file, format!("result: success"));
write_log_line(
&mut log_file,
format!("output_path: {}", resolved.to_string_lossy()),
);
Ok(GenerateResult { Ok(GenerateResult {
output_path: resolved.to_string_lossy().to_string(), output_path: resolved.to_string_lossy().to_string(),
log_path: log_path_display,
}) })
})(); })();