From 56e979ecbfdfbe77192e944c785f9ad279051d40 Mon Sep 17 00:00:00 2001 From: Eugene Volen Date: Fri, 13 Nov 2026 12:40:31 +0200 Subject: [PATCH 1/2] fix(diagnose): count a bad byte's offset from the start of --symptom-file input --symptom-file names the offset of the first byte that is not valid UTF-8. After dropping a UTF-8 byte-order mark the offset was counted in what was left, so a file that began with a BOM and then held bad UTF-8 named an offset three bytes too small, against the module's own promise that the error says where decoding failed. The offset now counts from the start of the input, and a test pins it behind a BOM. Also from the review of the original change: say that a file named `-` is passed as `./-`, pin how the advised-command scanner treats `<<<` here-strings, re-wrap an overlong line in docs/wsl.md, and correct the note in docs/testing.md about which CI lanes run the Windows shell forms of diagnose-59: the self-hosted Strix Halo Windows lanes, per pull request and nightly, neither of them required. Follow-up to #1048. Part of ROCMAI-955. Signed-off-by: Eugene Volen --- README.md | 17 +++++++++-------- apps/rocm/src/advised_commands.rs | 5 +++++ apps/rocm/src/cli.rs | 3 ++- apps/rocm/src/symptom_input.rs | 28 ++++++++++++++++++++-------- docs/manual-testing.md | 3 +++ docs/testing.md | 11 ++++++++++- docs/wsl.md | 4 ++-- 7 files changed, 51 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 143ff6f4c..21c84b3f2 100644 --- a/README.md +++ b/README.md @@ -380,14 +380,15 @@ position. reads that text first: quotes, `$(...)` and a leading `-` in a pasted error can be changed, run, or taken as a flag. - `--symptom-file PATH` reads the same text from a file instead, or from - standard input when PATH is `-`, so no quoting is needed. It cannot be - combined with `--symptom`. The text that arrives is matched as `--symptom` - would match it, minus one trailing line break. A UTF-8 byte-order mark is - dropped and a UTF-16 file with a byte-order mark (what Windows PowerShell's - `>` writes) is decoded; anything else must be UTF-8. A file that cannot be - read, input that is not text, or input larger than 16 MiB is a usage error - (exit code 2). With nothing piped in, paste the error at the terminal and - end it with Ctrl-D at the start of a line (Ctrl-Z then Enter on Windows). + standard input when PATH is `-`, so no quoting is needed (a file named `-` + is passed as `./-`). It cannot be combined with `--symptom`. The text that + arrives is matched as `--symptom` would match it, minus one trailing line + break. A UTF-8 byte-order mark is dropped and a UTF-16 file with a + byte-order mark (what Windows PowerShell's `>` writes) is decoded; anything + else must be UTF-8. A file that cannot be read, input that is not text, or + input larger than 16 MiB is a usage error (exit code 2). With nothing piped + in, paste the error at the terminal and end it with Ctrl-D at the start of + a line (Ctrl-Z then Enter on Windows). ```bash # bash (Linux, WSL): the quoted 'EOF' keeps the shell out of the paste diff --git a/apps/rocm/src/advised_commands.rs b/apps/rocm/src/advised_commands.rs index 6f5791ffd..97119718c 100644 --- a/apps/rocm/src/advised_commands.rs +++ b/apps/rocm/src/advised_commands.rs @@ -2126,6 +2126,9 @@ fn a_heredoc_ends_the_command() { "rocm diagnose --symptom-file - <<\"EOF\"", "rocm diagnose --symptom-file - << EOF", "rocm diagnose --symptom-file - <, /// Read the error text from a file instead, or from standard input - /// when PATH is `-`, so no shell quoting is needed. + /// when PATH is `-`, so no shell quoting is needed. A file named `-` + /// is passed as `./-`. /// /// The text that arrives is matched as `--symptom` would match it, /// with one trailing line break removed (shells and editors add one). diff --git a/apps/rocm/src/symptom_input.rs b/apps/rocm/src/symptom_input.rs index 162af5b07..77daaee25 100644 --- a/apps/rocm/src/symptom_input.rs +++ b/apps/rocm/src/symptom_input.rs @@ -145,12 +145,14 @@ fn read_symptom(reader: impl Read, source: &str) -> Result) -> Result { - if bytes.starts_with(&[0xEF, 0xBB, 0xBF]) { - bytes.drain(..3); - return utf8(bytes); + const UTF8_BOM: [u8; 3] = [0xEF, 0xBB, 0xBF]; + if bytes.starts_with(&UTF8_BOM) { + bytes.drain(..UTF8_BOM.len()); + return utf8(bytes, UTF8_BOM.len()); } if let Some(rest) = bytes.strip_prefix(&[0xFF, 0xFE]) { return utf16(rest, u16::from_le_bytes); @@ -158,14 +160,17 @@ fn decode(mut bytes: Vec) -> Result { if let Some(rest) = bytes.strip_prefix(&[0xFE, 0xFF]) { return utf16(rest, u16::from_be_bytes); } - utf8(bytes) + utf8(bytes, 0) } -fn utf8(bytes: Vec) -> Result { +/// `bytes` as UTF-8. `skipped` is how many bytes of the input came before +/// them (a byte-order mark), so the offset in an error counts from the start +/// of the input, where the user can find the byte. +fn utf8(bytes: Vec, skipped: usize) -> Result { String::from_utf8(bytes).map_err(|error| { format!( "it is not valid UTF-8 (invalid byte at offset {})", - error.utf8_error().valid_up_to() + skipped + error.utf8_error().valid_up_to() ) }) } @@ -257,6 +262,13 @@ mod tests { assert!(message.contains("offset 10"), "{message}"); assert!(message.contains("UTF-8"), "{message}"); + // Behind a UTF-8 byte-order mark the offset still counts from the + // start of the input, so it points at the byte in the file. + let mut with_bom = vec![0xEF, 0xBB, 0xBF]; + with_bom.extend_from_slice(b"HIP error \xff at"); + let message = read(&with_bom).unwrap_err().to_string(); + assert!(message.contains("offset 13"), "{message}"); + // A UTF-16 BOM with an odd tail, and one with a lone surrogate. assert!(matches!( read(&[0xFF, 0xFE, 0x41]), diff --git a/docs/manual-testing.md b/docs/manual-testing.md index eb3f8de01..cee6f2d99 100644 --- a/docs/manual-testing.md +++ b/docs/manual-testing.md @@ -1664,6 +1664,9 @@ Then, in an empty directory, hand it over in each shell you have: `rocm diagnose --symptom-file error.txt`. - Any shell, nothing piped in: `rocm diagnose --symptom-file -`, paste at the prompt, and end the input as the hint printed on the first line says. +- A file named `-`: save the paste as `-` and run + `rocm diagnose --symptom-file ./-`. It reports the same causes; a bare `-` + would read standard input instead. Expected result: diff --git a/docs/testing.md b/docs/testing.md index 127d45c6b..7add28041 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -4469,7 +4469,16 @@ hold the behaviour end to end, GPU or not: pipe), so nothing in it can run by construction; the scenario asserts the diagnosis, not the absence of something no shell could do. The paste is ASCII: Windows PowerShell 5.1 pipes text as ASCII, which is why the docs - send PowerShell users through a file instead. + send PowerShell users through a file instead. The cmd.exe and Windows + PowerShell runs need a Windows host, so in CI they run only on the + self-hosted Strix Halo Windows lanes: `e2e-gpu-strix-windows` in + [e2e-selfhosted.yml](../.github/workflows/e2e-selfhosted.yml) (per pull + request, behind that workflow's path filter) and the scheduled + `e2e-gpu-nightly-strix-windows` in + [nightly.yml](../.github/workflows/nightly.yml). Neither is a required + check. The required `E2E tests` job in [ci.yml](../.github/workflows/ci.yml) + runs only the bash half, on Linux, and ci.yml's Windows lane does not run + this scenario. - `diagnose-60` (Linux and WSL lanes only, like every pseudo-terminal scenario here; the Windows key is checked by hand in [manual-testing.md](manual-testing.md) section 13) runs diff --git a/docs/wsl.md b/docs/wsl.md index 666f5e9e2..7c14a9de2 100644 --- a/docs/wsl.md +++ b/docs/wsl.md @@ -189,8 +189,8 @@ Eight entries that are not WSL-specific also run on WSL: `fix-1-arch`, `fix-2-unset-override`, `fix-6-path`, `fix-8-wheel-rocm`, `fix-16-vllm-oom`, `fix-17-torch-dlpack`, `fix-18-comgr-conflict`, and `fix-19-shm-too-small`. `fix-16-vllm-oom` and `fix-17-torch-dlpack` are driven by the error text you -pass with `--symptom` (or `--symptom-file`) and read nothing from the environment or the ROCm -install. `fix-18-comgr-conflict` and +pass with `--symptom` (or `--symptom-file`) and read nothing from the +environment or the ROCm install. `fix-18-comgr-conflict` and `fix-19-shm-too-small` apply when you run `rocm diagnose` inside the distro. A `--distro` run skips both (see [Diagnose a distro from Windows](#diagnose-a-distro-from-windows) later in this From 529cd214f00b03f56f3acfc3625bb57a6dc175e8 Mon Sep 17 00:00:00 2001 From: Eugene Volen Date: Mon, 16 Nov 2026 10:12:34 +0200 Subject: [PATCH 2/2] test(diagnose): pin that a file named `-` is read as a file, and complete a CI note The documentation now tells users that a file literally named `-` is passed as `./-`, because `-` alone means standard input. Nothing tested that claim. A unit test now checks that the two spellings are different paths and that a file named `-` is opened as a file. Also complete the note in docs/testing.md about where the Windows shell forms of diagnose-59 run: the self-hosted Strix Halo Windows lane runs on pull requests behind its path filter, on pushes to main and release branches, and in the merge queue, in addition to the scheduled nightly lane. Neither is a required check. Follow-up to #1048. Part of ROCMAI-955. Signed-off-by: Eugene Volen --- apps/rocm/src/symptom_input.rs | 16 ++++++++++++++++ docs/testing.md | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/rocm/src/symptom_input.rs b/apps/rocm/src/symptom_input.rs index 77daaee25..bca04651b 100644 --- a/apps/rocm/src/symptom_input.rs +++ b/apps/rocm/src/symptom_input.rs @@ -326,6 +326,22 @@ mod tests { assert_eq!(resolve(None, None).unwrap(), None); } + // `-` alone means standard input, so a file literally named `-` is reached + // as `./-`, which is what the documentation tells the user. The two + // spellings are different paths, and a path that is not `-` is opened as a + // file whatever the working directory. + #[test] + fn a_file_named_dash_is_read_as_a_file_not_as_standard_input() { + assert_ne!(Path::new("./-").as_os_str(), STDIN_PATH); + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("-"); + std::fs::write(&path, "from the file named dash\n").unwrap(); + assert_eq!( + resolve(None, Some(&path)).unwrap().as_deref(), + Some("from the file named dash") + ); + } + #[test] fn a_bad_file_is_a_usage_error_naming_the_command() { let error = usage_error(&SymptomFileError::TooLarge { diff --git a/docs/testing.md b/docs/testing.md index 7add28041..7eea475cc 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -4472,8 +4472,9 @@ hold the behaviour end to end, GPU or not: send PowerShell users through a file instead. The cmd.exe and Windows PowerShell runs need a Windows host, so in CI they run only on the self-hosted Strix Halo Windows lanes: `e2e-gpu-strix-windows` in - [e2e-selfhosted.yml](../.github/workflows/e2e-selfhosted.yml) (per pull - request, behind that workflow's path filter) and the scheduled + [e2e-selfhosted.yml](../.github/workflows/e2e-selfhosted.yml) (on pull + requests that touch the serve paths, on pushes to `main` and `release/**`, + and in the merge queue) and the scheduled `e2e-gpu-nightly-strix-windows` in [nightly.yml](../.github/workflows/nightly.yml). Neither is a required check. The required `E2E tests` job in [ci.yml](../.github/workflows/ci.yml)