Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3000886
test(logs): pin how each log-tail reader behaves today
jussielo-amd Nov 5, 2026
fce592c
fix(logs): read every log tail through one bounded, lossy routine
jussielo-amd Nov 5, 2026
b886923
test(logs): cover a log with an invalid byte in the logs scenarios
jussielo-amd Nov 5, 2026
fe12448
Merge remote-tracking branch 'origin/main' into refactor-log-tails-us…
jussielo-amd Nov 5, 2026
640e4c5
Merge remote-tracking branch 'origin/main' into refactor-log-tails-us…
jussielo-amd Nov 5, 2026
993a138
test: pin what rocm and rocmd each do when a managed stop terminates …
jussielo-amd Nov 5, 2026
3db6cd4
test: pin both copies of the keyless-respawn guard before merging them
jussielo-amd Nov 5, 2026
c14f366
refactor: stop managed services through one rocm-core routine shared …
jussielo-amd Nov 5, 2026
6e3c6d6
refactor: one endpoint-key respawn guard shared by rocm and rocmd
jussielo-amd Nov 5, 2026
566cdbc
Merge remote-tracking branch 'origin/main' into refactor-one-managed-…
jussielo-amd Nov 5, 2026
d178303
Merge remote-tracking branch 'origin/main' into refactor-one-managed-…
jussielo-amd Nov 5, 2026
f0c4606
test(engine-ipc): pin what rocm and rocmd each send an engine child a…
jussielo-amd Nov 5, 2026
e3cbccb
Merge branch 'main' of github.com:ROCm/rocm-cli into refactor-log-tai…
jussielo-amd Nov 5, 2026
6bf32ba
refactor(engine-ipc): run engine children through one stdio client sh…
jussielo-amd Nov 5, 2026
45e4b75
fix(rocmd): reach engines through the rocm executable when running as…
jussielo-amd Nov 5, 2026
7a83e9b
Merge origin/main into refactor-one-engine-ipc-client
jussielo-amd Nov 5, 2026
b945cf0
Merge origin/main into refactor-one-endpoint-key-respawn-guard
jussielo-amd Nov 5, 2026
ff616a6
Merge origin/main into refactor-one-engine-ipc-client
jussielo-amd Nov 5, 2026
4f7a0af
fix(engine-protocol): guard the stderr forwarding writes against SIGPIPE
jussielo-amd Nov 6, 2026
779586d
fix(engine-protocol): quote what the fake engine puts in shell literals
jussielo-amd Nov 6, 2026
92ba629
fix(logs): keep a UTF-8 tail read inside its size snapshot and skip a…
jussielo-amd Nov 6, 2026
9c2eabc
fix(logs): do not report a log that has content as empty or without o…
jussielo-amd Nov 6, 2026
76e3bf2
fix(services): clear the recorded processes after a confirmed rocm stop
jussielo-amd Nov 6, 2026
f8a44e2
test(e2e): stop a real managed server and its child through rocm serv…
jussielo-amd Nov 6, 2026
9f00765
Merge refactor-one-endpoint-key-respawn-guard into the managed-servic…
jussielo-amd Nov 6, 2026
0504370
Merge refactor-one-engine-ipc-client into the managed-service PR
jussielo-amd Nov 6, 2026
ef5155b
Merge refactor-log-tails-use-the-shared-routine into the managed-serv…
jussielo-amd Nov 6, 2026
c94ff29
test(e2e): write the service-stop wait in minutes for clippy
jussielo-amd Nov 6, 2026
5d9a570
fix(engine-protocol): kill and reap the engine child when its answer …
jussielo-amd Nov 6, 2026
4398998
fix(mcp): tell an empty service log from one whose newest line exceed…
jussielo-amd Nov 6, 2026
8ff2ff9
style(core): keep the first doc paragraph of the log tail summaries s…
jussielo-amd Nov 6, 2026
5f9baad
fix(core): record a process creation time as the start identity on Wi…
jussielo-amd Nov 6, 2026
852acf3
Merge origin/main into the managed-service PR
jussielo-amd Nov 6, 2026
106af92
Merge origin/main into the managed-service PR
jussielo-amd Nov 6, 2026
2f90709
Merge origin/main into the managed-service PR
jussielo-amd Nov 6, 2026
9d16666
Merge origin/main into the managed-service PR
jussielo-amd Nov 6, 2026
ef877b7
fix(core): decide a stop's identity verdict in one place that a table…
jussielo-amd Nov 6, 2026
2d19609
test(core): enter the two overlapping SIGPIPE guards in a fixed order
jussielo-amd Nov 6, 2026
806c907
test(e2e): end the process a stop scenario's recorded process started…
jussielo-amd Nov 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/rocm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ apple-native-keyring-store = { version = "1.0", features = ["keychain"] }
zbus-secret-service-keyring-store = { version = "1.0", features = ["rt-tokio-crypto-rust"] }

