Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(cli): retry a briefly busy OpenCode probe

AkitaOnRails79d7b4b2dd05
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d5d2de36..1f0b3b4e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -391,6 +391,10 @@ version in [`docs/changelog/`](docs/changelog/):
### Fixed
+- Retried an OpenCode version probe briefly when the executable is temporarily
+ busy, covering both an updater replacing the binary and a just-written
+ launcher under parallel load instead of failing the managed launch.
+
- Fixed live response capture after transcript gaps. Bounded batches now resume
from durable enqueue checkpoints, including across hook processes and
transcript read windows (#1830).
diff --git a/crates/ai-memory-cli/src/commands/opencode_dialect.rs b/crates/ai-memory-cli/src/commands/opencode_dialect.rs
index 6ed6d4c9..9ff20005 100644
--- a/crates/ai-memory-cli/src/commands/opencode_dialect.rs
+++ b/crates/ai-memory-cli/src/commands/opencode_dialect.rs
@@ -67,12 +67,12 @@ fn resolve_generic_with_timeout(
})?;
let mut command = Command::new(&resolved);
env.apply_to_std(&mut command);
- let mut child = command
+ command
.arg("--version")
.stdin(Stdio::null())
.stdout(Stdio::piped())
- .stderr(Stdio::piped())
- .spawn()
+ .stderr(Stdio::piped());
+ let mut child = spawn_retrying_busy(&mut command)
.with_context(|| format!("probing OpenCode executable {}", resolved.display()))?;
let stdout = read_bounded(child.stdout.take());
let stderr = read_bounded(child.stderr.take());
@@ -131,6 +131,24 @@ fn resolve_generic_with_timeout(
})
}
+/// Retry a probe while an updater or a just-finished write still owns the
+/// executable. The total 80 ms retry window stays inside the probe timeout.
+fn spawn_retrying_busy(command: &mut Command) -> std::io::Result<std::process::Child> {
+ const ATTEMPTS: u32 = 5;
+ let mut attempt = 1;
+ loop {
+ match command.spawn() {
+ Err(error)
+ if error.kind() == std::io::ErrorKind::ExecutableFileBusy && attempt < ATTEMPTS =>
+ {
+ attempt += 1;
+ thread::sleep(Duration::from_millis(20));
+ }
+ result => return result,
+ }
+ }
+}
+
fn timeout_error(program: &std::path::Path, timeout: Duration) -> anyhow::Error {
anyhow!(
"OpenCode version probe timed out after {} seconds for {}; run `{} --version` and verify it exits promptly",
@@ -259,6 +277,30 @@ mod tests {
assert_eq!(resolved.executable, executable);
}
+ #[cfg(target_os = "linux")]
+ #[test]
+ fn version_probe_retries_a_briefly_busy_executable() {
+ use std::fs::OpenOptions;
+
+ let temp = fake_version("opencode v2.0.23");
+ let executable = temp.path().join("opencode");
+ let writer = OpenOptions::new().write(true).open(&executable).unwrap();
+ let release = thread::spawn(move || {
+ thread::sleep(Duration::from_millis(30));
+ drop(writer);
+ });
+
+ let resolved = resolve_generic_with_timeout(
+ Some(executable.as_os_str()),
+ &EffectiveChildEnv::from_runtime(&crate::config::RuntimeEnv::default()),
+ Duration::from_secs(1),
+ )
+ .unwrap();
+ release.join().unwrap();
+
+ assert_eq!(resolved.dialect, OpenCodeDialect::V2);
+ }
+
#[cfg(unix)]
#[test]
fn version_probe_timeout_fails_actionably() {