Skip to content

Commit 7fb8cd3

Browse files
authored
fix(desktop): gate codex-acp on a minimum supported version (#3254)
The codex adapter version gate accepted any `major >= 1`, so a 1.x `codex-acp` older than the version that fixes outbound relay access for `buzz` CLI subprocesses classified as `Available` and was never offered a reinstall. Only the 0.16.x `@zed-industries/codex-acp` adapter — which fails `--version` outright — was caught. `probe_codex_acp_version` now returns the full `(major, minor, patch)` triple and `codex_adapter_availability` compares it against a new `MIN_CODEX_ACP_VERSION` floor of `1.1.7`, the current npm latest. An adapter below the floor classifies as `AdapterOutdated`, which routes it through the existing uninstall-then-install reinstall plan. The parse requires exactly three numeric dot-separated components. Partial versions (`1.2`) and prerelease tags (`1.2.0-rc1`) return `None` and therefore classify as `AdapterOutdated` — a version Buzz cannot compare against the floor fails closed, offering a reinstall rather than running an adapter of unknown vintage. Both the floor's bump policy and the strict-parse behavior are stated in doc comments rather than left implicit. Supersedes [#3097](#3097) by @Bharathchinneni, whose semver floor and behavior tests this carries. That PR could not land as written: the two `probe_codex_acp_major_version` compatibility wrappers it kept had no non-test callers, which is a hard `clippy -D warnings` failure. The wrappers are deleted here and their call sites collapsed onto `probe_codex_acp_version`. Signed-off-by: Will Pfleger <[email protected]>
1 parent eeb16ab commit 7fb8cd3

5 files changed

Lines changed: 168 additions & 62 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ const overrides = new Map([
346346
// entries.push block collapsed into the helper.
347347
// +6: legacy Goose Windows install dir (%USERPROFILE%\goose) probed in
348348
// common_binary_paths so pre-#2680 standalone installs are discoverable.
349-
["src-tauri/src/managed_agents/discovery.rs", 1841],
349+
// +19: codex-acp minimum-version gate — MIN_CODEX_ACP_VERSION plus the strict
350+
// three-component parse in probe_codex_acp_version, so an outdated 1.x adapter
351+
// is offered a reinstall instead of classifying as Available on major alone.
352+
["src-tauri/src/managed_agents/discovery.rs", 1860],
350353
// BYOH — save_custom_harness_to_dir (backup-swap atomic write) + save_and_warm /
351354
// delete_and_warm (persist-mutex serialization for concurrent-safe registry
352355
// refresh, B-6). Also: id/collision/load/registry tests (from the file base) +
@@ -391,7 +394,11 @@ const overrides = new Map([
391394
// Available both-present AND adapter-present/CLI-absent — the selectability
392395
// regression guard), bound to an injectable resolver so the tests stay
393396
// PATH-independent.
394-
["src-tauri/src/managed_agents/discovery/tests.rs", 1871],
397+
// +51: codex-acp minimum-version gate — probe_codex_acp_version assertions carry
398+
// the full (major, minor, patch) triple instead of a bare major, plus
399+
// below-the-floor and uncomparable-version (partial / prerelease) classification
400+
// regressions for the fail-closed parse.
401+
["src-tauri/src/managed_agents/discovery/tests.rs", 1922],
395402
// identity-import-keyring: the identity resolution state machine's behavioral
396403
// matrix (46 tests over FakeIdentityStore — probe × marker × file cells,
397404
// adoption / read-back-corruption / marker-failure arms, recovery-mode
@@ -633,7 +640,9 @@ const overrides = new Map([
633640
// with backoff, output truncation) extracted to agent_discovery/install_exec.rs
634641
// alongside its tests, matching the managed_node.rs / post_install_verification.rs
635642
// split. The entries above describe the file's history, not its current shape.
636-
["src-tauri/src/commands/agent_discovery.rs", 1808],
643+
// +27: codex-acp minimum-version gate — test_plan_adapter_install_updates_older_
644+
// 1x_codex_binary pins that a 1.x adapter below the floor still plans a reinstall.
645+
["src-tauri/src/commands/agent_discovery.rs", 1835],
637646
// draft-persistence predicate: submit-time `loadDraft` check + inline comment
638647
// + deps-array entry in submitMessage closes the never-persisted-boundary
639648
// defect (Thufir Pass-3 finding). Load-bearing correctness fix; queued to

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn active_installs() -> &'static std::sync::Mutex<std::collections::HashSet<Stri
2525
/// `None` if none was found).
2626
///
2727
/// Returns `None` when no install is needed (adapter is present and current).
28-
/// Returns `Some(cmds)` when the adapter is missing or (for codex) outdated.
28+
/// Returns `Some(cmds)` when the adapter is missing or (for codex) below its
29+
/// minimum supported version.
2930
///
3031
/// For the codex **outdated** case the returned sequence is a two-step
3132
/// reinstall: first uninstall the old `@zed-industries/codex-acp` package
@@ -1152,7 +1153,8 @@ mod tests {
11521153
/// plan_adapter_install is the pure install-plan seam used by
11531154
/// install_acp_runtime_blocking. These tests verify:
11541155
/// - A 0.x binary (AdapterOutdated) → uninstall-then-install sequence returned
1155-
/// - A 1.x binary (Available) → None (no reinstall)
1156+
/// - A current 1.x binary (Available) → None (no reinstall)
1157+
/// - A 1.x binary below the floor → install plan returned
11561158
/// - Missing binary (None path) → catalog install commands returned
11571159
#[cfg(unix)]
11581160
#[test]
@@ -1192,10 +1194,10 @@ mod tests {
11921194

11931195
let dir = tempfile::tempdir().unwrap();
11941196
let bin = dir.path().join("codex-acp");
1195-
// Simulate 1.x adapter: outputs version and exits 0
1197+
// Simulate the minimum supported adapter version.
11961198
std::fs::write(
11971199
&bin,
1198-
"#!/bin/sh\necho '@agentclientprotocol/codex-acp 1.1.2'\nexit 0\n",
1200+
"#!/bin/sh\necho '@agentclientprotocol/codex-acp 1.1.7'\nexit 0\n",
11991201
)
12001202
.expect("write script");
12011203
std::fs::set_permissions(&bin, std::fs::Permissions::from_mode(0o755))
@@ -1206,7 +1208,32 @@ mod tests {
12061208

12071209
assert!(
12081210
plan.is_none(),
1209-
"1.x codex adapter must not trigger install plan (no reinstall needed)"
1211+
"current codex adapter must not trigger install plan (no reinstall needed)"
1212+
);
1213+
}
1214+
1215+
#[cfg(unix)]
1216+
#[test]
1217+
fn test_plan_adapter_install_updates_older_1x_codex_binary() {
1218+
use std::os::unix::fs::PermissionsExt;
1219+
1220+
let dir = tempfile::tempdir().unwrap();
1221+
let bin = dir.path().join("codex-acp");
1222+
// A 1.x adapter below MIN_CODEX_ACP_VERSION must still be reinstalled.
1223+
std::fs::write(
1224+
&bin,
1225+
"#!/bin/sh\necho '@agentclientprotocol/codex-acp 1.1.5'\nexit 0\n",
1226+
)
1227+
.expect("write script");
1228+
std::fs::set_permissions(&bin, std::fs::Permissions::from_mode(0o755))
1229+
.expect("chmod script");
1230+
1231+
let install_cmds = &["npm install -g @agentclientprotocol/codex-acp"];
1232+
let plan = plan_adapter_install("codex", Some(&bin), install_cmds, Some("/usr/bin:/bin"));
1233+
1234+
assert!(
1235+
plan.is_some(),
1236+
"older 1.x codex adapter must trigger update plan"
12101237
);
12111238
}
12121239

‎desktop/src-tauri/src/managed_agents/discovery.rs‎

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ pub fn clear_resolve_cache() {
603603
//
604604
// `build_managed_agent_summary` needs to compare the spawn-time adapter
605605
// availability against the *current* availability without triggering a live
606-
// `probe_codex_acp_major_version` subprocess on every poll cycle. This cache
606+
// `probe_codex_acp_version` subprocess on every poll cycle. This cache
607607
// stores the last availability status of the codex-acp binary at its resolved
608608
// path. It is warmed by `discover_acp_runtimes` (which already probes), so
609609
// the badge path reads warm data, and is invalidated by `clear_resolve_cache`
@@ -1163,15 +1163,30 @@ pub(crate) fn classify_runtime(
11631163
}
11641164
}
11651165

1166-
/// Probe the major version of a `codex-acp` binary by running `--version`.
1166+
/// The oldest `codex-acp` version supported by Buzz managed agents.
1167+
///
1168+
/// Older 1.x adapters are detected successfully, but can still bundle a Codex runtime
1169+
/// that does not reliably give `buzz` CLI subprocesses outbound relay access.
1170+
///
1171+
/// Bump policy: raise this only when a newer adapter fixes a defect that breaks managed
1172+
/// agents, and only to a version already published on npm — every user below the floor is
1173+
/// offered a reinstall on their next discovery pass.
1174+
pub(crate) const MIN_CODEX_ACP_VERSION: (u64, u64, u64) = (1, 1, 7);
1175+
1176+
/// Probe the full version of a `codex-acp` binary by running `--version`.
11671177
///
11681178
/// The 1.x adapter (`@agentclientprotocol/codex-acp`) outputs
11691179
/// `@agentclientprotocol/codex-acp <major>.<minor>.<patch>` on stdout and exits 0.
11701180
/// The old 0.16.x adapter (`@zed-industries/codex-acp`) is a Rust binary that does
11711181
/// not recognise `--version` and exits non-zero.
11721182
///
1173-
/// Returns the major version on success, `None` on any failure (non-zero exit,
1174-
/// unparseable output, timeout, or missing binary).
1183+
/// Returns the `(major, minor, patch)` triple on success, `None` on any failure
1184+
/// (non-zero exit, unparseable output, timeout, or missing binary).
1185+
///
1186+
/// The parse is deliberately strict: exactly three numeric dot-separated components.
1187+
/// Partial versions (`1.2`) and prerelease tags (`1.2.0-rc1`) return `None` and so
1188+
/// classify as [`AcpAvailabilityStatus::AdapterOutdated`] — failing closed offers a
1189+
/// reinstall rather than running an adapter whose version cannot be compared.
11751190
///
11761191
/// The probe is bounded by a 5-second deadline. The child is polled with
11771192
/// [`std::process::Child::try_wait`] (the repo's standard deadline pattern) and
@@ -1180,16 +1195,16 @@ pub(crate) fn classify_runtime(
11801195
/// Stdout is redirected to a temporary file rather than a pipe, so forked
11811196
/// descendants cannot hold EOF open. Reads from a regular file return EOF at its
11821197
/// current write position regardless of inherited file descriptors, cross-platform.
1183-
pub(crate) fn probe_codex_acp_major_version(binary_path: &Path) -> Option<u64> {
1184-
probe_codex_acp_major_version_with_path(
1198+
pub(crate) fn probe_codex_acp_version(binary_path: &Path) -> Option<(u64, u64, u64)> {
1199+
probe_codex_acp_version_with_path(
11851200
binary_path,
11861201
crate::managed_agents::readiness::cli_probe::augmented_path().as_deref(),
11871202
)
11881203
}
1189-
pub(crate) fn probe_codex_acp_major_version_with_path(
1204+
pub(crate) fn probe_codex_acp_version_with_path(
11901205
binary_path: &Path,
11911206
augmented_path: Option<&str>,
1192-
) -> Option<u64> {
1207+
) -> Option<(u64, u64, u64)> {
11931208
use std::io::{Read as _, Seek as _, SeekFrom};
11941209
use std::time::{Duration, Instant};
11951210
const VERSION_PROBE_TIMEOUT: Duration = Duration::from_secs(5);
@@ -1245,30 +1260,35 @@ pub(crate) fn probe_codex_acp_major_version_with_path(
12451260
let stdout = String::from_utf8_lossy(&buf);
12461261
// Output format: "<package-name> <major>.<minor>.<patch>"
12471262
let version_str = stdout.split_whitespace().last()?;
1248-
let major_str = version_str.split('.').next()?;
1249-
major_str.parse::<u64>().ok()
1263+
let mut components = version_str.split('.');
1264+
let major = components.next()?.parse::<u64>().ok()?;
1265+
let minor = components.next()?.parse::<u64>().ok()?;
1266+
let patch = components.next()?.parse::<u64>().ok()?;
1267+
if components.next().is_some() {
1268+
return None;
1269+
}
1270+
Some((major, minor, patch))
12501271
}
12511272

12521273
/// Classifies a resolved codex-acp binary path as [`AcpAvailabilityStatus::Available`]
12531274
/// or [`AcpAvailabilityStatus::AdapterOutdated`].
12541275
///
12551276
/// The 0.16.x adapter (`@zed-industries/codex-acp`) does not recognise `--version`
1256-
/// and exits non-zero — that probe failure yields `AdapterOutdated`. The 1.x adapter
1257-
/// (`@agentclientprotocol/codex-acp`) prints its version and exits 0; major ≥ 1
1258-
/// yields `Available`.
1277+
/// and exits non-zero — that probe failure yields `AdapterOutdated`. An adapter is
1278+
/// available only when its version is at least [`MIN_CODEX_ACP_VERSION`].
12591279
///
12601280
/// Used by `discover_acp_runtimes`, `cli_login_requirements`, and
12611281
/// `install_acp_runtime_blocking` so the version-gate logic is not duplicated.
12621282
pub(crate) fn codex_adapter_availability(path: &Path) -> AcpAvailabilityStatus {
1263-
match probe_codex_acp_major_version(path) {
1264-
Some(major) if major >= 1 => AcpAvailabilityStatus::Available,
1283+
match probe_codex_acp_version(path) {
1284+
Some(version) if version >= MIN_CODEX_ACP_VERSION => AcpAvailabilityStatus::Available,
12651285
_ => AcpAvailabilityStatus::AdapterOutdated,
12661286
}
12671287
}
12681288

1269-
/// Returns `true` when the codex-acp binary at `path` is outdated (major version < 1)
1270-
/// or cannot be probed using `augmented_path`. Thin wrapper around
1271-
/// [`codex_adapter_is_outdated_with_path`].
1289+
/// Returns `true` when the codex-acp binary at `path` is below
1290+
/// [`MIN_CODEX_ACP_VERSION`] or cannot be probed using `augmented_path`. Thin wrapper
1291+
/// around [`codex_adapter_is_outdated_with_path`].
12721292
#[cfg(test)]
12731293
pub(crate) fn codex_adapter_is_outdated(path: &Path) -> bool {
12741294
codex_adapter_is_outdated_with_path(
@@ -1277,15 +1297,15 @@ pub(crate) fn codex_adapter_is_outdated(path: &Path) -> bool {
12771297
)
12781298
}
12791299

1280-
/// Returns `true` when the codex-acp binary at `path` is outdated (major version < 1)
1281-
/// or cannot be probed with the supplied PATH.
1300+
/// Returns `true` when the codex-acp binary at `path` is below
1301+
/// [`MIN_CODEX_ACP_VERSION`] or cannot be probed with the supplied PATH.
12821302
pub(crate) fn codex_adapter_is_outdated_with_path(
12831303
path: &Path,
12841304
augmented_path: Option<&str>,
12851305
) -> bool {
12861306
!matches!(
1287-
probe_codex_acp_major_version_with_path(path, augmented_path),
1288-
Some(major) if major >= 1
1307+
probe_codex_acp_version_with_path(path, augmented_path),
1308+
Some(version) if version >= MIN_CODEX_ACP_VERSION
12891309
)
12901310
}
12911311

@@ -1308,9 +1328,8 @@ fn discover_acp_runtime_phase1(runtime: &'static KnownAcpRuntime) -> PartialEntr
13081328
let (mut availability, command, binary_path) =
13091329
classify_runtime(adapter_result, runtime.underlying_cli, underlying_cli_found);
13101330

1311-
// For codex-acp: when the adapter resolves as Available, probe the
1312-
// version. An adapter with major version < 1 is treated as outdated —
1313-
// the CODEX_CONFIG spawn contract requires 1.x.
1331+
// For codex-acp: when the adapter resolves as Available, probe its full
1332+
// version. An adapter below MIN_CODEX_ACP_VERSION is treated as outdated.
13141333
if runtime.id == "codex"
13151334
&& availability == AcpAvailabilityStatus::Available
13161335
&& command.as_deref() == Some("codex-acp")

0 commit comments

Comments
 (0)