Skip to content

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

Go

MUL-6734 fix(daemon): resolve Windows set-path overrides via LookPath (#7623)

leilei3167f9f5e3b81fc4
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 33ae440aba..27e427835f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -670,7 +670,7 @@ jobs:
# explicitly configured path reach the release executable. The same job
# covers the npm shape, where the entry point is a `.cmd` shim that only
# the command interpreter can run.
- run: go test ./internal/daemon -v -run '^(TestCanonicalExecutablePath|TestTrimExtendedLengthPrefix|TestResolveAgentExecutablePathKeeps|TestResolveAgentEntry(FollowsRetargetedInstallerJunction|CanonicalizesRediscoveredJunction|ForLaunchKeepsCmdShimLaunchable|ForLaunchRejectsUnverifiedInitialJunctionTarget|ForLaunchRejectsRediscoveredJunctionWhenFinalPathResolutionFails|DoesNotSharePreRetargetSingleflightResult|ForLaunchFailsWhenJunctionKeepsRetargeting)|TestHandleTaskReportsWindowsCodexProcessStartFailure)' -count=1 -timeout=5m
+ run: go test ./internal/daemon -v -run '^(TestCanonicalExecutablePath|TestTrimExtendedLengthPrefix|TestResolveAgentExecutablePathKeeps|TestResolveAgentExecutablePath_ProfileOverride|TestResolveAgentEntry(FollowsRetargetedInstallerJunction|CanonicalizesRediscoveredJunction|ForLaunchKeepsCmdShimLaunchable|ForLaunchRejectsUnverifiedInitialJunctionTarget|ForLaunchRejectsRediscoveredJunctionWhenFinalPathResolutionFails|DoesNotSharePreRetargetSingleflightResult|ForLaunchFailsWhenJunctionKeepsRetargeting)|TestHandleTaskReportsWindowsCodexProcessStartFailure)' -count=1 -timeout=5m
- name: Build Windows CLI helper entrypoint
working-directory: server
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.go
index b84f3f5f84..2e4818d25b 100644
--- a/server/internal/daemon/daemon.go
+++ b/server/internal/daemon/daemon.go
@@ -276,20 +276,15 @@ var (
// process PATH. Mirrors the detectAgentVersion hook above.
lookPath = exec.LookPath
- // profilePathExecutable reports whether path points at an existing,
- // non-directory file with at least one executable bit set. It is the
- // gate appendProfileRuntimes uses before trusting a per-machine command
- // path override (MUL-3284) — a stale or mistyped override must fall back
- // to the PATH lookup rather than register a runtime that can't launch.
- // Indirected as a package var so tests can assert override preference
- // without staging a real executable on disk.
- profilePathExecutable = func(path string) bool {
- info, err := os.Stat(path)
- if err != nil || info.IsDir() {
- return false
- }
- return info.Mode().Perm()&0o111 != 0
- }
+ // resolveProfileOverridePath is what appendProfileRuntimes uses before
+ // trusting a per-machine command path override (MUL-3284). It must be the
+ // same contract agent launches use — resolveAgentExecutablePath /
+ // exec.LookPath — so Windows PATHEXT completion (.cmd shims, extension-less
+ // pins) and unix exec-bit checks stay in one place. A stale or mistyped
+ // override must fall back to PATH rather than register a runtime that
+ // can't launch. Indirected as a package var so override-preference tests
+ // can decide which paths resolve without staging real files on disk.
+ resolveProfileOverridePath = resolveAgentExecutablePath
)
// workspaceState tracks registered runtimes for a single workspace.
@@ -3088,8 +3083,8 @@ func (d *Daemon) appendProfileRuntimes(ctx context.Context, workspaceID string,
var resolved string
var failureReason string
if override := strings.TrimSpace(d.cfg.ProfileCommandOverrides[profile.ID]); override != "" {
- if profilePathExecutable(override) {
- resolved = override
+ if path, err := resolveProfileOverridePath(override); err == nil {
+ resolved = path
d.logger.Info("custom runtime profile: using per-machine command path override",
"workspace_id", workspaceID, "profile_id", profile.ID, "command_path", resolved)
} else {
diff --git a/server/internal/daemon/profile_path_executable_test.go b/server/internal/daemon/profile_path_executable_test.go
new file mode 100644
index 0000000000..8fccd416ff
--- /dev/null
+++ b/server/internal/daemon/profile_path_executable_test.go
@@ -0,0 +1,88 @@
+package daemon
+
+import (
+ "os"
+ "path/filepath"
+ "runtime"
+ "testing"
+)
+
+// TestResolveAgentExecutablePath_ProfileOverride is the set-path gate
+// regression for MUL-3284 / #7613. appendProfileRuntimes must reuse
+// resolveAgentExecutablePath (exec.LookPath) so Windows PATHEXT completion
+// and unix exec-bit checks match what agent launch already does — including
+// assigning LookPath's return value, not the raw override.
+func TestResolveAgentExecutablePath_ProfileOverride(t *testing.T) {
+ dir := t.TempDir()
+
+ if runtime.GOOS == "windows" {
+ t.Setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD")
+
+ exe := filepath.Join(dir, "tool.exe")
+ if err := os.WriteFile(exe, []byte("MZ"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ got, err := resolveAgentExecutablePath(exe)
+ if err != nil {
+ t.Fatalf("resolveAgentExecutablePath(%q): %v", exe, err)
+ }
+ if got != exe {
+ t.Fatalf("resolved .exe = %q, want %q", got, exe)
+ }
+
+ cmd := filepath.Join(dir, "tool.cmd")
+ if err := os.WriteFile(cmd, []byte("@echo off\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ got, err = resolveAgentExecutablePath(cmd)
+ if err != nil {
+ t.Fatalf("resolveAgentExecutablePath(%q): %v", cmd, err)
+ }
+ if got != cmd {
+ t.Fatalf("resolved .cmd = %q, want %q", got, cmd)
+ }
+
+ // npm-style shim: operator pins C:\tools\openclaw while only
+ // openclaw.cmd exists. LookPath must complete the extension.
+ shimDir := t.TempDir()
+ shimCmd := filepath.Join(shimDir, "openclaw.cmd")
+ if err := os.WriteFile(shimCmd, []byte("@echo off\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ extensionless := filepath.Join(shimDir, "openclaw")
+ got, err = resolveAgentExecutablePath(extensionless)
+ if err != nil {
+ t.Fatalf("resolveAgentExecutablePath(%q): %v", extensionless, err)
+ }
+ if got != shimCmd {
+ t.Fatalf("extension-less override resolved to %q, want %q", got, shimCmd)
+ }
+ // Non-PATHEXT absolute files are not asserted: on Windows,
+ // exec.LookPath accepts an absolute path to any existing file.
+ } else {
+ tool := filepath.Join(dir, "tool")
+ if err := os.WriteFile(tool, []byte("#!/bin/sh\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := resolveAgentExecutablePath(tool); err == nil {
+ t.Fatalf("0644 file should not resolve on unix")
+ }
+ if err := os.Chmod(tool, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ got, err := resolveAgentExecutablePath(tool)
+ if err != nil {
+ t.Fatalf("resolveAgentExecutablePath(%q): %v", tool, err)
+ }
+ if got != tool {
+ t.Fatalf("resolved unix tool = %q, want %q", got, tool)
+ }
+ }
+
+ if _, err := resolveAgentExecutablePath(dir); err == nil {
+ t.Fatalf("directory should not resolve")
+ }
+ if _, err := resolveAgentExecutablePath(filepath.Join(dir, "missing")); err == nil {
+ t.Fatalf("missing path should not resolve")
+ }
+}
diff --git a/server/internal/daemon/runtime_profile_test.go b/server/internal/daemon/runtime_profile_test.go
index 3e832392fa..3ccbfdd196 100644
--- a/server/internal/daemon/runtime_profile_test.go
+++ b/server/internal/daemon/runtime_profile_test.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
+ "os/exec"
"strconv"
"strings"
"testing"
@@ -416,7 +417,7 @@ func TestRegisterRuntimes_PrefersCommandPathOverride(t *testing.T) {
t.Cleanup(stubAgentVersion(t))
// PATH would resolve to a *different* binary; the override must win.
stubLookPath(t, map[string]string{"company-codex": "/usr/bin/company-codex"})
- stubProfilePathExecutable(t, map[string]bool{"/opt/custom/company-codex": true})
+ stubResolveProfileOverridePath(t, map[string]string{"/opt/custom/company-codex": "/opt/custom/company-codex"})
profiles := []RuntimeProfile{{
ID: "prof-1",
@@ -449,8 +450,8 @@ func TestRegisterRuntimes_PrefersCommandPathOverride(t *testing.T) {
func TestRegisterRuntimes_OverrideNotExecutableFallsBackToPath(t *testing.T) {
t.Cleanup(stubAgentVersion(t))
stubLookPath(t, map[string]string{"company-codex": "/usr/bin/company-codex"})
- // Override path reports NOT executable -> must fall back to PATH.
- stubProfilePathExecutable(t, map[string]bool{})
+ // Override path does not resolve -> must fall back to PATH.
+ stubResolveProfileOverridePath(t, map[string]string{})
profiles := []RuntimeProfile{{
ID: "prof-1",
@@ -474,14 +475,20 @@ func TestRegisterRuntimes_OverrideNotExecutableFallsBackToPath(t *testing.T) {
}
}
-// stubProfilePathExecutable swaps the package-level profilePathExecutable
-// indirection so override-preference tests can decide which paths are
-// "executable" without staging real files. An absent path reports false.
-func stubProfilePathExecutable(t *testing.T, executable map[string]bool) {
+// stubResolveProfileOverridePath swaps the package-level
+// resolveProfileOverridePath indirection so override-preference tests can
+// decide which paths resolve without staging real files. An absent path
+// reports exec.ErrNotFound.
+func stubResolveProfileOverridePath(t *testing.T, resolved map[string]string) {
t.Helper()
- orig := profilePathExecutable
- profilePathExecutable = func(path string) bool { return executable[path] }
- t.Cleanup(func() { profilePathExecutable = orig })
+ orig := resolveProfileOverridePath
+ resolveProfileOverridePath = func(path string) (string, error) {
+ if p, ok := resolved[path]; ok {
+ return p, nil
+ }
+ return "", exec.ErrNotFound
+ }
+ t.Cleanup(func() { resolveProfileOverridePath = orig })
}
// bookkeeping that runTask relies on to override the launch path.