Skip to content

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

Go

fix: gate worktree mode on a declared capability, not a version string (MUL-5707) (#6904)

Bohan Jiang063698f57122
diff --git a/packages/core/runtimes/cli-version.test.ts b/packages/core/runtimes/cli-version.test.ts
index bb7a0139a4..855212e62a 100644
--- a/packages/core/runtimes/cli-version.test.ts
+++ b/packages/core/runtimes/cli-version.test.ts
@@ -6,6 +6,8 @@ import {
handoffSupported,
MIN_CHAT_PROJECT_CONTEXT_CLI_VERSION,
MIN_HANDOFF_CLI_VERSION,
+ runtimeSupportsLocalWorktree,
+ daemonSupportsLocalWorktree,
} from "./cli-version";
describe("checkQuickCreateCliVersion", () => {
@@ -91,3 +93,91 @@ describe("chatProjectContextSupported", () => {
expect(chatProjectContextSupported("v0.1.0-235-gdaf0e935-dirty")).toBe(true);
});
});
+
+describe("runtimeSupportsLocalWorktree", () => {
+ it("reads the advertised capability", () => {
+ expect(
+ runtimeSupportsLocalWorktree({ capabilities: ["skill-bundles-v1", "local-worktree-v1"] }),
+ ).toBe(true);
+ expect(runtimeSupportsLocalWorktree({ capabilities: ["skill-bundles-v1"] })).toBe(false);
+ });
+
+ // The whole reason this replaced a version check: a dev-built daemon reports a
+ // git-describe string that the version floor exempts, so a binary with no
+ // worktree implementation passed and two tasks ran in the user's own
+ // directory (MUL-5707). The capability must ignore versions entirely.
+ it("ignores the version string in both directions", () => {
+ expect(runtimeSupportsLocalWorktree({ cli_version: "v0.4.21-24-gcd3c0bb89" })).toBe(false);
+ expect(runtimeSupportsLocalWorktree({ cli_version: "9.9.9" })).toBe(false);
+ expect(
+ runtimeSupportsLocalWorktree({ cli_version: "0.0.1", capabilities: ["local-worktree-v1"] }),
+ ).toBe(true);
+ });
+
+ it("fails closed on anything it cannot read", () => {
+ for (const metadata of [undefined, null, {}, "nope", 42, { capabilities: "local-worktree-v1" }]) {
+ expect(runtimeSupportsLocalWorktree(metadata)).toBe(false);
+ }
+ });
+});
+
+describe("daemonSupportsLocalWorktree", () => {
+ const capable = { capabilities: ["local-worktree-v1"] };
+ const incapable = { cli_version: "9.9.9" };
+
+ // Deregistering only marks a runtime offline; its metadata survives and the
+ // list endpoint still returns it. An any-row match would therefore keep
+ // vouching for a machine that has since downgraded, so the UI would offer a
+ // mode the server refuses at claim time.
+ it("ignores a stale capable row once a newer row lacks the capability", () => {
+ expect(
+ daemonSupportsLocalWorktree(
+ [
+ { daemon_id: "d1", last_seen_at: "2026-08-01T00:00:00Z", metadata: capable },
+ { daemon_id: "d1", last_seen_at: "2026-08-13T00:00:00Z", metadata: incapable },
+ ],
+ "d1",
+ ),
+ ).toBe(false);
+ });
+
+ it("recognises an upgrade: newest row advertises it", () => {
+ expect(
+ daemonSupportsLocalWorktree(
+ [
+ { daemon_id: "d1", last_seen_at: "2026-08-01T00:00:00Z", metadata: incapable },
+ { daemon_id: "d1", last_seen_at: "2026-08-13T00:00:00Z", metadata: capable },
+ ],
+ "d1",
+ ),
+ ).toBe(true);
+ });
+
+ it("does not depend on array order", () => {
+ const rows = [
+ { daemon_id: "d1", last_seen_at: "2026-08-13T00:00:00Z", metadata: incapable },
+ { daemon_id: "d1", last_seen_at: "2026-08-01T00:00:00Z", metadata: capable },
+ ];
+ expect(daemonSupportsLocalWorktree(rows, "d1")).toBe(false);
+ expect(daemonSupportsLocalWorktree([...rows].reverse(), "d1")).toBe(false);
+ });
+
+ it("a row that never reported loses to one that did", () => {
+ expect(
+ daemonSupportsLocalWorktree(
+ [
+ { daemon_id: "d1", last_seen_at: null, metadata: capable },
+ { daemon_id: "d1", last_seen_at: "2026-08-13T00:00:00Z", metadata: incapable },
+ ],
+ "d1",
+ ),
+ ).toBe(false);
+ });
+
+ it("ignores other daemons, and fails closed with no rows or no id", () => {
+ const other = [{ daemon_id: "d2", last_seen_at: "2026-08-13T00:00:00Z", metadata: capable }];
+ expect(daemonSupportsLocalWorktree(other, "d1")).toBe(false);
+ expect(daemonSupportsLocalWorktree([], "d1")).toBe(false);
+ expect(daemonSupportsLocalWorktree(other, null)).toBe(false);
+ });
+});
diff --git a/packages/core/runtimes/cli-version.ts b/packages/core/runtimes/cli-version.ts
index 456a06d5f9..6e6b9d90c8 100644
--- a/packages/core/runtimes/cli-version.ts
+++ b/packages/core/runtimes/cli-version.ts
@@ -168,3 +168,67 @@ export const MIN_LOCAL_WORKTREE_CLI_VERSION = "0.4.24";
export function localWorktreeSupported(detected: string | undefined | null): boolean {
return meetsMinCliVersion(detected, MIN_LOCAL_WORKTREE_CLI_VERSION);
}
+
+/**
+ * Capability a daemon advertises when it implements worktree mode for
+ * local_directory resources. Mirrors `DaemonCapabilityLocalWorktreeV1` in
+ * `server/pkg/protocol/messages.go`.
+ */
+export const LOCAL_WORKTREE_CAPABILITY = "local-worktree-v1";
+
+/**
+ * Whether a runtime advertised worktree support at registration.
+ *
+ * This replaces a version comparison on purpose. A daemon without the
+ * implementation does not merely lose concurrency — it ignores `execution_mode`
+ * and edits the user's working copy, which is what the mode exists to prevent.
+ * Version strings could not answer that: a dev build reports a git-describe
+ * string that `meetsMinCliVersion` deliberately exempts, so a daemon with no
+ * worktree code at all passed the check (MUL-5707).
+ *
+ * Absent metadata (an older daemon that never sent the header) is `false` —
+ * this must fail closed, and the server enforces the same thing at claim time.
+ */
+export function runtimeSupportsLocalWorktree(metadata: unknown): boolean {
+ if (!metadata || typeof metadata !== "object") return false;
+ const caps = (metadata as { capabilities?: unknown }).capabilities;
+ return Array.isArray(caps) && caps.includes(LOCAL_WORKTREE_CAPABILITY);
+}
+
+/** Minimal runtime shape this module needs; keeps callers from importing types. */
+type RuntimeCapabilityRow = {
+ daemon_id?: string | null;
+ last_seen_at?: string | null;
+ metadata?: unknown;
+};
+
+/**
+ * Whether the machine behind `daemonId` currently runs a daemon that supports
+ * worktree mode, judged by its MOST RECENTLY SEEN runtime row.
+ *
+ * Deliberately not "any row advertised it". Deregistering a runtime only marks
+ * the row offline — its metadata survives — so a machine that once ran a
+ * capable daemon and then downgraded still has an old capable row beside the
+ * fresh incapable one, and an any-match would answer yes forever. The server's
+ * `daemonAdvertisesWorktree` uses the same newest-wins rule; the two must agree
+ * or the UI offers a mode the API will refuse.
+ */
+export function daemonSupportsLocalWorktree(
+ runtimes: RuntimeCapabilityRow[],
+ daemonId: string | null | undefined,
+): boolean {
+ if (!daemonId) return false;
+ let newest: RuntimeCapabilityRow | undefined;
+ for (const rt of runtimes) {
+ if (rt.daemon_id !== daemonId) continue;
+ if (!newest) {
+ newest = rt;
+ continue;
+ }
+ // A row that never reported sorts oldest, so a live row always wins.
+ const candidateSeen = rt.last_seen_at ?? "";
+ const currentSeen = newest.last_seen_at ?? "";
+ if (candidateSeen > currentSeen) newest = rt;
+ }
+ return newest ? runtimeSupportsLocalWorktree(newest.metadata) : false;
+}
diff --git a/packages/views/modals/create-project-local-mode.test.tsx b/packages/views/modals/create-project-local-mode.test.tsx
index 1da32687a8..f4c3139406 100644
--- a/packages/views/modals/create-project-local-mode.test.tsx
+++ b/packages/views/modals/create-project-local-mode.test.tsx
@@ -9,6 +9,9 @@ import { renderWithI18n } from "../test/i18n";
// Runtime list drives the worktree version gate. Each test sets the reported
// CLI version before rendering.
let runtimeCliVersion = "9.9.9";
+// Whether the fake runtime advertises worktree support. This — not the version
+// string — is what the gate reads now (MUL-5707).
+let runtimeAdvertisesWorktree = true;
// What the desktop validator reports for the picked folder.
let pickedIsGitRepo: boolean | undefined = true;
@@ -34,7 +37,15 @@ vi.mock("@tanstack/react-query", () => ({
const key = options?.queryKey?.[0];
if (key === "members" || key === "agents") return { data: [] };
return {
- data: [{ daemon_id: "daemon-1", metadata: { cli_version: runtimeCliVersion } }],
+ data: [
+ {
+ daemon_id: "daemon-1",
+ metadata: {
+ cli_version: runtimeCliVersion,
+ ...(runtimeAdvertisesWorktree ? { capabilities: ["local-worktree-v1"] } : {}),
+ },
+ },
+ ],
};
},
// runtimeListOptions builds its descriptor with this; the mocked useQuery
@@ -151,6 +162,7 @@ describe("CreateProjectModal — local directory execution mode", () => {
beforeEach(() => {
createProjectMock.mockClear();
runtimeCliVersion = "9.9.9";
+ runtimeAdvertisesWorktree = true;
pickedIsGitRepo = true;
});
@@ -183,8 +195,8 @@ describe("CreateProjectModal — local directory execution mode", () => {
// A runtime that cannot run the mode must not be preselected into it, or the
// create call would be rejected by the server's version gate.
- it("preselects direct when the daemon is too old, even for a git repository", async () => {
- runtimeCliVersion = "0.1.0";
+ it("preselects direct when the daemon does not support it, even for a git repository", async () => {
+ runtimeAdvertisesWorktree = false;
const user = userEvent.setup();
renderWithI18n(<CreateProjectModal onClose={vi.fn()} />);
@@ -242,8 +254,8 @@ describe("CreateProjectModal — local directory execution mode", () => {
// The server refuses to save a worktree resource below the version floor, and
// here that rejection would fail the whole project creation — so the option
// has to be blocked before submit, not after.
- it("blocks parallel mode when the daemon is too old", async () => {
- runtimeCliVersion = "0.1.0";
+ it("blocks parallel mode when the daemon does not support it", async () => {
+ runtimeAdvertisesWorktree = false;
const user = userEvent.setup();
renderWithI18n(<CreateProjectModal onClose={vi.fn()} />);
diff --git a/packages/views/modals/create-project.tsx b/packages/views/modals/create-project.tsx
index 39a10602e1..422eff4872 100644
--- a/packages/views/modals/create-project.tsx
+++ b/packages/views/modals/create-project.tsx
@@ -69,7 +69,7 @@ import {
import { useLocalDaemonStatus } from "../platform/use-local-daemon-status";
import {
MIN_LOCAL_WORKTREE_CLI_VERSION,
- localWorktreeSupported,
+ daemonSupportsLocalWorktree,
readRuntimeCliVersion,
runtimeListOptions,
} from "@multica/core/runtimes";
@@ -213,10 +213,17 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }) {
.map((rt) => readRuntimeCliVersion(rt.metadata))
.find((v) => v && v.length > 0) ?? "")
: "";
+ // Capability, not version: a dev-built daemon reports a git-describe string
+ // that the version floor exempts, so the version check passed for a binary
+ // with no worktree implementation (MUL-5707).
+ const localDaemonSupportsWorktree = daemonSupportsLocalWorktree(
+ runtimes,
+ daemonStatus.daemonId,
+ );
const worktreeUnavailableReason =
localIsGitRepo === false
? ("not_git" as const)
- : !localWorktreeSupported(localDaemonCliVersion)
+ : !localDaemonSupportsWorktree
? ("daemon_outdated" as const)
: undefined;
// Preselection, not a default behavior change: when the folder is a git repo
diff --git a/packages/views/projects/components/project-resources-section.tsx b/packages/views/projects/components/project-resources-section.tsx
index 80d34ff773..b37d989e4f 100644
--- a/packages/views/projects/components/project-resources-section.tsx
+++ b/packages/views/projects/components/project-resources-section.tsx
@@ -29,7 +29,7 @@ import type {
} from "@multica/core/types";
import {
MIN_LOCAL_WORKTREE_CLI_VERSION,
- localWorktreeSupported,
+ daemonSupportsLocalWorktree,
readRuntimeCliVersion,
runtimeListOptions,
} from "@multica/core/runtimes";
@@ -140,6 +140,11 @@ export function ProjectResourcesSection({ projectId }: { projectId: string }) {
// be changed from the web app or from a different device. Using the local
// daemon here would report "too old" for every resource whenever the viewer
// is not on that machine.
+ // Capability, not version, and judged by the daemon's newest runtime row —
+ // see daemonSupportsLocalWorktree for why an any-match would keep saying yes
+ // after a downgrade.
+ const daemonSupportsWorktree = (daemonId: string | null): boolean =>
+ daemonSupportsLocalWorktree(runtimes, daemonId);
const cliVersionForDaemon = (daemonId: string | null): string => {
if (!daemonId) return "";
return (
@@ -244,7 +249,7 @@ export function ProjectResourcesSection({ projectId }: { projectId: string }) {
// user still confirms, and existing resources keep whatever they have.
mode:
validation.is_git_repo === true &&
- localWorktreeSupported(cliVersionForDaemon(localDaemonId))
+ daemonSupportsWorktree(localDaemonId)
? "worktree"
: "in_place",
isGitRepo: validation.is_git_repo,
@@ -531,7 +536,7 @@ export function ProjectResourcesSection({ projectId }: { projectId: string }) {
value={modeDialog.mode}
unavailableReason={worktreeUnavailableReason(
modeDialog.isGitRepo,
- localWorktreeSupported(cliVersionForDaemon(modeDialog.daemonId)),
+ daemonSupportsWorktree(modeDialog.daemonId),
)}
currentVersion={cliVersionForDaemon(modeDialog.daemonId)}
minVersion={MIN_LOCAL_WORKTREE_CLI_VERSION}
diff --git a/server/internal/daemon/client.go b/server/internal/daemon/client.go
index 8f8334907a..df5229f546 100644
--- a/server/internal/daemon/client.go
+++ b/server/internal/daemon/client.go
@@ -189,6 +189,7 @@ func daemonClientCapabilities() string {
protocol.DaemonCapabilityCoalescedCommentsV1,
protocol.DaemonCapabilityExecutionManifestV1,
protocol.DaemonCapabilityAgentSkillV1,
+ protocol.DaemonCapabilityLocalWorktreeV1,
protocol.DaemonCapabilityRPCV1,
}, ",")
}
diff --git a/server/internal/daemon/client_test.go b/server/internal/daemon/client_test.go
index 7d2c8b2389..1dd5957212 100644
--- a/server/internal/daemon/client_test.go
+++ b/server/internal/daemon/client_test.go
@@ -36,6 +36,11 @@ func TestClient_IdentityHeaders_PostJSON(t *testing.T) {
for _, want := range []string{
protocol.DaemonCapabilitySkillBundlesV1,
protocol.DaemonCapabilityCoalescedCommentsV1,
+ // The worktree gate is decided entirely from this header: if the
+ // daemon stops advertising it, every worktree task on this machine
+ // is cancelled with an upgrade prompt (MUL-5707). Pin it here so
+ // dropping it from the list can never be a silent change.
+ protocol.DaemonCapabilityLocalWorktreeV1,
} {
if !capabilities[want] {
t.Errorf("X-Client-Capabilities missing %q: %v", want, capabilities)
diff --git a/server/internal/handler/daemon.go b/server/internal/handler/daemon.go
index 810cc3b6a5..e87c732627 100644
--- a/server/internal/handler/daemon.go
+++ b/server/internal/handler/daemon.go
@@ -27,7 +27,6 @@ import (
"github.com/multica-ai/multica/server/internal/runtimeapps"
"github.com/multica-ai/multica/server/internal/service"
"github.com/multica-ai/multica/server/internal/util"
- agentpkg "github.com/multica-ai/multica/server/pkg/agent"
db "github.com/multica-ai/multica/server/pkg/db/generated"
"github.com/multica-ai/multica/server/pkg/protocol"
"github.com/multica-ai/multica/server/pkg/redact"
@@ -457,10 +456,15 @@ func (h *Handler) DaemonRegister(w http.ResponseWriter, r *http.Request) {
if runtime.Status == "offline" {
status = "offline"
}
+ // Persist what this daemon advertised, so surfaces that cannot see the
+ // live request — the resource-save gate and the UI — decide from the
+ // same signal the claim path uses, instead of re-deriving it from a
+ // version string (MUL-5707).
metadata, _ := json.Marshal(map[string]any{
- "version": runtime.Version,
- "cli_version": req.CLIVersion,
- "launched_by": req.LaunchedBy,
+ "version": runtime.Version,
+ "cli_version": req.CLIVersion,
+ "launched_by": req.LaunchedBy,
+ "capabilities": requestClientCapabilities(r),
})
var registered db.AgentRuntime
@@ -1427,6 +1431,44 @@ func logClaimEndpointSlow(runtimeID, outcome string, start time.Time, authMs, cl
// requestHasClientCapability reports whether the caller advertised a capability
// in X-Client-Capabilities. Daemons and app clients share the header.
+// requestClientCapabilities returns the advertised capability list, trimmed and
+// with empties dropped. Nil when the header is absent — which is exactly what an
+// older daemon looks like.
+func requestClientCapabilities(r *http.Request) []string {
+ raw := strings.Split(r.Header.Get("X-Client-Capabilities"), ",")
+ out := make([]string, 0, len(raw))
+ for _, part := range raw {
+ if trimmed := strings.TrimSpace(part); trimmed != "" {
+ out = append(out, trimmed)
+ }
+ }
+ if len(out) == 0 {
+ return nil
+ }
+ return out
+}
+
+// runtimeHasCapability reports whether a stored runtime row advertised the
+// capability at registration. Absent metadata means an older daemon that never
+// sent the header, so this fails closed.
+func runtimeHasCapability(metadata []byte, capability string) bool {
+ if len(metadata) == 0 {
+ return false
+ }
+ var m struct {
+ Capabilities []string `json:"capabilities"`
+ }
+ if err := json.Unmarshal(metadata, &m); err != nil {
+ return false
+ }
+ for _, c := range m.Capabilities {
+ if c == capability {
+ return true
+ }
+ }
+ return false
+}
+
func requestHasClientCapability(r *http.Request, capability string) bool {
for _, part := range strings.Split(r.Header.Get("X-Client-Capabilities"), ",") {
if strings.TrimSpace(part) == capability {
@@ -2697,7 +2739,11 @@ func (h *Handler) buildClaimedTaskResponse(r *http.Request, task *db.AgentTaskQu
// user asked to isolate. That is the exact outcome worktree mode exists to
// prevent, so it fails closed here, against the version of the runtime that
// is actually claiming.
- if reason := worktreeClaimBlockReason(resp.ProjectResources, runtime); reason != "" {
+ if reason := worktreeClaimBlockReason(
+ resp.ProjectResources,
+ runtime,
+ requestHasClientCapability(r, protocol.DaemonCapabilityLocalWorktreeV1),
+ ); reason != "" {
slog.Error("task claim: runtime too old for worktree mode; cancelling rather than running in place",
"task_id", uuidToString(task.ID),
"runtime_id", runtimeID,
@@ -2751,13 +2797,24 @@ func (h *Handler) buildClaimedTaskResponse(r *http.Request, task *db.AgentTaskQu
// worktreeClaimBlockReason returns a user-facing reason when this runtime must
// not run the task, or "" when it may proceed.
//
+// The decision is made on the CAPABILITY the daemon advertised on this very
+// request, not on its version string. A daemon without the implementation does
+// not merely lose concurrency — it json-skips execution_mode and runs the task
+// in place, editing the working copy the user asked to isolate. Version strings
+// could not answer that reliably: the git-describe dev-build exemption that
+// keeps `make daemon` unblocked let a v0.4.23-era daemon straight through, and
+// two tasks silently ran in the user's own directory (MUL-5707).
+//
// Only resources bound to the claiming runtime's own daemon are considered: a
// project may carry one local_directory per machine, and another machine's
// worktree resource says nothing about this one's ability to run the task.
-func worktreeClaimBlockReason(resources []ProjectResourceData, runtime db.AgentRuntime) string {
+func worktreeClaimBlockReason(resources []ProjectResourceData, runtime db.AgentRuntime, hasWorktreeCapability bool) string {
if !runtime.DaemonID.Valid || runtime.DaemonID.String == "" {
return ""
}
+ if hasWorktreeCapability {
+ return ""
+ }
for _, res := range resources {
if res.ResourceType != "local_directory" {
continue
@@ -2769,16 +2826,11 @@ func worktreeClaimBlockReason(resources []ProjectResourceData, runtime db.AgentR
if ref.ExecutionMode != localDirectoryModeWorktree || ref.DaemonID != runtime.DaemonID.String {
continue
}
- current := readRuntimeCLIVersion(runtime.Metadata)
- if err := agentpkg.CheckMinCLIVersionFor(current, agentpkg.MinLocalWorktreeCLIVersion); err != nil {
- shown := current
- if strings.TrimSpace(shown) == "" {
- shown = "unknown"
- }
- return fmt.Sprintf(
- "this project's local directory %q is set to run tasks in isolated git worktrees, but the Multica runtime on that machine is %s and needs %s or newer; update it, or switch the resource back to in_place",
- ref.LocalPath, shown, agentpkg.MinLocalWorktreeCLIVersion)
- }
+ return fmt.Sprintf(
+ "This machine's Multica runtime does not support parallel (worktree) mode, which %q is set to use. "+
+ "Update the Multica app on that machine to the latest version, then re-run this task. "+
+ "Refusing to run rather than falling back to editing the directory directly, which is what this mode exists to prevent.",
+ ref.LocalPath)
}
return ""
}
diff --git a/server/internal/handler/project_resource.go b/server/internal/handler/project_resource.go
index 6699df88ff..dadbec6804 100644
--- a/server/internal/handler/project_resource.go
+++ b/server/internal/handler/project_resource.go
@@ -167,32 +167,78 @@ func (h *Handler) requireWorktreeCapableDaemon(w http.ResponseWriter, r *http.Re
}
// One machine hosts one runtime row per provider, all registered by the
- // same daemon binary, so the freshest row's metadata.cli_version is the
- // machine's current binary. A workspace has a handful of runtimes; the
- // unfiltered list is a tiny read.
+ // same daemon binary. A workspace has a handful of runtimes; the unfiltered
+ // list is a tiny read.
runtimes, err := h.Queries.ListAgentRuntimes(r.Context(), workspaceID)
if err != nil {
- writeError(w, http.StatusInternalServerError, "failed to check daemon version")
+ writeError(w, http.StatusInternalServerError, "failed to check runtime capabilities")
return false
}
- current := latestDaemonCLIVersion(runtimes, ref.DaemonID)
- minimum := agentpkg.MinLocalWorktreeCLIVersion
- if err := agentpkg.CheckMinCLIVersionFor(current, minimum); err != nil {
- // Fail closed on missing/unparsable versions too — including a
- // daemon_id with no registered runtime at all: a worktree resource
- // that can never dispatch correctly is worse than a save-time error.
- writeJSON(w, http.StatusUnprocessableEntity, map[string]any{
- "error": fmt.Sprintf(
- "local_directory: execution_mode=worktree needs daemon version %s or newer, but daemon %s reports %q; upgrade the daemon (or keep the resource on in_place)",
- minimum, ref.DaemonID, current),
- "code": "daemon_version_unsupported",
- "current_version": current,
- "min_version": minimum,
- "daemon_id": ref.DaemonID,
- })
+ // Same signal the claim gate uses: what the daemon advertised, recorded on
+ // its runtime row at registration. Version numbers cannot answer this — a
+ // dev-built daemon reports a git-describe string that the version floor
+ // deliberately exempts (MUL-5707).
+ if daemonAdvertisesWorktree(runtimes, ref.DaemonID) {
+ return true
+ }
+ // Fail closed when no runtime for this daemon advertises it — including a
+ // daemon_id with no registered runtime at all: a worktree resource that can
+ // never dispatch correctly is worse than a save-time error.
+ writeJSON(w, http.StatusUnprocessableEntity, map[string]any{
+ "error": fmt.Sprintf(
+ "local_directory: %q is set to parallel (worktree) mode, but the Multica runtime on that machine does not support it. Update the Multica app on that machine to the latest version, or keep the resource on in_place.",
+ ref.LocalPath),
+ "code": "daemon_version_unsupported",
+ "current_version": latestDaemonCLIVersion(runtimes, ref.DaemonID),
+ "min_version": agentpkg.MinLocalWorktreeCLIVersion,
+ "daemon_id": ref.DaemonID,
+ })
+ return false
+}
+
+// daemonAdvertisesWorktree reports whether the daemon's MOST RECENTLY SEEN
+// runtime row advertised worktree support.
+//
+// Deliberately not "any row advertised it". Deregistering a runtime only flips
+// the row to offline — its metadata survives — and ListAgentRuntimes returns
+// every row. So a machine that once ran a capable daemon, then downgraded,
+// still has an old capable row sitting next to the fresh incapable one, and an
+// any-match would keep saying yes forever. Newest-wins reads the machine's
+// CURRENT binary, which is the question being asked.
+//
+// A row missing the capability is never skipped: being the newest is what makes
+// it authoritative, not whether its answer is convenient.
+func daemonAdvertisesWorktree(runtimes []db.AgentRuntime, daemonID string) bool {
+ if strings.TrimSpace(daemonID) == "" {
return false
}
- return true
+ var newest *db.AgentRuntime
+ for i := range runtimes {
+ rt := &runtimes[i]
+ if !rt.DaemonID.Valid || rt.DaemonID.String != daemonID {
+ continue
+ }
+ if newest == nil || runtimeSeenAfter(rt, newest) {
+ newest = rt
+ }
+ }
+ if newest == nil {
+ return false
+ }
+ return runtimeHasCapability(newest.Metadata, protocol.DaemonCapabilityLocalWorktreeV1)
+}
+
+// runtimeSeenAfter orders two rows of the same daemon by last_seen_at. A row
+// that never reported (NULL) sorts oldest, so a live row always wins over one
+// that never checked in.
+func runtimeSeenAfter(candidate, current *db.AgentRuntime) bool {
+ if !candidate.LastSeenAt.Valid {
+ return false
+ }
+ if !current.LastSeenAt.Valid {
+ return true
+ }
+ return candidate.LastSeenAt.Time.After(current.LastSeenAt.Time)
}
// latestDaemonCLIVersion returns the cli_version of the freshest runtime row
diff --git a/server/internal/handler/worktree_claim_gate_test.go b/server/internal/handler/worktree_claim_gate_test.go
index 1b1dcc5838..26cf6b15f7 100644
--- a/server/internal/handler/worktree_claim_gate_test.go
+++ b/server/internal/handler/worktree_claim_gate_test.go
@@ -7,11 +7,13 @@ import (
"net/http/httptest"
"strings"
"testing"
+ "time"
"github.com/go-chi/chi/v5"
"github.com/jackc/pgx/v5/pgtype"
db "github.com/multica-ai/multica/server/pkg/db/generated"
+ "github.com/multica-ai/multica/server/pkg/protocol"
)
func localDirRef(t *testing.T, path, daemonID, mode string) json.RawMessage {
@@ -45,27 +47,27 @@ func TestWorktreeClaimBlockReason(t *testing.T) {
ResourceRef: localDirRef(t, "/Users/dev/game", daemon, "worktree"),
}}
- t.Run("blocks a runtime below the floor", func(t *testing.T) {
- reason := worktreeClaimBlockReason(worktreeRes, runtimeWithVersion(daemon, "0.4.10"))
+ t.Run("blocks a runtime that does not advertise the capability", func(t *testing.T) {
+ reason := worktreeClaimBlockReason(worktreeRes, runtimeWithVersion(daemon, "0.4.10"), false)
if reason == "" {
t.Fatal("an outdated runtime was allowed to claim a worktree task")
}
- if !strings.Contains(reason, "/Users/dev/game") || !strings.Contains(reason, "0.4.10") {
- t.Errorf("reason should name the directory and the version, got: %q", reason)
+ if !strings.Contains(reason, "/Users/dev/game") || !strings.Contains(reason, "Update the Multica app") {
+ t.Errorf("reason should name the directory and tell the user to update, got: %q", reason)
}
})
- t.Run("blocks a runtime reporting no version at all", func(t *testing.T) {
+ t.Run("blocks a runtime that advertises nothing at all", func(t *testing.T) {
// Fail closed: "no version" is what a daemon far older than the field
// looks like, which is exactly the dangerous case.
- if worktreeClaimBlockReason(worktreeRes, runtimeWithVersion(daemon, "")) == "" {
- t.Error("a runtime with no reported version was allowed to claim")
+ if worktreeClaimBlockReason(worktreeRes, runtimeWithVersion(daemon, ""), false) == "" {
+ t.Error("a runtime advertising nothing was allowed to claim")
}
})
- t.Run("allows a runtime at or above the floor", func(t *testing.T) {
- if reason := worktreeClaimBlockReason(worktreeRes, runtimeWithVersion(daemon, "9.9.9")); reason != "" {
- t.Errorf("a new enough runtime was blocked: %q", reason)
+ t.Run("allows a runtime that advertises the capability", func(t *testing.T) {
+ if reason := worktreeClaimBlockReason(worktreeRes, runtimeWithVersion(daemon, "9.9.9"), true); reason != "" {
+ t.Errorf("a capable runtime was blocked: %q", reason)
}
})
@@ -75,8 +77,8 @@ func TestWorktreeClaimBlockReason(t *testing.T) {
ID: "r1", ResourceType: "local_directory",
ResourceRef: localDirRef(t, "/Users/dev/game", daemon, mode),
}}
- if reason := worktreeClaimBlockReason(res, runtimeWithVersion(daemon, "0.1.0")); reason != "" {
- t.Errorf("mode %q blocked an old daemon that can run it fine: %q", mode, reason)
+ if reason := worktreeClaimBlockReason(res, runtimeWithVersion(daemon, "0.1.0"), false); reason != "" {
+ t.Errorf("mode %q blocked a daemon that can run it fine: %q", mode, reason)
}
}
})
@@ -88,7 +90,7 @@ func TestWorktreeClaimBlockReason(t *testing.T) {
ID: "r1", ResourceType: "local_directory",
ResourceRef: localDirRef(t, "/Users/dev/game", "daemon-b", "worktree"),
}}
- if reason := worktreeClaimBlockReason(other, runtimeWithVersion(daemon, "0.1.0")); reason != "" {
+ if reason := worktreeClaimBlockReason(other, runtimeWithVersion(daemon, "0.1.0"), false); reason != "" {
t.Errorf("another machine's resource blocked this claim: %q", reason)
}
})
@@ -98,13 +100,13 @@ func TestWorktreeClaimBlockReason(t *testing.T) {
ID: "r1", ResourceType: "github_repo",
ResourceRef: json.RawMessage(`{"url":"https://github.com/a/b"}`),
}}
- if reason := worktreeClaimBlockReason(repo, runtimeWithVersion(daemon, "0.1.0")); reason != "" {
+ if reason := worktreeClaimBlockReason(repo, runtimeWithVersion(daemon, "0.1.0"), false); reason != "" {
t.Errorf("github_repo resource blocked a claim: %q", reason)
}
})
t.Run("ignores a runtime with no daemon id", func(t *testing.T) {
- if reason := worktreeClaimBlockReason(worktreeRes, runtimeWithVersion("", "0.1.0")); reason != "" {
+ if reason := worktreeClaimBlockReason(worktreeRes, runtimeWithVersion("", "0.1.0"), false); reason != "" {
t.Errorf("cloud runtime blocked: %q", reason)
}
})
@@ -114,7 +116,7 @@ func TestWorktreeClaimBlockReason(t *testing.T) {
ID: "r1", ResourceType: "local_directory",
ResourceRef: json.RawMessage(`{"local_path": 42}`),
}}
- if reason := worktreeClaimBlockReason(bad, runtimeWithVersion(daemon, "0.1.0")); reason != "" {
+ if reason := worktreeClaimBlockReason(bad, runtimeWithVersion(daemon, "0.1.0"), false); reason != "" {
t.Errorf("malformed ref produced a block: %q", reason)
}
})
@@ -619,8 +621,10 @@ func TestClaimTask_WorktreeGateSingular(t *testing.T) {
if w.Code != http.StatusUnprocessableEntity {
t.Fatalf("expected 422 for a too-old runtime, got %d: %s", w.Code, w.Body.String())
}
- if body := w.Body.String(); !strings.Contains(body, "/Users/dev/wtgate") || !strings.Contains(body, "0.4.10") {
- t.Errorf("422 body should carry the actionable reason, got: %s", body)
+ if body := w.Body.String(); !strings.Contains(body, "/Users/dev/wtgate") ||
+ !strings.Contains(body, "does not support parallel") ||
+ !strings.Contains(body, "Update the Multica app") {
+ t.Errorf("422 body should name the directory and tell the user to update, got: %s", body)
}
assertWorktreeGateCancelled(t, ctx, taskID)
}
@@ -654,18 +658,21 @@ func TestClaimTask_WorktreeGateBatch(t *testing.T) {
}
// TestClaimTask_WorktreeGateAllowsCurrentRuntime is the control: the same
-// fixture with a new-enough runtime claims normally, proving the gate blocks
-// on version — not on worktree resources in general.
+// fixture with a daemon that ADVERTISES worktree support claims normally,
+// proving the gate blocks on the missing capability — not on worktree
+// resources in general. Note the deliberately ancient version string: the gate
+// must not consult it at all.
func TestClaimTask_WorktreeGateAllowsCurrentRuntime(t *testing.T) {
if testHandler == nil || testPool == nil {
t.Skip("database not available")
}
ctx := context.Background()
const daemonID = "wtgate-ok-daemon"
- runtimeID, taskID := seedWorktreeGateClaimFixture(t, ctx, "WT gate ok", daemonID, "9.9.9")
+ runtimeID, taskID := seedWorktreeGateClaimFixture(t, ctx, "WT gate ok", daemonID, "0.0.1")
w := httptest.NewRecorder()
req := newDaemonTokenRequest("POST", "/api/daemon/runtimes/"+runtimeID+"/claim", nil, testWorkspaceID, daemonID)
+ req.Header.Set("X-Client-Capabilities", protocol.DaemonCapabilityLocalWorktreeV1)
req = withURLParam(req, "runtimeId", runtimeID)
testHandler.ClaimTaskByRuntime(w, req)
@@ -778,3 +785,220 @@ func TestClaimTask_WorktreeGateCancelFailureRequeuesBatch(t *testing.T) {
t.Errorf("status = %q, want queued after the batch gate's cancel failed", status)
}
}
+
+// The bug this gate was rebuilt for: a dev-built daemon reports a git-describe
+// version that the version floor deliberately exempts, so the old version-based
+// gate waved through a binary with no worktree implementation and two tasks ran
+// in the user's own directory (MUL-5707). The capability signal is immune to
+// how the version string happens to be spelled.
+func TestWorktreeClaimGateIgnoresVersionStrings(t *testing.T) {
+ const daemon = "daemon-a"
+ res := []ProjectResourceData{{
+ ID: "r1", ResourceType: "local_directory",
+ ResourceRef: localDirRef(t, "/Users/dev/game", daemon, "worktree"),
+ }}
+
+ // Every one of these is a version string that the old floor check would
+ // have ALLOWED. Without the capability, all must now be blocked.
+ for _, version := range []string{
+ "v0.4.21-24-gcd3c0bb89", // the exact dev-describe build that got through
+ "0.4.24", // at the floor
+ "9.9.9", // far above it
+ "", // none reported
+ } {
+ if worktreeClaimBlockReason(res, runtimeWithVersion(daemon, version), false) == "" {
+ t.Errorf("version %q was allowed to claim without advertising the capability", version)
+ }
+ }
+
+ // And the converse: a capable daemon runs regardless of how old its version
+ // string looks, so the gate can never strand a runtime that actually works.
+ for _, version := range []string{"v0.4.21-24-gcd3c0bb89", "0.0.1", ""} {
+ if reason := worktreeClaimBlockReason(res, runtimeWithVersion(daemon, version), true); reason != "" {
+ t.Errorf("version %q blocked a capable runtime: %q", version, reason)
+ }
+ }
+}
+
+// The stored-capability read backs the save-time gate and the UI, which cannot
+// see the live request. Absent metadata is an older daemon: fail closed.
+func TestRuntimeHasCapability(t *testing.T) {
+ withCaps := func(caps ...string) []byte {
+ raw, err := json.Marshal(map[string]any{"capabilities": caps})
+ if err != nil {
+ t.Fatalf("marshal: %v", err)
+ }
+ return raw
+ }
+
+ if !runtimeHasCapability(withCaps("skill-bundles-v1", "local-worktree-v1"), "local-worktree-v1") {
+ t.Error("advertised capability not detected")
+ }
+ if runtimeHasCapability(withCaps("skill-bundles-v1"), "local-worktree-v1") {
+ t.Error("unadvertised capability reported as present")
+ }
+ for _, metadata := range [][]byte{
+ nil,
+ []byte(`{}`),
+ []byte(`{"cli_version":"9.9.9"}`), // an old daemon: version, no capabilities
+ []byte(`not json`),
+ } {
+ if runtimeHasCapability(metadata, "local-worktree-v1") {
+ t.Errorf("metadata %q reported the capability as present", string(metadata))
+ }
+ }
+}
+
+func runtimeRow(daemonID string, seenAt time.Time, caps ...string) db.AgentRuntime {
+ rt := db.AgentRuntime{
+ DaemonID: pgtype.Text{String: daemonID, Valid: daemonID != ""},
+ LastSeenAt: pgtype.Timestamptz{Time: seenAt, Valid: !seenAt.IsZero()},
+ }
+ payload := map[string]any{"cli_version": "9.9.9"}
+ if len(caps) > 0 {
+ payload["capabilities"] = caps
+ }
+ rt.Metadata, _ = json.Marshal(payload)
+ return rt
+}
+
+// Deregistering a runtime only flips the row to offline — its metadata,
+// capabilities included, survives — and ListAgentRuntimes returns every row. So
+// "any row advertised it" keeps answering yes long after the machine downgraded,
+// and the save gate and UI would keep offering a mode the claim gate then
+// refuses. Newest-seen row wins.
+func TestDaemonAdvertisesWorktreeUsesNewestRow(t *testing.T) {
+ const daemon = "daemon-a"
+ older := time.Date(2026, 8, 1, 0, 0, 0, 0, time.UTC)
+ newer := time.Date(2026, 8, 13, 0, 0, 0, 0, time.UTC)
+
+ t.Run("stale capable row does not rescue a downgraded daemon", func(t *testing.T) {
+ rows := []db.AgentRuntime{
+ runtimeRow(daemon, older, "local-worktree-v1"), // left behind by the old capable build
+ runtimeRow(daemon, newer), // what the machine runs now
+ }
+ if daemonAdvertisesWorktree(rows, daemon) {
+ t.Error("a stale capable row was allowed to vouch for a downgraded daemon")
+ }
+ })
+
+ t.Run("newest capable row wins over an older incapable one", func(t *testing.T) {
+ rows := []db.AgentRuntime{
+ runtimeRow(daemon, older),
+ runtimeRow(daemon, newer, "local-worktree-v1"), // the upgrade
+ }
+ if !daemonAdvertisesWorktree(rows, daemon) {
+ t.Error("an upgraded daemon was not recognised")
+ }
+ })
+
+ t.Run("row order does not matter", func(t *testing.T) {
+ rows := []db.AgentRuntime{
+ runtimeRow(daemon, newer),
+ runtimeRow(daemon, older, "local-worktree-v1"),
+ }
+ if daemonAdvertisesWorktree(rows, daemon) {
+ t.Error("result depended on slice order")
+ }
+ })
+
+ t.Run("a row that never reported loses to one that did", func(t *testing.T) {
+ var never time.Time
+ rows := []db.AgentRuntime{
+ runtimeRow(daemon, never, "local-worktree-v1"),
+ runtimeRow(daemon, newer),
+ }
+ if daemonAdvertisesWorktree(rows, daemon) {
+ t.Error("a never-seen row outvoted a live one")
+ }
+ })
+
+ t.Run("ignores other daemons and empty ids", func(t *testing.T) {
+ rows := []db.AgentRuntime{runtimeRow("daemon-b", newer, "local-worktree-v1")}
+ if daemonAdvertisesWorktree(rows, daemon) {
+ t.Error("another machine's row vouched for this daemon")
+ }
+ if daemonAdvertisesWorktree(rows, "") {
+ t.Error("empty daemon id matched a row")
+ }
+ if daemonAdvertisesWorktree(nil, daemon) {
+ t.Error("no rows at all reported capable")
+ }
+ })
+}
+
+// The bridge the whole gate rests on: what the daemon advertises on the
+// register request has to survive onto the runtime row, or the save gate and
+// the UI read an empty capability list and refuse a machine that is perfectly
+// capable. Drives the real DaemonRegister handler.
+func TestDaemonRegisterPersistsCapabilities(t *testing.T) {
+ if testHandler == nil || testPool == nil {
+ t.Skip("database not available")
+ }
+ ctx := context.Background()
+ const daemonID = "capability-roundtrip-daemon"
+
+ register := func(t *testing.T, capabilities string) string {
+ t.Helper()
+ w := httptest.NewRecorder()
+ req := newDaemonTokenRequest("POST", "/api/daemon/register", map[string]any{
+ "workspace_id": testWorkspaceID,
+ "daemon_id": daemonID,
+ "device_name": "capability-roundtrip-device",
+ "runtimes": []map[string]any{
+ {"name": "cap-runtime", "type": "claude", "version": "1.0.0", "status": "online"},
+ },
+ }, testWorkspaceID, daemonID)
+ if capabilities != "" {
+ req.Header.Set("X-Client-Capabilities", capabilities)
+ } else {
+ req.Header.Del("X-Client-Capabilities")
+ }
+ testHandler.DaemonRegister(w, req)
+ if w.Code != http.StatusOK {
+ t.Fatalf("DaemonRegister: expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+ var resp map[string]any
+ if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
+ t.Fatalf("decode: %v", err)
+ }
+ runtimes, ok := resp["runtimes"].([]any)
+ if !ok || len(runtimes) == 0 {
+ t.Fatalf("expected runtimes in response, got %v", resp)
+ }
+ id := runtimes[0].(map[string]any)["id"].(string)
+ t.Cleanup(func() { testPool.Exec(ctx, `DELETE FROM agent_runtime WHERE id = $1`, id) })
+ return id
+ }
+
+ assertCapable := func(t *testing.T, runtimeID string, want bool) {
+ t.Helper()
+ var metadata []byte
+ if err := testPool.QueryRow(ctx,
+ `SELECT metadata FROM agent_runtime WHERE id = $1`, runtimeID).Scan(&metadata); err != nil {
+ t.Fatalf("read metadata: %v", err)
+ }
+ if got := runtimeHasCapability(metadata, protocol.DaemonCapabilityLocalWorktreeV1); got != want {
+ t.Errorf("capability persisted = %v, want %v (metadata: %s)", got, want, metadata)
+ }
+ }
+
+ t.Run("advertised capability lands on the row", func(t *testing.T) {
+ id := register(t, protocol.DaemonCapabilitySkillBundlesV1+","+protocol.DaemonCapabilityLocalWorktreeV1)
+ assertCapable(t, id, true)
+ })
+
+ // An older daemon sends no header at all. Re-registering must overwrite the
+ // row rather than leave a capable-looking one behind — that is precisely the
+ // downgrade the save gate has to notice.
+ t.Run("re-registering without the header clears it", func(t *testing.T) {
+ id := register(t, protocol.DaemonCapabilitySkillBundlesV1+","+protocol.DaemonCapabilityLocalWorktreeV1)
+ assertCapable(t, id, true)
+
+ again := register(t, "")
+ if again != id {
+ t.Fatalf("expected the same runtime row on re-register, got %s then %s", id, again)
+ }
+ assertCapable(t, id, false)
+ })
+}
diff --git a/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md b/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md
index 834c979966..00e2b41acd 100644
--- a/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md
+++ b/server/internal/service/builtin_skills/multica-projects-and-resources/references/projects-and-resources-source-map.md
@@ -6,7 +6,7 @@
- `project create` / `project update` accept `--start-date` / `--due-date` (calendar days, `YYYY-MM-DD`), mapping to the project `start_date` / `due_date` columns (migration `166_project_dates`); an empty `--start-date ""`/`--due-date ""` on update clears the date, mirroring the issue date flags in `cmd_issue.go`.
- `project resource add` supports shortcuts for `github_repo` (`--url`, non-JSON `--ref` for checkout ref, `--default-branch-hint`) and `local_directory` (`--local-path`, `--daemon-id`, `--ref-label`, `--execution-mode`), or generic JSON `--ref '<json>'`.
- `local_directory.execution_mode` is validated in `server/internal/handler/project_resource.go` (`validateLocalDirectoryRef`); the daemon reads it in `server/internal/daemon/local_directory.go` (`localDirectoryAssignment.UsesWorktree`) and builds the per-task worktree in `server/internal/daemon/execenv/local_worktree.go`.
-- Saving `execution_mode=worktree` is gated on the daemon's registered `cli_version` by `requireWorktreeCapableDaemon` in `server/internal/handler/project_resource.go` (floor: `MinLocalWorktreeCLIVersion` in `server/pkg/agent/version.go`); too old → HTTP 422 `daemon_version_unsupported`.
+- Saving `execution_mode=worktree` is gated on the daemon having advertised the `local-worktree-v1` capability (`protocol.DaemonCapabilityLocalWorktreeV1`), checked by `requireWorktreeCapableDaemon` in `server/internal/handler/project_resource.go` against the daemon's most recently seen runtime row; not capable → HTTP 422 `daemon_version_unsupported`. The authoritative gate is at claim time (`worktreeClaimBlockReason` in `server/internal/handler/daemon.go`), which reads the capability off the claim request itself and cancels the task with a reason. `MinLocalWorktreeCLIVersion` is only the number shown to the user; nothing gates on it.
- `project resource update` merges shortcut edits with existing `resource_ref` so a partial edit does not clobber required fields; non-JSON `--ref` updates `github_repo.resource_ref.ref`.
- `server/cmd/server/router.go` exposes `/api/projects` plus `/api/projects/{projectId}/resources` routes.
- `server/pkg/db/queries/project_resource.sql` is the CRUD query surface for `project_resource` rows.
diff --git a/server/pkg/agent/version.go b/server/pkg/agent/version.go
index 255a8f48bb..85ad406d3d 100644
--- a/server/pkg/agent/version.go
+++ b/server/pkg/agent/version.go
@@ -34,17 +34,20 @@ const MinQuickCreateCLIVersion = "0.2.21"
// older floor above; only requests using these optional fields need this gate.
const MinQuickCreateFieldsCLIVersion = "0.4.3"
-// MinLocalWorktreeCLIVersion is the first daemon release that implements
-// execution_mode=worktree for local_directory resources (MUL-5707). A daemon
-// older than this does not know the field exists: it json-skips it and runs
-// the task IN PLACE, editing the working copy the user explicitly asked to
-// isolate. (Daemons FROM this version refuse unknown future modes themselves —
-// see localDirectoryAssignment.ValidateExecutionMode — but a daemon that
-// predates the field cannot refuse what it cannot see, so the server has to.)
-// The handler rejects saving a worktree-mode resource while the owning
-// daemon's registered CLI version is missing or below this floor. Hard
-// requirement, fail closed. Keep in sync with the release that actually ships
-// worktree mode when tagging.
+// MinLocalWorktreeCLIVersion is the release that first shipped
+// execution_mode=worktree for local_directory resources (MUL-5707).
+//
+// NOTHING GATES ON THIS. It is a display value: the number shown in the 422
+// payload and the UI hint so a user knows roughly which release to update to.
+// The gates themselves read protocol.DaemonCapabilityLocalWorktreeV1, which
+// the daemon advertises only when it actually implements the mode.
+//
+// It stopped being a gate because it could not be one. A daemon without the
+// implementation does not lose a field — it runs the task IN PLACE, editing the
+// working copy the user asked to isolate. Version strings cannot answer that:
+// CheckMinCLIVersionFor exempts git-describe dev builds so `make daemon` stays
+// unblocked, and a v0.4.23-era daemon reporting "v0.4.21-24-gcd3c0bb89" sailed
+// through the floor and ran two tasks in the user's own directory.
const MinLocalWorktreeCLIVersion = "0.4.24"
// MinHandoffCLIVersion is the lowest multica CLI version whose daemon renders
diff --git a/server/pkg/agent/worktree_version_floor_test.go b/server/pkg/agent/worktree_version_floor_test.go
index f07d88d98b..dfc1388394 100644
--- a/server/pkg/agent/worktree_version_floor_test.go
+++ b/server/pkg/agent/worktree_version_floor_test.go
@@ -7,14 +7,10 @@ import (
"testing"
)
-// The worktree version floor is enforced in three places that must agree:
-//
-// server — refuses to save a worktree resource below it, and refuses to hand
-// a worktree task to a runtime below it at claim time;
-// frontend — disables the option and explains why before the user submits.
-//
-// If they drift, the UI offers a mode the server will refuse, or worse, the
-// frontend permits a version the server no longer gates. Pin them together.
+// The worktree floor is no longer a gate — the capability is (MUL-5707). It
+// survives as the version number shown to the user in the 422 payload and the
+// UI hint, and those two must still quote the same release: telling someone to
+// update to 0.4.24 in one place and 0.4.30 in another is its own bug.
func TestWorktreeCLIVersionFloorMatchesFrontend(t *testing.T) {
path := filepath.Join("..", "..", "..", "packages", "core", "runtimes", "cli-version.ts")
src, err := os.ReadFile(path)
@@ -26,7 +22,7 @@ func TestWorktreeCLIVersionFloorMatchesFrontend(t *testing.T) {
t.Fatal("MIN_LOCAL_WORKTREE_CLI_VERSION not found in packages/core/runtimes/cli-version.ts")
}
if got := string(m[1]); got != MinLocalWorktreeCLIVersion {
- t.Errorf("frontend floor %s != server floor %s; the save gate, the claim gate and the UI must agree",
+ t.Errorf("frontend shows %s but the server's 422 quotes %s; the update hint must name one release",
got, MinLocalWorktreeCLIVersion)
}
}
diff --git a/server/pkg/protocol/messages.go b/server/pkg/protocol/messages.go
index d1157242c1..f8ed42dc96 100644
--- a/server/pkg/protocol/messages.go
+++ b/server/pkg/protocol/messages.go
@@ -7,6 +7,19 @@ const (
DaemonCapabilityCoalescedCommentsV1 = "coalesced-comments-v1"
DaemonCapabilityExecutionManifestV1 = "execution-manifest-v1"
DaemonCapabilityAgentSkillV1 = "agent-skill-v1"
+ // DaemonCapabilityLocalWorktreeV1 advertises that the daemon implements
+ // worktree mode for local_directory resources (execution_mode=worktree).
+ //
+ // This is a CAPABILITY rather than a version check on purpose. The failure
+ // mode of getting it wrong is not a missing field — a daemon without the
+ // implementation json-skips execution_mode and runs the task IN PLACE,
+ // editing the working copy the user asked to isolate. Version strings
+ // cannot answer that reliably: a git-describe dev build ("v0.4.21-24-g…")
+ // is deliberately exempted from the version floor so `make daemon` stays
+ // unblocked, which let exactly such a daemon through (MUL-5707). A daemon
+ // that implements the mode says so; one that does not, cannot.
+ DaemonCapabilityLocalWorktreeV1 = "local-worktree-v1"
+
// DaemonCapabilityRPCV1 advertises that the daemon can carry
// request/response RPCs over the WebSocket control connection (MUL-4257).
// Gated so only daemons+servers that both support it route claim over WS;