Skip to content

Commit 166c665

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): surface install failures hidden by curl-pipe exit codes (#2892)
Ubuntu Doctor reports `Install failed at verify: The installer finished, but Buzz still could not use claude-code (observed: CLI missing)` while the `cli` step shows success. The `cli` step is lying. ## The masking Every CLI install command is a pipe — `curl -fsSL https://claude.ai/install.sh | bash` (`managed_agents/discovery.rs:109`), `… | sh` for Codex (`:141`), `… | CONFIGURE=false bash` for Goose (`:75`). `install_shell_command` ran them through `bash -l -c` with no `pipefail`, so the pipeline's exit status was the **right-hand** side's. A `curl` that fails — or that isn't on the child's PATH at all — feeds `bash` an empty stdin, and `bash` with nothing to run exits 0: ``` $ /bin/bash -l -c 'curl -fsSL https://nonexistent.invalid/x.sh | bash'; echo $? curl: (6) Could not resolve host: nonexistent.invalid 0 $ PATH=/tmp/empty /bin/bash -l -c 'curl -fsSL https://claude.ai/install.sh | bash'; echo $? bash: line 1: curl: command not found 0 ``` `run_install_command` records exit 0 as `success: true`, the adapter step then installs fine (it uses Buzz's own bundled Node, no system PATH needed), and `post_install_verification` correctly reports the CLI is absent. The user is handed a `verify` riddle instead of curl's error, which is why diagnosing this required three rounds of guessing. Install commands now run under `set -o pipefail`, so the left-hand side's failure is the step's failure and `InstallStepResult.stderr` carries the vendor's own message. `SHELLOPTS` is not exported by either shell, so the piped-to vendor script still runs with its default options. The Windows PowerShell install path (`install_powershell_command`) bypasses this shell and is untouched. ## The PATH collapse it was hiding `install_shell_command` composes the child's PATH and calls `cmd.env("PATH", …)`, which **replaces** rather than extends. `should_use_inherited` was `is_windows && !had_shell_path && has_local_context`, so on Unix the inherited process PATH was never appended. When `login_shell_path()` returns `None` — a login shell that exits non-zero or prints nothing, which a GUI-launched process can easily hit via `~/.profile` — the child's entire PATH becomes Buzz's two managed Node dirs. There is no `curl`, `sh`, `sha256sum`, or `tar` in either, so every curl-pipe install fails, and before this PR it failed invisibly. The `is_windows` requirement is dropped: the inherited PATH is the floor whenever no login-shell PATH was obtained, on every OS. Both existing suppressions are kept — a login-shell PATH present still suppresses it (no doubling), and no home/exe context still suppresses it (never manufacture a PATH from ambient state alone). Inherited entries stay **last**, so managed dirs keep precedence. The other caller, `build_augmented_path` (`runtime/path.rs:148`, feeding agent spawns and CLI probes), reads correctly under the new rule for the same reason: it only gains the inherited PATH in the case where it would otherwise hand a child a PATH with no native entries. When a login-shell PATH exists — the normal case on macOS and Linux — its output is unchanged, which `unix_shell_path_suppresses_inherited_fallback` pins. ## Scope This fixes the reporting defect and the PATH floor. The specific environment failure on the affected Ubuntu box is still being diagnosed and is deliberately not addressed here; the point of this change is that the next attempt produces the real error instead of a `verify` riddle. One interaction worth noting: `install_failure_is_retryable` retries any failure that carries an exit code, so a pipefail-surfaced curl failure now gets 3 attempts with backoff — correct for transient network blips, and harmless for hard failures. `desktop/scripts/check-file-sizes.mjs` ratchets the `agent_discovery.rs` ceiling 1836 → 1895 for the added tests. --------- Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
1 parent c9a7372 commit 166c665

3 files changed

Lines changed: 320 additions & 74 deletions

File tree

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,15 @@ const overrides = new Map([
492492
// fix for the Goose Windows installer (PR #2680 interaction with #2750).
493493
// +10: pass an explicit PATH through Codex adapter install planning so unit
494494
// tests avoid the process-global login-shell PATH cache.
495-
["src-tauri/src/commands/agent_discovery.rs", 1836],
495+
// +59: run install commands under `pipefail` so a failing `curl` in a
496+
// `curl … | bash` install fails the `cli` step instead of being masked by
497+
// `bash`'s exit 0, plus tests for the arg shape and the real pipeline status.
498+
// +81: install_shell_args re-exports the composed PATH inside the command
499+
// body so login startup files can't clear or reorder it, plus an isolated
500+
// hostile-profile regression the pure composition tests structurally miss.
501+
// +42: gate that re-export off Windows, where join_paths is `;`-separated and
502+
// bash would collapse it into one entry, plus a platform-shape test.
503+
["src-tauri/src/commands/agent_discovery.rs", 2022],
496504
// draft-persistence predicate: submit-time `loadDraft` check + inline comment
497505
// + deps-array entry in submitMessage closes the never-persisted-boundary
498506
// defect (Thufir Pass-3 finding). Load-bearing correctness fix; queued to

‎desktop/src-tauri/src/commands/agent_discovery.rs‎

Lines changed: 197 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,62 @@ fn persist_last_error_on_install(
547547
save_managed_agents(app, &records)
548548
}
549549

550+
/// Build the `-l -c` argument list for the install shell.
551+
///
552+
/// The body runs under `pipefail`: every CLI install command is a `curl … |
553+
/// bash` / `| sh` pipe, and without it the pipeline's status is the right-hand
554+
/// side's — `bash`/`sh` fed an empty stdin exits 0 — so a `curl` that fails (or
555+
/// isn't on PATH at all) was recorded as a successful `cli` step, leaving the
556+
/// user an unactionable `verify` error instead of curl's own stderr. Every
557+
/// install shell supports it; the Windows PowerShell path bypasses this shell.
558+
/// `SHELLOPTS` is not exported, so the piped-to vendor script keeps its own
559+
/// defaults.
560+
///
561+
/// Off Windows, `composed_path` is passed as a positional and re-exported
562+
/// *inside* the body, because `-l` sources the user's login startup files after
563+
/// the process environment is installed: a profile assigning PATH overwrites
564+
/// `cmd.env("PATH", …)` before the vendor command runs. `export PATH=` empties
565+
/// it outright; macOS `/etc/zprofile` runs `path_helper`, which reorders it and
566+
/// costs Buzz's managed Node/npm dirs their precedence. A positional rather than
567+
/// an interpolated body keeps entries containing spaces or quotes intact.
568+
///
569+
/// The prelude is omitted where it would do harm:
570+
/// - `composed_path` is `None` — `export PATH="$1"` with `$1` unset sets an
571+
/// *empty* PATH, worse than the ambient one.
572+
/// - `is_windows` — `join_paths` uses the platform separator, so the positional
573+
/// would be `;`-joined while bash splits PATH on `:`, collapsing every entry
574+
/// into one nonsense path; and Windows is where the inherited fallback always
575+
/// fires (`login_shell_path()` is unconditionally `None` there), so this would
576+
/// be the steady state. `cmd.env("PATH", …)` already delivers the native form
577+
/// Git Bash translates on entry, and Windows has no login startup files doing
578+
/// the clobbering this prelude defends against.
579+
///
580+
/// `is_windows` is a parameter rather than a `#[cfg]` so the Windows shape stays
581+
/// asserted on Unix CI — the same reason `should_skip_claude_executable` takes
582+
/// one. Extracted from `install_shell_command` for that testability, not because
583+
/// it has more than one caller.
584+
fn install_shell_args(
585+
command: &str,
586+
composed_path: Option<&std::ffi::OsStr>,
587+
is_windows: bool,
588+
) -> Vec<std::ffi::OsString> {
589+
let Some(path) = composed_path.filter(|_| !is_windows) else {
590+
return vec![
591+
"-l".into(),
592+
"-c".into(),
593+
format!("set -o pipefail; {command}").into(),
594+
];
595+
};
596+
vec![
597+
"-l".into(),
598+
"-c".into(),
599+
format!("export PATH=\"$1\"; set -o pipefail; {command}").into(),
600+
// `$0` is the shell-name slot, so the PATH must be the second positional.
601+
"buzz-install".into(),
602+
path.to_os_string(),
603+
]
604+
}
605+
550606
/// Build a login-shell `Command` for `command` with hermit env vars stripped,
551607
/// Buzz-managed npm locations set, and the user's PATH set. This is the
552608
/// single source of truth for
@@ -561,18 +617,25 @@ fn install_shell_command(command: &str) -> Result<std::process::Command, String>
561617
let shell: std::path::PathBuf = resolve_install_shell()?;
562618

563619
let mut cmd = std::process::Command::new(&shell);
564-
cmd.args(["-l", "-c", command]);
565620

566621
// Strip hermit vars and set managed npm paths (see apply_npm_env).
567622
apply_npm_env(&mut cmd);
568623

569624
// Compose the PATH for the install shell using the same kernel as the
570625
// runtime/probe path so the two can never drift. managed entries first
571626
// (Node/npm bins keep precedence); login-shell entries next; inherited
572-
// process PATH appended last on Windows when no login-shell PATH exists
573-
// (login_shell_path() always returns None on Windows — Git Bash paths are
574-
// POSIX-shaped and poison native children; cmd.env("PATH", …) replaces
575-
// rather than extends, so without inherited the install shell loses npm).
627+
// process PATH appended last when no login-shell PATH exists — the case
628+
// where the composed PATH would otherwise be Buzz's managed Node dirs
629+
// alone, with no `curl`/`sh`/`tar` for the vendor install pipes
630+
// (cmd.env("PATH", …) replaces rather than extends). On Windows that case
631+
// is the steady state: login_shell_path() always returns None there
632+
// because Git Bash paths are POSIX-shaped and poison native children.
633+
//
634+
// The composed PATH is set twice on purpose off Windows: `cmd.env` so the
635+
// login startup files themselves run with a usable PATH, and the `$1`
636+
// export in `install_shell_args` so their own PATH assignments cannot undo
637+
// it. Neither is redundant — see `install_shell_args`, which also explains
638+
// why the export is suppressed on Windows.
576639
let login_path = crate::managed_agents::login_shell_path();
577640
let had_login = login_path.is_some();
578641
let managed: Vec<std::path::PathBuf> = [
@@ -589,14 +652,20 @@ fn install_shell_command(command: &str) -> Result<std::process::Command, String>
589652
let inherited: Vec<std::path::PathBuf> = std::env::var_os("PATH")
590653
.map(|p| std::env::split_paths(&p).collect())
591654
.unwrap_or_default();
592-
let use_inherited = crate::managed_agents::should_use_inherited(had_login, true, cfg!(windows));
655+
let use_inherited = crate::managed_agents::should_use_inherited(had_login, true);
593656
let path_parts =
594657
crate::managed_agents::compose_path_entries(managed, login, inherited, use_inherited);
595-
if !path_parts.is_empty() {
596-
if let Ok(path) = std::env::join_paths(path_parts) {
597-
cmd.env("PATH", path);
598-
}
599-
}
658+
let composed_path = (!path_parts.is_empty())
659+
.then(|| std::env::join_paths(path_parts).ok())
660+
.flatten();
661+
if let Some(path) = composed_path.as_deref() {
662+
cmd.env("PATH", path);
663+
}
664+
cmd.args(install_shell_args(
665+
command,
666+
composed_path.as_deref(),
667+
cfg!(windows),
668+
));
600669

601670
// Detach from the controlling terminal so install scripts that read from
602671
// /dev/tty (e.g. Codex's "Start Codex now? [y/N]") fall back to stdin
@@ -1408,6 +1477,123 @@ mod tests {
14081477
assert!(result.is_ok(), "install_shell_command must succeed on Unix");
14091478
}
14101479

1480+
// ── pipefail: install pipes must not mask a failing left-hand side ────────
1481+
1482+
/// The command handed to the install shell must run under `set -o pipefail;`
1483+
/// with the vendor command preserved verbatim, so `curl … | bash` fails when
1484+
/// `curl` does. Platform-agnostic: only the PATH prelude differs by OS, and
1485+
/// `test_install_shell_args_shape_per_platform` pins that.
1486+
#[test]
1487+
fn test_install_shell_command_enables_pipefail() {
1488+
let cmd = super::install_shell_command("curl -fsSL https://example.test/i.sh | bash")
1489+
.expect("install shell must resolve on a test host");
1490+
let args: Vec<String> = cmd
1491+
.get_args()
1492+
.map(|a| a.to_string_lossy().into_owned())
1493+
.collect();
1494+
let body = &args[2];
1495+
assert!(
1496+
body.contains("set -o pipefail; "),
1497+
"the install body must set pipefail; got: {body}"
1498+
);
1499+
assert!(
1500+
body.ends_with("curl -fsSL https://example.test/i.sh | bash"),
1501+
"the vendor command must be preserved verbatim; got: {body}"
1502+
);
1503+
}
1504+
1505+
/// The PATH prelude is emitted only where it helps, and the exact argument
1506+
/// vector is the contract: a stray trailing positional with no `$1` reader,
1507+
/// or an export whose `$1` the shell cannot split, both corrupt PATH.
1508+
/// Windows is excluded because `join_paths` is `;`-separated there while bash
1509+
/// splits PATH on `:` — and it is the platform where the inherited fallback
1510+
/// always fires. See `install_shell_args` for the full reasoning.
1511+
#[test]
1512+
fn test_install_shell_args_shape_per_platform() {
1513+
let composed = std::ffi::OsString::from("/buzz/node/bin:/usr/bin");
1514+
let windows_composed = std::ffi::OsString::from(r"C:\buzz\node;C:\Windows\system32");
1515+
let bare = ["-l", "-c", "set -o pipefail; echo hi"].map(std::ffi::OsString::from);
1516+
1517+
assert_eq!(
1518+
super::install_shell_args("echo hi", Some(&composed), false),
1519+
[
1520+
"-l",
1521+
"-c",
1522+
"export PATH=\"$1\"; set -o pipefail; echo hi",
1523+
"buzz-install",
1524+
"/buzz/node/bin:/usr/bin",
1525+
]
1526+
.map(std::ffi::OsString::from),
1527+
"Unix must re-export the composed PATH after login init"
1528+
);
1529+
assert_eq!(
1530+
super::install_shell_args("echo hi", Some(&windows_composed), true),
1531+
bare,
1532+
"Windows must not re-export a `;`-joined PATH inside bash"
1533+
);
1534+
assert_eq!(
1535+
super::install_shell_args("echo hi", None, false),
1536+
bare,
1537+
"no composed PATH must yield the bare pipefail body and no positionals"
1538+
);
1539+
}
1540+
1541+
/// Regression for the login-startup-file overwrite: `cmd.env("PATH", …)` is
1542+
/// installed *before* `-l` sources the user's profile, so a profile that
1543+
/// assigns PATH silently discards the composed one. Uses `/bin/bash`
1544+
/// explicitly — the planted profile is bash-specific, so resolving the host
1545+
/// shell (which prefers zsh) would make this vacuous.
1546+
#[cfg(unix)]
1547+
#[test]
1548+
fn test_composed_path_survives_a_profile_that_clears_it() {
1549+
let home = tempfile::tempdir().expect("temp HOME");
1550+
std::fs::write(home.path().join(".bash_profile"), "export PATH=\n")
1551+
.expect("plant a hostile login profile");
1552+
let composed = std::ffi::OsString::from("/buzz/sentinel/bin:/usr/bin:/bin");
1553+
1554+
// `echo` is a shell builtin, so the child needs no PATH to report one.
1555+
let out = std::process::Command::new("/bin/bash")
1556+
.args(super::install_shell_args(
1557+
"echo \"$PATH\"",
1558+
Some(&composed),
1559+
false,
1560+
))
1561+
.env("HOME", home.path())
1562+
.env("PATH", &composed)
1563+
.stdin(std::process::Stdio::null())
1564+
.output()
1565+
.expect("bash must spawn");
1566+
1567+
let path = String::from_utf8_lossy(&out.stdout);
1568+
assert!(
1569+
path.contains("/buzz/sentinel/bin"),
1570+
"the composed PATH must survive login init; got: {path:?}"
1571+
);
1572+
}
1573+
1574+
/// End-to-end on the real resolved install shell (no network): a pipeline
1575+
/// whose left-hand side fails must exit non-zero, while a fully successful
1576+
/// pipeline must still succeed. Without `pipefail` the status is the
1577+
/// right-hand side's and the left-hand failure is invisible.
1578+
#[cfg(unix)]
1579+
#[test]
1580+
fn test_install_shell_pipeline_status_follows_left_side() {
1581+
for (command, expect_success) in [("false | true", false), ("echo ok | cat", true)] {
1582+
let status = super::install_shell_command(command)
1583+
.expect("Unix must always resolve an install shell")
1584+
.stdin(std::process::Stdio::null())
1585+
.stdout(std::process::Stdio::null())
1586+
.stderr(std::process::Stdio::null())
1587+
.status()
1588+
.expect("install shell must spawn");
1589+
assert_eq!(
1590+
status.success(),
1591+
expect_success,
1592+
"`{command}` must report success={expect_success}; got {status:?}"
1593+
);
1594+
}
1595+
}
1596+
14111597
// ── Phase A: Windows install shell selection ───────────────────────────────
14121598

14131599
/// On Windows (CI runner has Git pre-installed), resolve_install_shell succeeds.

0 commit comments

Comments
 (0)