Skip to content

Fix: enhance error handling in process monitoring and update performa…#1273

Merged
shm11C3 merged 1 commit into
developfrom
ci/fix/#1272
Mar 22, 2026
Merged

Fix: enhance error handling in process monitoring and update performa…#1273
shm11C3 merged 1 commit into
developfrom
ci/fix/#1272

Conversation

@shm11C3

@shm11C3 shm11C3 commented Mar 22, 2026

Copy link
Copy Markdown
Owner

…nce thresholds for Linux and macOS

Summary

Related Issues

Type of Change

  • Bug fix (fix/ branch)
  • New feature (feat/ branch)
  • Refactoring (refactor/ branch)
  • Documentation (docs/ branch)
  • Dependencies update
  • Other (chore/ branch)

Screenshots / Videos

Test Plan

  • Manual testing
  • Unit tests

Checklist

  • Self-reviewed the code
  • Linting and formatting pass (npm run lint && npm run format / cargo tauri-lint && cargo tauri-fmt)
  • Tests pass (npm test / cargo tauri-test)
  • No new warnings or errors

Copilot AI review requested due to automatic review settings March 22, 2026 04:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the perf-monitor utility used by HardwareVisualizer to (1) provide more actionable diagnostics when the monitored process exits early, and (2) relax Linux/macOS memory thresholds to better match real-world baselines.

Changes:

  • Increase Linux/macOS memory thresholds (avg + p95) in perf-thresholds.toml.
  • Pipe and capture the monitored process’s stderr and include it in early-exit errors.
  • Add a helper to format early-exit errors with phase context (warmup vs measurement).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
perf-thresholds.toml Raises Linux/macOS max avg/p95 memory thresholds to reduce false failures on those platforms.
perf-monitor/src/monitor.rs Enhances early-exit error reporting by piping stderr and formatting richer error messages during warmup/measurement.

Comment on lines 60 to 64
for _ in 0..timing.warmup_seconds {
thread::sleep(Duration::from_secs(1));
if guard.0.try_wait()?.is_some() {
return Err("Process exited during warmup".into());
return Err(format_exit_error(&mut guard, "warmup"));
}

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_monitor calls try_wait() to detect early exit, then format_exit_error calls try_wait() again. If the first try_wait() already reaped the child, the second call can fail/return None, so the formatted error may miss the exit status (and you do an extra syscall). Capture the ExitStatus from the first try_wait() and pass it into format_exit_error (or restructure to call wait/try_wait only once).

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +117
let child = Command::new(binary_path)
.stderr(Stdio::piped())
.spawn()?;

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Piping the child’s stderr without draining it can deadlock the monitored process if it writes enough output to fill the OS pipe buffer (which would stall the process and skew measurements). Consider inheriting stderr by default, or spawn a thread to continuously read/drain stderr into a bounded buffer that you can include in the error message on early exit.

Suggested change
let child = Command::new(binary_path)
.stderr(Stdio::piped())
.spawn()?;
let child = Command::new(binary_path).spawn()?;

Copilot uses AI. Check for mistakes.
Comment on lines +122 to +145
fn format_exit_error(
guard: &mut ProcessGuard,
phase: &str,
) -> Box<dyn std::error::Error> {
let status = guard.0.try_wait().ok().flatten();
let stderr = guard
.0
.stderr
.take()
.and_then(|mut s| {
let mut buf = String::new();
s.read_to_string(&mut buf).ok()?;
if buf.is_empty() { None } else { Some(buf) }
});

let mut msg = format!("Process exited during {phase}");
if let Some(st) = status {
msg.push_str(&format!(" (exit status: {st})"));
}
if let Some(err) = stderr {
msg.push_str(&format!("\n--- process stderr ---\n{err}"));
}
msg.into()
}

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New format_exit_error behavior (including stderr capture and exit-status formatting) isn’t covered by tests, even though this module already has unit tests. Add targeted tests that spawn a short-lived process which writes to stderr and exits non-zero, and assert the returned error string includes the phase + captured stderr/exit status (using OS-specific commands gated by cfg).

Copilot uses AI. Check for mistakes.
@shm11C3 shm11C3 merged commit 9469f10 into develop Mar 22, 2026
24 of 28 checks passed
@shm11C3 shm11C3 deleted the ci/fix/#1272 branch March 22, 2026 04:55
@shm11C3 shm11C3 linked an issue Mar 22, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance test threshold exceeded

2 participants