Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(agent): probe Hermes version with acp --version (MUL-9132) (#10468)

Bohan Jiangef7cc4a275e3
diff --git a/server/internal/daemon/agents_probe_hermes_unix_test.go b/server/internal/daemon/agents_probe_hermes_unix_test.go
new file mode 100644
index 0000000000..352747a676
--- /dev/null
+++ b/server/internal/daemon/agents_probe_hermes_unix_test.go
@@ -0,0 +1,54 @@
+//go:build !windows
+
+package daemon
+
+import (
+ "context"
+ "fmt"
+ "io"
+ "log/slog"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// MUL-9132: the registration probe must reach Hermes through `acp --version`.
+// The root `hermes --version` checks GitHub for updates; on a slow network that
+// outlasted the probe timeout every round and left a partial git pack behind
+// each time.
+func TestProbeBuiltinRuntimeProbesHermesThroughACP(t *testing.T) {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "hermes")
+ record := filepath.Join(dir, "argv.log")
+ body := fmt.Sprintf(`#!/bin/sh
+printf '%%s\n' "$*" >> %q
+if [ "$1" = "acp" ] && [ "$2" = "--version" ]; then echo 0.22.5; exit 0; fi
+echo "Hermes Agent v0.22.5 (2026.9.24)"
+`, record)
+ if err := os.WriteFile(path, []byte(body), 0o755); err != nil {
+ t.Fatalf("write fake hermes: %v", err)
+ }
+
+ d := &Daemon{
+ logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
+ agentVersions: map[string]string{},
+ }
+ version, reason, verdict := d.probeBuiltinRuntime(context.Background(), "hermes",
+ AgentEntry{Path: path, Command: "hermes"})
+ if verdict != builtinProbeOK {
+ t.Fatalf("verdict = %v (reason %q), want OK", verdict, reason)
+ }
+ if version != "0.22.5" {
+ t.Fatalf("version = %q, want 0.22.5", version)
+ }
+ data, err := os.ReadFile(record)
+ if err != nil {
+ t.Fatalf("read argv log: %v", err)
+ }
+ for _, line := range strings.Split(strings.TrimRight(string(data), "\n"), "\n") {
+ if line != "acp --version" {
+ t.Fatalf("hermes was invoked as %q; every registration probe must be `acp --version`", line)
+ }
+ }
+}
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.go
index faaf810287..420e8b27d3 100644
--- a/server/internal/daemon/daemon.go
+++ b/server/internal/daemon/daemon.go
@@ -1230,7 +1230,7 @@ func (d *Daemon) adoptAgentPath(ctx context.Context, provider, command, newPath,
// older or broken install must not be launched under the daemon's stale
// version policy, and must not slip past the minimum-version gate that the
// registration path applies (MUL-4486 review).
- version, err := detectAgentVersion(ctx, agent.Command{Path: newPath})
+ version, err := detectAgentVersion(ctx, agent.Command{Path: newPath}.ForVersionProbe(provider))
if err != nil {
d.logger.Warn("re-resolved agent executable failed version detection; keeping pinned path",
"provider", provider, "command", command, "new_path", newPath, "error", err)
@@ -2619,7 +2619,7 @@ probeLoop:
"name", name, "version", heal.rejected.Detected, "error", heal.rejected.Error())
return heal.rejected.Detected, heal.rejected.Error(), builtinProbeBelowMinimum
}
- version, err := detectAgentVersion(ctx, agent.Command{Path: resolved.Path})
+ version, err := detectAgentVersion(ctx, agent.Command{Path: resolved.Path}.ForVersionProbe(name))
if err != nil {
lastErr = err
if time.Since(startedAt) >= runtimeVersionProbeRetryWindow {
@@ -3193,7 +3193,7 @@ func (d *Daemon) appendProfileRuntimes(ctx context.Context, workspaceID string,
// wrapper's, and only the former means anything to the min-version
// gate (GH #7046).
version, verErr := detectAgentVersion(ctx, agent.NewCommand(resolved,
- agent.FilterLaunchPrefix(runtimeType, profile.FixedArgs, d.logger)))
+ agent.FilterLaunchPrefix(runtimeType, profile.FixedArgs, d.logger)).ForVersionProbe(runtimeType))
if verErr != nil {
d.logger.Debug("custom runtime profile: version probe failed (registering with empty version)",
"workspace_id", workspaceID, "profile_id", profile.ID, "path", resolved, "error", verErr)
diff --git a/server/pkg/agent/claude.go b/server/pkg/agent/claude.go
index d09e863a2d..f43d3071df 100644
--- a/server/pkg/agent/claude.go
+++ b/server/pkg/agent/claude.go
@@ -1591,14 +1591,64 @@ func detectCLIVersion(ctx context.Context, runtimeCmd Command) (string, error) {
// still applied (MUL-6260). Desktop ZCode ships as a Node .cjs/.mjs bundle;
// those must go through chooseZcodeInvocation (node + script) the same way
// Execute does, with a clear error when node is missing from PATH.
- var cmd *exec.Cmd
if isNodeScriptPath(runtimeCmd.Path) {
if err := requireNodeForZcodeScript(runtimeCmd.Path); err != nil {
return "", err
}
- cmd, _, _ = runtimeCmd.execVia(ctx, chooseZcodeInvocation, runtimeCmd.Path, []string{"--version"}, runtimeCmd.logger)
+ }
+
+ // A provider-specific probe (see Command.ForVersionProbe) runs first. A
+ // build too old to know it rejects the arguments outright, and only that
+ // case falls back to `--version`: a probe that hung or could not start would
+ // fail the same way again, and here it would also spend the remaining
+ // budget on the side effects the provider-specific probe exists to avoid.
+ if len(runtimeCmd.versionArgs) > 0 {
+ version, err := runVersionProbe(ctx, runtimeCmd, runtimeCmd.versionArgs)
+ if err == nil {
+ return version, nil
+ }
+ if !versionProbeRejectedArgs(ctx, err) {
+ return "", fmt.Errorf("detect version for %s: %w", runtimeCmd, ExplainExecError(err))
+ }
+ if runtimeCmd.logger != nil {
+ runtimeCmd.logger.Debug("agent: CLI rejected its version probe; falling back to --version",
+ "command", runtimeCmd.String(), "probe", strings.Join(runtimeCmd.versionArgs, " "), "err", err)
+ }
+ }
+
+ version, err := runVersionProbe(ctx, runtimeCmd, []string{"--version"})
+ if err != nil {
+ // One provider-agnostic boundary for probes: DetectVersion routes every
+ // provider through here, so an ENOEXEC diagnosis added at this point
+ // reaches the reason the daemon reports for a skipped runtime
+ // (MUL-6164).
+ return "", fmt.Errorf("detect version for %s: %w", runtimeCmd, ExplainExecError(err))
+ }
+ return version, nil
+}
+
+// versionProbeRejectedArgs reports whether a failed provider-specific version
+// probe is the CLI refusing its arguments: the process ran and exited non-zero
+// on its own, before the deadline. A kill on timeout also surfaces as an
+// *exec.ExitError, with exit code -1, which is why both the code and the
+// context are checked.
+func versionProbeRejectedArgs(ctx context.Context, err error) bool {
+ if ctx.Err() != nil {
+ return false
+ }
+ var exitErr *exec.ExitError
+ return errors.As(err, &exitErr) && exitErr.ExitCode() > 0
+}
+
+// runVersionProbe runs one `<cli> <args>` version probe and returns the
+// recognised version line. The error is unwrapped; detectCLIVersion adds the
+// command and the exec diagnosis.
+func runVersionProbe(ctx context.Context, runtimeCmd Command, args []string) (string, error) {
+ var cmd *exec.Cmd
+ if isNodeScriptPath(runtimeCmd.Path) {
+ cmd, _, _ = runtimeCmd.execVia(ctx, chooseZcodeInvocation, runtimeCmd.Path, args, runtimeCmd.logger)
} else {
- cmd = runtimeCmd.exec(ctx, "--version")
+ cmd = runtimeCmd.exec(ctx, args...)
}
hideAgentWindow(cmd)
cmd.WaitDelay = probeWaitDelay
@@ -1620,14 +1670,10 @@ func detectCLIVersion(ctx context.Context, runtimeCmd Command) (string, error) {
// to empty would be a regression (#2516). It is only unusable as
// evidence that a *bounded, incomplete* read already contains the
// answer.
- if salvaged := salvageProbeAnswer(runtimeCmd, "--version", recognised, err); salvaged {
+ if salvageProbeAnswer(runtimeCmd, strings.Join(args, " "), recognised, err) {
return version, nil
}
- // One provider-agnostic boundary for probes: DetectVersion routes every
- // provider through here, so an ENOEXEC diagnosis added at this point
- // reaches the reason the daemon reports for a skipped runtime
- // (MUL-6164).
- return "", fmt.Errorf("detect version for %s: %w", runtimeCmd, ExplainExecError(err))
+ return "", err
}
return version, nil
}
diff --git a/server/pkg/agent/hermes.go b/server/pkg/agent/hermes.go
index c7d55cd2cb..7d619bfb53 100644
--- a/server/pkg/agent/hermes.go
+++ b/server/pkg/agent/hermes.go
@@ -143,6 +143,13 @@ func hermesInsideMcpAdd(args []string, index int) bool {
// cannot reason about a profile selection without it.
const hermesACPSubcommand = "acp"
+// hermesVersionProbeArgs is the version probe Command.ForVersionProbe selects
+// for Hermes: the ACP entry point's own `--version`, which reads the installed
+// version locally, instead of the root `--version`, which also checks GitHub
+// for updates. Supported since Hermes v0.14.0; older builds reject it with an
+// argparse usage error and detectCLIVersion falls back to `--version`.
+var hermesVersionProbeArgs = []string{hermesACPSubcommand, "--version"}
+
// hermesACPSubcommandFlags are the options Hermes' `acp` subparser declares
// (hermes_cli/subcommands/acp.py, plus argparse's own -h/--help), all
// value-less. Argparse accepts them only after the subcommand, so they keep
diff --git a/server/pkg/agent/launch.go b/server/pkg/agent/launch.go
index 903fc70332..b9cd17d0ca 100644
--- a/server/pkg/agent/launch.go
+++ b/server/pkg/agent/launch.go
@@ -85,6 +85,29 @@ type Command struct {
// probeDir isolates discovery from the daemon's inherited directory.
// Task commands leave it empty and keep their execution directory.
probeDir string
+ // versionArgs replaces `--version` in detectCLIVersion for a provider
+ // whose plain `--version` is not a cheap local read. Empty means
+ // `--version`. Set only through ForVersionProbe.
+ versionArgs []string
+}
+
+// ForVersionProbe returns c set up to probe provider's version the way that
+// provider can answer it without side effects. Most CLIs answer `--version`
+// locally; for them this returns c unchanged.
+//
+// Hermes is the exception. `hermes --version` runs a synchronous update check
+// that talks to GitHub (`git ls-remote`, and a `git fetch` on older installs).
+// On a slow network that outlasts detectVersionTimeout, the kill leaves a
+// partial `tmp_pack_*` in the Hermes checkout on every registration round, and
+// because Hermes caches the update result only after the check finishes, the
+// next round fetches again (MUL-9132). `hermes acp --version` prints the same
+// version from the local install stamp or `git rev-parse` and never checks for
+// updates. It is also the entry point the backend launches.
+func (c Command) ForVersionProbe(provider string) Command {
+ if provider == "hermes" {
+ c.versionArgs = hermesVersionProbeArgs
+ }
+ return c
}
// NewCommand builds a Command from a resolved executable path and a launch
diff --git a/server/pkg/agent/version_probe_unix_test.go b/server/pkg/agent/version_probe_unix_test.go
new file mode 100644
index 0000000000..8d11a1323b
--- /dev/null
+++ b/server/pkg/agent/version_probe_unix_test.go
@@ -0,0 +1,133 @@
+//go:build !windows
+
+package agent
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+// fakeHermesForVersionProbe writes a fake hermes that appends each argv it is
+// called with to a log, one line per invocation, and answers with body. It
+// returns the script path and the log path.
+func fakeHermesForVersionProbe(t *testing.T, body string) (string, string) {
+ t.Helper()
+ dir := t.TempDir()
+ script := filepath.Join(dir, "hermes")
+ record := filepath.Join(dir, "argv.log")
+ content := fmt.Sprintf("#!/bin/sh\nprintf '%%s\\n' \"$*\" >> %q\n%s\n", record, body)
+ if err := os.WriteFile(script, []byte(content), 0o755); err != nil {
+ t.Fatalf("write fake hermes: %v", err)
+ }
+ return script, record
+}
+
+func readProbeInvocations(t *testing.T, record string) []string {
+ t.Helper()
+ data, err := os.ReadFile(record)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return nil
+ }
+ t.Fatalf("read argv log: %v", err)
+ }
+ return strings.Split(strings.TrimRight(string(data), "\n"), "\n")
+}
+
+// MUL-9132: `hermes --version` runs an update check against GitHub, so the
+// Hermes probe must go through `acp --version`, and a Hermes that answers it
+// must never see the root `--version`.
+func TestDetectVersionHermesUsesACPVersion(t *testing.T) {
+ // The root --version "hangs" here, standing in for the slow network fetch:
+ // reaching it would fail the test on the timeout as well as the argv check.
+ script, record := fakeHermesForVersionProbe(t, `
+if [ "$1" = "acp" ] && [ "$2" = "--version" ]; then echo 0.22.5; exit 0; fi
+if [ "$1" = "--version" ]; then exec sleep 30; fi
+exit 2`)
+ orig := detectVersionTimeout
+ detectVersionTimeout = 5 * time.Second
+ t.Cleanup(func() { detectVersionTimeout = orig })
+
+ version, err := DetectVersion(context.Background(), Command{Path: script}.ForVersionProbe("hermes"))
+ if err != nil {
+ t.Fatalf("DetectVersion: %v", err)
+ }
+ if version != "0.22.5" {
+ t.Fatalf("version = %q, want 0.22.5", version)
+ }
+ if got, want := readProbeInvocations(t, record), []string{"acp --version"}; strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Fatalf("invocations = %q, want %q", got, want)
+ }
+}
+
+// A custom runtime's fixed_args are Hermes global flags (`-p <profile>`), which
+// argparse accepts only before the subcommand — the same position the backend
+// launches them in.
+func TestDetectVersionHermesKeepsLaunchPrefixBeforeACP(t *testing.T) {
+ script, record := fakeHermesForVersionProbe(t, `echo 0.22.5`)
+
+ cmd := NewCommand(script, []string{"-p", "work"}).ForVersionProbe("hermes")
+ if _, err := DetectVersion(context.Background(), cmd); err != nil {
+ t.Fatalf("DetectVersion: %v", err)
+ }
+ if got, want := readProbeInvocations(t, record), []string{"-p work acp --version"}; strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Fatalf("invocations = %q, want %q", got, want)
+ }
+}
+
+// A Hermes older than v0.14.0 has no `acp --version`; argparse rejects it with
+// exit 2 and the probe falls back to the root `--version`.
+func TestDetectVersionHermesFallsBackWhenACPVersionIsRejected(t *testing.T) {
+ script, record := fakeHermesForVersionProbe(t, `
+if [ "$1" = "--version" ]; then echo "Hermes Agent v0.13.0 (2026.5.7)"; exit 0; fi
+echo "hermes: error: unrecognized arguments: --version" >&2
+exit 2`)
+
+ version, err := DetectVersion(context.Background(), Command{Path: script}.ForVersionProbe("hermes"))
+ if err != nil {
+ t.Fatalf("DetectVersion: %v", err)
+ }
+ if version != "Hermes Agent v0.13.0 (2026.5.7)" {
+ t.Fatalf("version = %q, want the root --version line", version)
+ }
+ if got, want := readProbeInvocations(t, record), []string{"acp --version", "--version"}; strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Fatalf("invocations = %q, want %q", got, want)
+ }
+}
+
+// A hang is not a rejection: falling back would spend the rest of the budget on
+// the root `--version` and its network check, the thing this probe avoids.
+func TestDetectVersionHermesDoesNotFallBackOnTimeout(t *testing.T) {
+ script, record := fakeHermesForVersionProbe(t, `exec sleep 30`)
+ orig := detectVersionTimeout
+ detectVersionTimeout = time.Second
+ t.Cleanup(func() { detectVersionTimeout = orig })
+
+ if _, err := DetectVersion(context.Background(), Command{Path: script}.ForVersionProbe("hermes")); err == nil {
+ t.Fatal("expected an error from a hanging probe, got nil")
+ }
+ // The kill can land before a cold shell writes its log line, so assert only
+ // that the root --version never ran.
+ for _, got := range readProbeInvocations(t, record) {
+ if got != "acp --version" {
+ t.Fatalf("hermes was invoked as %q after the probe timed out; want no fallback", got)
+ }
+ }
+}
+
+// Every other provider keeps the plain `--version` probe.
+func TestDetectVersionOtherProvidersKeepRootVersion(t *testing.T) {
+ script, record := fakeHermesForVersionProbe(t, `echo 1.2.3`)
+
+ if _, err := DetectVersion(context.Background(), Command{Path: script}.ForVersionProbe("claude")); err != nil {
+ t.Fatalf("DetectVersion: %v", err)
+ }
+ if got, want := readProbeInvocations(t, record), []string{"--version"}; strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Fatalf("invocations = %q, want %q", got, want)
+ }
+}