[dev-dependencies]
# The fake engine child both engine IPC callers are tested against.
rocm-engine-protocol = { path = "../../crates/rocm-engine-protocol", features = ["test-support"] }
# Property-based tests for the byte-size formatter behind the `download:
# approved up to …` line. "A size is printed in its own unit" has to hold at
# every unit boundary, and the narrow band where `{:.1}` rounding reaches 1024.0
Expand Down
12 changes: 5 additions & 7 deletions apps/rocm/src/chat/mcp_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::managed_service_status::{load_managed_services, managed_service_is_li
use crate::rocm_argv::{chat_cli_arg_value, chat_cli_has_flag};
use crate::runtimes_cmd::render_runtimes_text;
use crate::services_text::{
read_tail_lines, render_logs_browser_text, render_logs_text, render_service_logs_text,
read_log_tail, render_logs_browser_text, render_logs_text, render_service_logs_text,
render_services_text,
};
use crate::tool_policy::{
Expand Down Expand Up @@ -213,16 +213,14 @@ pub(crate) fn run_internal_mcp_call(
.into_iter()
.find(|service| service.service_id == service_id)
.with_context(|| format!("managed service `{service_id}` not found"))?;
let tail = read_tail_lines(&record.log_path, lines, "service log")?.join("\n");
let log_tail = read_log_tail(&record.log_path, lines, "service log")?;
Ok(internal_mcp_tool_success(
format!(
"Read the last {} line(s) from service `{}`.",
lines, record.service_id
),
rocm_core::service_log_tool_summary(&record.service_id, &log_tail),
serde_json::json!({
"service": record,
"lines": lines,
"tail": tail,
"newest_line_exceeds_read_bound": log_tail.newest_line_exceeds_the_read_bound(),
"tail": log_tail.lines.join("\n"),
}),
))
}
Expand Down
300 changes: 237 additions & 63 deletions apps/rocm/src/comfyui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,20 @@ fn render_logs_with_options(
if show_file_locations {
writeln!(output, " saved file: {}", path.display())?;
}
let lines = read_tail_lines(path, limit)
let tail = read_log_tail(path, limit)
.with_context(|| format!("failed to read {}", path.display()))?;
if lines.is_empty() {
if tail.newest_line_exceeds_the_read_bound() {
// The file has content; saying it is empty would be false.
writeln!(
output,
" No output shown: {}.",
rocm_core::newest_line_exceeds_bound_notice()
)?;
} else if tail.lines.is_empty() {
writeln!(output, " The saved log is empty.")?;
} else {
writeln!(output, " latest output:")?;
for line in lines {
for line in tail.lines {
writeln!(output, " {line}")?;
}
}
Expand Down Expand Up @@ -668,66 +675,17 @@ fn comfyui_log_title(path: &Path) -> &'static str {
}
}

fn read_tail_lines(path: &Path, limit: usize) -> Result<Vec<String>> {
let bytes = fs::read(path)?;
let text = strip_ansi_sequences(&decode_log_bytes(&bytes));
let mut lines = text
.lines()
.rev()
.take(limit)
.map(str::to_owned)
.collect::<Vec<_>>();
lines.reverse();
Ok(lines)
}

fn decode_log_bytes(bytes: &[u8]) -> String {
if bytes.starts_with(&[0xff, 0xfe]) || looks_like_utf16_le(bytes) {
let start = if bytes.starts_with(&[0xff, 0xfe]) {
2
} else {
0
};
let units = bytes[start..]
.chunks_exact(2)
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
.collect::<Vec<_>>();
return String::from_utf16_lossy(&units);
}
String::from_utf8_lossy(bytes).into_owned()
}

fn looks_like_utf16_le(bytes: &[u8]) -> bool {
if bytes.len() < 8 {
return false;
}
let sample_len = bytes.len().min(512);
let zero_odd_bytes = bytes[..sample_len]
.iter()
.enumerate()
.filter(|(index, byte)| index % 2 == 1 && **byte == 0)
.count();
zero_odd_bytes * 4 >= sample_len
}

fn strip_ansi_sequences(text: &str) -> String {
let mut cleaned = String::with_capacity(text.len());
let mut chars = text.chars().peekable();
while let Some(ch) = chars.next() {
if ch != '\x1b' {
cleaned.push(ch);
continue;
}
if chars.peek() == Some(&'[') {
let _ = chars.next();
for next in chars.by_ref() {
if ('@'..='~').contains(&next) {
break;
}
}
}
}
cleaned
/// The last `limit` lines of a saved log, read through the shared bounded tail
/// routine. A ComfyUI log may have been redirected by a Windows shell as
/// UTF-16 and carries the colour codes of the Python process, so it is
/// decoded the console way: UTF-16 detected, ANSI sequences stripped.
fn read_log_tail(path: &Path, limit: usize) -> Result<rocm_core::LogTail> {
rocm_core::tail_log_decoded(
path,
limit,
rocm_core::LOG_VIEW_MAX_TAIL_READ,
rocm_core::LogDecode::CONSOLE,
)
}

fn load_manifest(paths: &AppPaths) -> Result<Option<ComfyUiManifest>> {
Expand Down Expand Up @@ -1162,6 +1120,222 @@ mod tests {
Ok(())
}

/// The lines of [`read_log_tail`], for the tests that compare lines.
fn read_tail_lines(path: &Path, limit: usize) -> Result<Vec<String>> {
Ok(read_log_tail(path, limit)?.lines)
}

fn tail_fixture(name: &str, bytes: &[u8]) -> Result<PathBuf> {
let paths = test_paths(name);
let dir = app_root(&paths).join("logs");
fs::create_dir_all(&dir)?;
let path = dir.join("start-fixture.log");
fs::write(&path, bytes)?;
Ok(path)
}

fn utf16_le(text: &str, bom: bool) -> Vec<u8> {
let mut bytes = if bom { vec![0xff, 0xfe] } else { Vec::new() };
for unit in text.encode_utf16() {
bytes.extend_from_slice(&unit.to_le_bytes());
}
bytes
}

/// 5 MiB: a marked first line, 5120 lines of 1 KiB, a marked last line.
fn large_log_with_head_marker() -> Vec<u8> {
let mut bytes = b"HEAD-MARKER\n".to_vec();
let filler = format!("{}\n", "x".repeat(1023));
for _ in 0..5120 {
bytes.extend_from_slice(filler.as_bytes());
}
bytes.extend_from_slice(b"TAIL-MARKER\n");
bytes
}

/// What `render_logs` prints for a lone saved log with these bytes, and
/// the log's size on disk, so a message is asserted with the state it
/// describes.
fn render_lone_log(name: &str, bytes: &[u8]) -> Result<(String, u64)> {
let paths = test_paths(name);
let logs = app_root(&paths).join("logs");
fs::create_dir_all(&logs)?;
let log = logs.join("start-fixture.log");
fs::write(&log, bytes)?;
let size = fs::metadata(&log)?.len();
Ok((render_logs(&paths, 5)?, size))
}

#[test]
fn logs_say_a_log_is_empty_only_when_it_is_and_name_the_bound_when_it_is_not() -> Result<()> {
let bound = rocm_core::LOG_VIEW_MAX_TAIL_READ;
assert_eq!(
bound,
4 * 1024 * 1024,
"the notice below names this many MiB"
);
let notice = "No output shown: the newest line is longer than the 4 MiB a log view reads.";
let over_the_bound = usize::try_from(bound)? + 1024;

// An empty file: the log really is empty, and says so.
let (rendered, size) = render_lone_log("comfyui-logs-empty", b"")?;
assert_eq!(size, 0);
assert!(rendered.contains("The saved log is empty."), "{rendered}");
assert!(!rendered.contains(notice), "{rendered}");

// One line longer than the bound, with and without a final newline,
// and as sixteen-bit text: the file has content, so it is not empty,
// and the notice names the bound.
let one_line = "x".repeat(over_the_bound).into_bytes();
let mut with_newline = one_line.clone();
with_newline.push(b'\n');
let wide = utf16_le(&"y".repeat(over_the_bound / 2 + 1), true);
for (name, bytes) in [
("comfyui-logs-long-line", one_line),
("comfyui-logs-long-line-newline", with_newline),
("comfyui-logs-long-line-wide", wide),
] {
let (rendered, size) = render_lone_log(name, &bytes)?;
assert!(size > bound, "{name}: the log is bigger than the bound");
assert!(rendered.contains(notice), "{name}: {rendered}");
assert!(!rendered.contains("is empty"), "{name}: {rendered}");
assert!(!rendered.contains("latest output:"), "{name}: {rendered}");
}

// A big log whose newest lines are short is shown, not described.
let (rendered, size) = render_lone_log("comfyui-logs-big", &large_log_with_head_marker())?;
assert!(size > bound);
assert!(rendered.contains("TAIL-MARKER"), "{rendered}");
assert!(!rendered.contains(notice), "{rendered}");
Ok(())
}

#[test]
fn read_tail_lines_a_large_file_is_read_through_a_bounded_window() -> Result<()> {
// A line far outside the tail window is not returned however large the
// limit: the log is not read whole.
let log = tail_fixture("comfyui-tail-large", &large_log_with_head_marker())?;

let lines = read_tail_lines(&log, 10_000)?;
fs::remove_file(&log)?;

assert!(!lines.iter().any(|line| line == "HEAD-MARKER"));
assert_eq!(lines.last().map(String::as_str), Some("TAIL-MARKER"));
assert!(lines.len() < 5122, "got {} lines", lines.len());
assert!(lines.len() > 3500, "the window holds about 4 MiB of lines");
Ok(())
}

#[test]
fn read_tail_lines_a_large_sixteen_bit_log_is_read_through_a_bounded_window() -> Result<()> {
// The window of a UTF-16 log must start on a character boundary or
// every following character decodes as garbage.
let mut text = String::from("HEAD-MARKER\r\n");
let filler = format!("\u{1b}[33m{}\u{1b}[0m\r\n", "y".repeat(1000));
for _ in 0..3000 {
text.push_str(&filler);
}
text.push_str("TAIL-MARKER\r\n");
let log = tail_fixture("comfyui-tail-large-utf16", &utf16_le(&text, true))?;
assert!(fs::metadata(&log)?.len() > 6_000_000);

let lines = read_tail_lines(&log, 10_000)?;
fs::remove_file(&log)?;

assert!(!lines.iter().any(|line| line == "HEAD-MARKER"));
assert_eq!(lines.last().map(String::as_str), Some("TAIL-MARKER"));
let whole = "y".repeat(1000);
for line in &lines[..lines.len() - 1] {
assert_eq!(line, &whole, "a partial leading fragment was kept");
}
Ok(())
}

#[test]
fn read_tail_lines_decodes_a_bomless_utf16_log_and_strips_ansi() -> Result<()> {
let text = "\u{1b}[32m[INFO]\u{1b}[0m one\r\n\u{1b}[1;31mtwo\u{1b}[0m\r\n";
let log = tail_fixture("comfyui-tail-utf16-nobom", &utf16_le(text, false))?;

let lines = read_tail_lines(&log, 5)?;

assert_eq!(lines, vec!["[INFO] one", "two"]);
Ok(())
}

#[test]
fn read_tail_lines_strips_ansi_from_an_eight_bit_log() -> Result<()> {
let log = tail_fixture("comfyui-tail-ansi-utf8", b"\x1b[32mgreen\x1b[0m done\n")?;

assert_eq!(read_tail_lines(&log, 5)?, vec!["green done"]);
Ok(())
}

#[test]
fn read_tail_lines_decodes_invalid_eight_bit_text_lossily() -> Result<()> {
let log = tail_fixture("comfyui-tail-invalid", b"ok\nbad\xffbyte\nlast\n")?;

assert_eq!(
read_tail_lines(&log, 5)?,
vec!["ok", "bad\u{FFFD}byte", "last"]
);
Ok(())
}

#[test]
fn read_tail_lines_missing_file_is_a_not_found_error_naming_the_path() {
let paths = test_paths("comfyui-tail-missing");
let missing = app_root(&paths).join("logs").join("absent.log");

let error = read_tail_lines(&missing, 5).expect_err("a missing log must not read");

assert_eq!(
error.to_string(),
format!("failed to open {}", missing.display())
);
let io_error = error
.downcast_ref::<io::Error>()
.expect("the io error is kept as the cause");
assert_eq!(io_error.kind(), io::ErrorKind::NotFound);
// A limit of 0 returns before the file is looked at.
assert!(
read_tail_lines(&missing, 0)
.expect("limit 0 never opens the file")
.is_empty()
);
}

#[test]
fn read_tail_lines_limit_zero_returns_nothing_for_an_existing_log() -> Result<()> {
let log = tail_fixture("comfyui-tail-zero", b"a\nb\n")?;

assert!(read_tail_lines(&log, 0)?.is_empty());
Ok(())
}

#[test]
fn read_tail_lines_returns_every_line_when_fewer_than_the_limit() -> Result<()> {
let log = tail_fixture("comfyui-tail-few", b"a\nb\n")?;

assert_eq!(read_tail_lines(&log, 50)?, vec!["a", "b"]);
Ok(())
}

#[test]
fn read_tail_lines_keeps_a_final_line_without_a_trailing_newline() -> Result<()> {
let log = tail_fixture("comfyui-tail-no-newline", b"a\nb\nc")?;

assert_eq!(read_tail_lines(&log, 2)?, vec!["b", "c"]);
Ok(())
}

#[test]
fn read_tail_lines_strips_crlf_line_endings() -> Result<()> {
let log = tail_fixture("comfyui-tail-crlf", b"a\r\nb\r\n")?;

assert_eq!(read_tail_lines(&log, 5)?, vec!["a", "b"]);
Ok(())
}

#[test]
fn unmanaged_running_url_reports_reachable_loopback_endpoint() -> Result<()> {
let listener = TcpListener::bind("127.0.0.1:0")?;
Expand Down
Loading
Loading