Skip to content

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

Go

MUL-6126: fix(runtime): make private runtimes owner-only in the API and CLI too (#6905)

Bohan Jiang6db6b235bac3
diff --git a/apps/docs/content/docs/daemon-runtimes.ja.mdx b/apps/docs/content/docs/daemon-runtimes.ja.mdx
index 3878bc357c..ed4be8dcae 100644
--- a/apps/docs/content/docs/daemon-runtimes.ja.mdx
+++ b/apps/docs/content/docs/daemon-runtimes.ja.mdx
@@ -73,9 +73,9 @@ multica daemon start
## プライベートと公開
-ローカルランタイムはデフォルトで**プライベート**です。ランタイムの所有者と、ワークスペースの owner・admin がその上にエージェントを作成できます。
+ローカルランタイムはデフォルトで**プライベート**です。その上にエージェントを作成できるのはランタイムの所有者だけで、ワークスペースの owner・admin も例外ではありません。ランタイムは他のメンバーのコンピュータであり、そこでエージェントを動かすことはそのメンバーのマシンとツール認証情報を消費するためです。
-ランタイムの所有者または管理者は、ランタイムを**公開**に変更できます。公開すると、ワークスペースの他のメンバーもこのランタイムを選べるようになります。これは基盤の AI コーディングツールのログイン認証情報を共有するものではなく、メンバーがエージェントの実行タスクをこのコンピュータにルーティングできるようになるだけです。
+ランタイムを**公開**に変更できるのは所有者だけです。ワークスペースの管理者はランタイムの名前変更や削除はできますが、共有するかどうかは所有者が決めます。公開すると、ワークスペースの他のメンバーもこのランタイムを選べるようになります。これは基盤の AI コーディングツールのログイン認証情報を共有するものではなく、メンバーがエージェントの実行タスクをこのコンピュータにルーティングできるようになるだけです。
## カスタムランタイムプロファイル
diff --git a/apps/docs/content/docs/daemon-runtimes.ko.mdx b/apps/docs/content/docs/daemon-runtimes.ko.mdx
index e45400c28a..f22690b605 100644
--- a/apps/docs/content/docs/daemon-runtimes.ko.mdx
+++ b/apps/docs/content/docs/daemon-runtimes.ko.mdx
@@ -73,9 +73,9 @@ multica daemon start
## 비공개와 공개
-로컬 런타임의 기본값은 **비공개**입니다. 런타임 owner와 워크스페이스 owner, admin이 그 위에 에이전트를 만들 수 있습니다.
+로컬 런타임의 기본값은 **비공개**입니다. 그 위에 에이전트를 만들 수 있는 사람은 런타임 owner뿐이며, 워크스페이스 owner와 admin도 예외가 아닙니다. 런타임은 다른 멤버의 컴퓨터이고, 거기서 에이전트를 실행하면 그 멤버의 컴퓨터와 도구 자격 증명을 사용하게 되기 때문입니다.
-런타임 owner 또는 관리자가 **공개**로 바꿀 수 있습니다. 공개하면 워크스페이스의 다른 멤버도 이 런타임을 선택할 수 있습니다. 기반 AI 코딩 도구의 로그인 자격 증명을 공유하는 것이 아니라 멤버가 에이전트 실행 태스크를 해당 컴퓨터로 라우팅할 수 있게 하는 것입니다.
+**공개**로 바꿀 수 있는 사람은 런타임 owner뿐입니다. 워크스페이스 관리자는 런타임의 이름을 바꾸거나 삭제할 수 있지만, 공유 여부는 owner가 결정합니다. 공개하면 워크스페이스의 다른 멤버도 이 런타임을 선택할 수 있습니다. 기반 AI 코딩 도구의 로그인 자격 증명을 공유하는 것이 아니라 멤버가 에이전트 실행 태스크를 해당 컴퓨터로 라우팅할 수 있게 하는 것입니다.
## 사용자 지정 런타임 설정
diff --git a/apps/docs/content/docs/daemon-runtimes.mdx b/apps/docs/content/docs/daemon-runtimes.mdx
index cce57fdcf4..3212cbf319 100644
--- a/apps/docs/content/docs/daemon-runtimes.mdx
+++ b/apps/docs/content/docs/daemon-runtimes.mdx
@@ -73,9 +73,9 @@ Once a limit is reached, new tasks keep queueing. You can adjust a single agent'
## Private and public runtimes
-A local runtime is **private** by default: the runtime owner and the workspace's owners and admins can create agents on it.
+A local runtime is **private** by default: only the runtime owner can create agents on it. Workspace owners and admins are no exception — the runtime is someone else's computer, and running an agent there spends their machine and their tool credentials.
-The runtime owner or an admin can make it **public**. Other workspace members can then select this runtime as well; that does not share the underlying AI coding tool's login credentials — it only lets members route their agents' tasks to this computer.
+Only the runtime owner can make it **public** — workspace admins can rename or delete a runtime, but sharing one is the owner's decision. Other workspace members can then select this runtime as well; that does not share the underlying AI coding tool's login credentials — it only lets members route their agents' tasks to this computer.
## Custom runtime profiles
diff --git a/apps/docs/content/docs/daemon-runtimes.zh.mdx b/apps/docs/content/docs/daemon-runtimes.zh.mdx
index aec3150eae..be2b192832 100644
--- a/apps/docs/content/docs/daemon-runtimes.zh.mdx
+++ b/apps/docs/content/docs/daemon-runtimes.zh.mdx
@@ -73,9 +73,9 @@ multica daemon start
## 私有与公开
-本地运行时默认是**私有**的:运行时所有者和工作区的 owner、admin 可以在它上面创建智能体。
+本地运行时默认是**私有**的:只有运行时所有者可以在它上面创建智能体。工作区的 owner、admin 也不例外——运行时是别人的电脑,在上面跑智能体消耗的是对方的机器和工具凭据。
-运行时所有者或管理员可以把它改为**公开**。公开后,工作区中的其他成员也可以选择这条运行时;这不会分享底层 AI 编程工具的登录凭据,只是允许成员把智能体的执行任务路由到这台电脑。
+只有运行时所有者可以把它改为**公开**——管理员可以重命名或删除运行时,但要不要共享由所有者决定。公开后,工作区中的其他成员也可以选择这条运行时;这不会分享底层 AI 编程工具的登录凭据,只是允许成员把智能体的执行任务路由到这台电脑。
## 自定义运行时配置
diff --git a/packages/core/runtimes/access.test.ts b/packages/core/runtimes/access.test.ts
new file mode 100644
index 0000000000..8c176b4ab6
--- /dev/null
+++ b/packages/core/runtimes/access.test.ts
@@ -0,0 +1,66 @@
+import { describe, expect, it } from "vitest";
+import type { AgentRuntime } from "../types";
+import { isRuntimeUsableForUser } from "./access";
+
+const OWNER = "user-owner";
+const OTHER = "user-other";
+
+function makeRuntime(overrides: Partial<AgentRuntime> = {}): AgentRuntime {
+ return {
+ id: "rt-1",
+ workspace_id: "ws-1",
+ daemon_id: "daemon-1",
+ name: "Test Runtime",
+ runtime_mode: "local",
+ provider: "claude",
+ launch_header: "",
+ status: "online",
+ device_info: "",
+ metadata: {},
+ owner_id: OWNER,
+ visibility: "private",
+ last_seen_at: null,
+ created_at: "2026-04-01T00:00:00Z",
+ updated_at: "2026-04-01T00:00:00Z",
+ ...overrides,
+ };
+}
+
+// This truth table is the client half of a contract the server enforces with
+// the identical predicate (canUseRuntimeForAgent in
+// server/internal/handler/runtime.go). Keep the two in step: a runtime this
+// says is usable but the server refuses is a picker that 403s on submit —
+// the MUL-6126 bug — and the reverse is a runtime the UI hides for no reason.
+describe("isRuntimeUsableForUser", () => {
+ it("lets the owner use their own private runtime", () => {
+ expect(isRuntimeUsableForUser(makeRuntime(), OWNER)).toBe(true);
+ });
+
+ it("refuses another member's private runtime", () => {
+ expect(isRuntimeUsableForUser(makeRuntime(), OTHER)).toBe(false);
+ });
+
+ it("lets anyone use a public runtime", () => {
+ expect(
+ isRuntimeUsableForUser(makeRuntime({ visibility: "public" }), OTHER),
+ ).toBe(true);
+ });
+
+ it("refuses an ownerless runtime whatever its visibility", () => {
+ // No owner means no task token at claim time (MUL-3292), so a bind here
+ // could only produce agents that fail the moment they run.
+ expect(isRuntimeUsableForUser(makeRuntime({ owner_id: null }), OTHER)).toBe(
+ false,
+ );
+ expect(
+ isRuntimeUsableForUser(
+ makeRuntime({ owner_id: null, visibility: "public" }),
+ OTHER,
+ ),
+ ).toBe(false);
+ });
+
+ it("allows everything while the viewer is unknown, so a loading session never hides the user's own runtime", () => {
+ expect(isRuntimeUsableForUser(makeRuntime(), null)).toBe(true);
+ });
+});
diff --git a/packages/core/runtimes/access.ts b/packages/core/runtimes/access.ts
index f8fdd7cdbe..63852c8cd9 100644
--- a/packages/core/runtimes/access.ts
+++ b/packages/core/runtimes/access.ts
@@ -4,14 +4,28 @@ import type { RuntimeDevice } from "../types";
* Whether this member may run an agent on `runtime`.
*
* A private runtime is usable only by its owner; a public one by anyone in the
- * workspace. An unknown viewer (no session yet) is treated as allowed so a
- * still-loading auth state never hides a runtime the user does own — every
- * write path re-checks server-side, where admin overrides also apply.
+ * workspace; an ownerless one by nobody. Workspace role does not enter into
+ * it: a private runtime is someone's own machine, so not even an admin may
+ * bind an agent to it, and only the owner may flip it to public. The server
+ * enforces exactly this predicate (`canUseRuntimeForAgent`), so the picker and
+ * the API/CLI never disagree (MUL-6126).
+ *
+ * An unknown viewer (no session yet) is treated as allowed so a still-loading
+ * auth state never hides a runtime the user does own — every write path
+ * re-checks server-side.
+ *
+ * This is the single source of truth for "can this runtime be picked": every
+ * create / duplicate / builder / reassign surface must call it rather than
+ * re-deriving the rule.
*/
export function isRuntimeUsableForUser(
runtime: RuntimeDevice,
currentUserId: string | null,
): boolean {
+ // An ownerless runtime is unusable by anyone, public included: the server
+ // needs an owner to mint the agent's task token, so a bind here would only
+ // yield agents whose tasks get cancelled at claim time (MUL-3292).
+ if (!runtime.owner_id) return false;
if (!currentUserId) return true;
if (runtime.owner_id === currentUserId) return true;
return runtime.visibility === "public";
diff --git a/packages/core/types/agent.ts b/packages/core/types/agent.ts
index dbee9d3812..b91fc2707e 100644
--- a/packages/core/types/agent.ts
+++ b/packages/core/types/agent.ts
@@ -49,10 +49,11 @@ export interface AgentInvocationTargetInput {
// Runtime visibility is a separate axis from agent visibility — different
// vocabulary because it gates a different action. "private" (default) means
-// only the runtime owner and workspace admins can bind agents to it;
-// "public" opens binding to any workspace member. Older backends that
-// haven't shipped MUL-2062 omit the field; the consumer must default to
-// "private" so the strictest behavior is the fallback.
+// only the runtime owner can bind agents to it — workspace admins included,
+// and only the owner may flip the flag (MUL-6126); "public" opens binding to
+// any workspace member. Older backends that haven't shipped MUL-2062 omit the
+// field; the consumer must default to "private" so the strictest behavior is
+// the fallback.
export type RuntimeVisibility = "private" | "public";
export interface RuntimeDevice {
diff --git a/packages/views/agents/components/inspector/runtime-picker.tsx b/packages/views/agents/components/inspector/runtime-picker.tsx
index 779ab487b5..0cdb1eb667 100644
--- a/packages/views/agents/components/inspector/runtime-picker.tsx
+++ b/packages/views/agents/components/inspector/runtime-picker.tsx
@@ -9,6 +9,7 @@ import {
Lock,
Monitor,
} from "lucide-react";
+import { isRuntimeUsableForUser } from "@multica/core/runtimes";
import type { AgentRuntime, MemberWithUser } from "@multica/core/types";
import { ActorAvatar } from "../../../common/actor-avatar";
import {
@@ -69,11 +70,11 @@ export function RuntimePicker({
const selected = runtimes.find((r) => r.id === value) ?? null;
- const isDisabled = (r: AgentRuntime): boolean => {
- if (!currentUserId) return false;
- if (r.owner_id === currentUserId) return false;
- return r.visibility !== "public";
- };
+ // Same predicate the create / duplicate / builder surfaces use, so a
+ // runtime this picker locks is exactly the one the API and CLI refuse
+ // (MUL-6126) — no workspace-role exception on either side.
+ const isDisabled = (r: AgentRuntime): boolean =>
+ !isRuntimeUsableForUser(r, currentUserId);
// Machine grouping over the unfiltered list — resolves the selected
// runtime's machine for the trigger label regardless of the Mine/All
diff --git a/packages/views/locales/en/agents.json b/packages/views/locales/en/agents.json
index d7653c4035..29160aa5ce 100644
--- a/packages/views/locales/en/agents.json
+++ b/packages/views/locales/en/agents.json
@@ -401,7 +401,7 @@
"runtime_none": "No runtime available",
"runtime_cloud_badge": "Cloud",
"runtime_private_badge": "Private",
- "runtime_private_locked_tooltip": "Private runtime — only its owner or a workspace admin can create agents on it. Ask the owner to switch it to Public to share.",
+ "runtime_private_locked_tooltip": "Private runtime — only its owner can create agents on it. Ask the owner to switch it to Public to share.",
"runtime_search_placeholder": "Search machines…",
"runtime_no_results": "No matching machines",
"runtime_group_online": "{{online}}/{{total}} online",
diff --git a/packages/views/locales/en/runtimes.json b/packages/views/locales/en/runtimes.json
index 75bc982c67..73bea48306 100644
--- a/packages/views/locales/en/runtimes.json
+++ b/packages/views/locales/en/runtimes.json
@@ -133,9 +133,13 @@
"public": "Public"
},
"visibility_hint": {
- "private": "Only you and workspace admins can create agents on this runtime.",
+ "private": "Only you can create agents on this runtime.",
"public": "Any workspace member can create agents on this runtime."
},
+ "visibility_hint_readonly": {
+ "private": "Only the runtime owner can create agents on this runtime, and only they can switch it to Public.",
+ "public": "Any workspace member can create agents on this runtime. Only the runtime owner can switch it back to Private."
+ },
"visibility_toast_updated": "Visibility set to {{visibility}}",
"visibility_toast_failed": "Failed to update visibility",
"delete_dialog": {
diff --git a/packages/views/locales/ja/agents.json b/packages/views/locales/ja/agents.json
index a9330cb251..2726ef820f 100644
--- a/packages/views/locales/ja/agents.json
+++ b/packages/views/locales/ja/agents.json
@@ -285,7 +285,7 @@
"runtime_none": "利用可能なランタイムがありません",
"runtime_cloud_badge": "クラウド",
"runtime_private_badge": "非公開",
- "runtime_private_locked_tooltip": "非公開ランタイムです。オーナーまたはワークスペースの admin のみがこのランタイム上にエージェントを作成できます。共有するには、オーナーに公開へ切り替えるよう依頼してください。",
+ "runtime_private_locked_tooltip": "非公開ランタイムです。オーナーのみがこのランタイム上にエージェントを作成できます。共有するには、オーナーに公開へ切り替えるよう依頼してください。",
"runtime_search_placeholder": "マシンを検索…",
"runtime_no_results": "一致するマシンがありません",
"runtime_group_online": "{{online}}/{{total}} オンライン",
diff --git a/packages/views/locales/ja/runtimes.json b/packages/views/locales/ja/runtimes.json
index fa4ab16a8e..a2d81295fa 100644
--- a/packages/views/locales/ja/runtimes.json
+++ b/packages/views/locales/ja/runtimes.json
@@ -128,9 +128,13 @@
"public": "公開"
},
"visibility_hint": {
- "private": "あなたとワークスペース管理者のみが、このランタイムでエージェントを作成できます。",
+ "private": "あなたのみが、このランタイムでエージェントを作成できます。",
"public": "ワークスペースのメンバーなら誰でも、このランタイムでエージェントを作成できます。"
},
+ "visibility_hint_readonly": {
+ "private": "このランタイムでエージェントを作成できるのは所有者だけで、公開に切り替えられるのも所有者だけです。",
+ "public": "ワークスペースのメンバーなら誰でも、このランタイムでエージェントを作成できます。非公開に戻せるのは所有者だけです。"
+ },
"visibility_toast_updated": "公開範囲を {{visibility}} に設定しました",
"visibility_toast_failed": "公開範囲を更新できませんでした",
"delete_dialog": {
diff --git a/packages/views/locales/ko/agents.json b/packages/views/locales/ko/agents.json
index 440917f00b..990c980668 100644
--- a/packages/views/locales/ko/agents.json
+++ b/packages/views/locales/ko/agents.json
@@ -293,7 +293,7 @@
"runtime_none": "사용 가능한 런타임이 없습니다",
"runtime_cloud_badge": "클라우드",
"runtime_private_badge": "비공개",
- "runtime_private_locked_tooltip": "비공개 런타임입니다. 소유자 또는 워크스페이스 관리자만 이 런타임에 에이전트를 만들 수 있습니다. 공유하려면 소유자에게 공개로 전환해 달라고 요청하세요.",
+ "runtime_private_locked_tooltip": "비공개 런타임입니다. 소유자만 이 런타임에 에이전트를 만들 수 있습니다. 공유하려면 소유자에게 공개로 전환해 달라고 요청하세요.",
"runtime_search_placeholder": "기기 검색…",
"runtime_no_results": "일치하는 기기가 없습니다",
"runtime_group_online": "{{online}}/{{total}} 온라인",
diff --git a/packages/views/locales/ko/runtimes.json b/packages/views/locales/ko/runtimes.json
index 87b9708b79..ed49873fcf 100644
--- a/packages/views/locales/ko/runtimes.json
+++ b/packages/views/locales/ko/runtimes.json
@@ -128,9 +128,13 @@
"public": "공개"
},
"visibility_hint": {
- "private": "본인과 워크스페이스 관리자만 이 런타임에 에이전트를 만들 수 있습니다.",
+ "private": "본인만 이 런타임에 에이전트를 만들 수 있습니다.",
"public": "워크스페이스 멤버라면 누구나 이 런타임에 에이전트를 만들 수 있습니다."
},
+ "visibility_hint_readonly": {
+ "private": "이 런타임에 에이전트를 만들 수 있는 사람은 런타임 owner뿐이며, 공개로 바꿀 수 있는 사람도 owner뿐입니다.",
+ "public": "워크스페이스 멤버라면 누구나 이 런타임에 에이전트를 만들 수 있습니다. 다시 비공개로 바꿀 수 있는 사람은 런타임 owner뿐입니다."
+ },
"visibility_toast_updated": "공개 범위를 {{visibility}}(으)로 설정했습니다",
"visibility_toast_failed": "공개 범위를 업데이트하지 못했습니다",
"delete_dialog": {
diff --git a/packages/views/locales/zh-Hans/agents.json b/packages/views/locales/zh-Hans/agents.json
index 4e150ae17f..b94db98d60 100644
--- a/packages/views/locales/zh-Hans/agents.json
+++ b/packages/views/locales/zh-Hans/agents.json
@@ -392,7 +392,7 @@
"runtime_none": "暂无可用运行时",
"runtime_cloud_badge": "云端",
"runtime_private_badge": "私有",
- "runtime_private_locked_tooltip": "私有运行时——只有 runtime 所有者或工作区管理员可在其上创建智能体。如果需要共享,请联系所有者切换为\"公开\"。",
+ "runtime_private_locked_tooltip": "私有运行时——只有 runtime 所有者可在其上创建智能体。如果需要共享,请联系所有者切换为\"公开\"。",
"runtime_search_placeholder": "搜索机器…",
"runtime_no_results": "没有匹配的机器",
"runtime_group_online": "{{online}}/{{total}} 在线",
diff --git a/packages/views/locales/zh-Hans/runtimes.json b/packages/views/locales/zh-Hans/runtimes.json
index 8cfdbc96fe..4aacf60e87 100644
--- a/packages/views/locales/zh-Hans/runtimes.json
+++ b/packages/views/locales/zh-Hans/runtimes.json
@@ -128,9 +128,13 @@
"public": "公开"
},
"visibility_hint": {
- "private": "仅你和工作区管理员可以在此运行时上创建智能体。",
+ "private": "仅你可以在此运行时上创建智能体。",
"public": "工作区内任何成员都可以在此运行时上创建智能体。"
},
+ "visibility_hint_readonly": {
+ "private": "仅运行时所有者可以在此运行时上创建智能体,也只有他们能切换为「公开」。",
+ "public": "工作区内任何成员都可以在此运行时上创建智能体。只有运行时所有者能切回「私有」。"
+ },
"visibility_toast_updated": "可见性已设为\"{{visibility}}\"",
"visibility_toast_failed": "更新可见性失败",
"delete_dialog": {
diff --git a/packages/views/runtimes/components/runtime-detail-visibility.test.tsx b/packages/views/runtimes/components/runtime-detail-visibility.test.tsx
index bd8e3f5e7d..905ee64979 100644
--- a/packages/views/runtimes/components/runtime-detail-visibility.test.tsx
+++ b/packages/views/runtimes/components/runtime-detail-visibility.test.tsx
@@ -267,6 +267,21 @@ describe("RuntimeDetail visibility section", () => {
expect(screen.queryByText("Private")).not.toBeInTheDocument();
});
+ // MUL-6126: a workspace admin may rename or delete someone else's runtime,
+ // but not share it — sharing is the owner's consent to lend their machine,
+ // and the PATCH refuses an admin regardless of what this UI renders.
+ it("keeps visibility read-only for a workspace admin who does not own the runtime", () => {
+ mockQueryData.members = [
+ { user_id: "user-me", role: "admin" },
+ { user_id: "someone-else", role: "member" },
+ ];
+ renderDetail(
+ makeRuntime({ owner_id: "someone-else", visibility: "private" }),
+ );
+ expect(screen.getByText("Private")).toBeInTheDocument();
+ expect(screen.queryByText("Public")).not.toBeInTheDocument();
+ });
+
// MUL-3352: an owner viewing an online local (self-healing) runtime
// used to see a disabled Delete button with only a hover tooltip
// explaining why. The new contract: the button is always clickable
diff --git a/packages/views/runtimes/components/runtime-detail.tsx b/packages/views/runtimes/components/runtime-detail.tsx
index 310f4e7504..21941a92e4 100644
--- a/packages/views/runtimes/components/runtime-detail.tsx
+++ b/packages/views/runtimes/components/runtime-detail.tsx
@@ -205,7 +205,7 @@ export function RuntimeDetail({
/>
<DiagnosticsCard
runtime={runtime}
- canEdit={!!canEditRuntime}
+ canEditVisibility={!!isRuntimeOwner}
canDelete={!!canDelete}
onDelete={() => setDeleteOpen(true)}
/>
@@ -474,12 +474,18 @@ function ServingAgentsCard({
function DiagnosticsCard({
runtime,
- canEdit,
+ canEditVisibility,
canDelete,
onDelete,
}: {
runtime: AgentRuntime;
- canEdit: boolean;
+ /**
+ * Runtime owner only — narrower than the card's other affordances on
+ * purpose (MUL-6126). Sharing a machine with the workspace is the owner's
+ * call, so a workspace admin sees the read-only chip here even though they
+ * may still rename or delete the runtime.
+ */
+ canEditVisibility: boolean;
canDelete: boolean;
onDelete: () => void;
}) {
@@ -494,7 +500,7 @@ function DiagnosticsCard({
<div className="mb-1.5 text-micro uppercase tracking-wide text-muted-foreground">
{t(($) => $.detail.diagnostics_visibility)}
</div>
- {canEdit ? (
+ {canEditVisibility ? (
<VisibilityEditor runtime={runtime} />
) : (
<VisibilityReadout runtime={runtime} />
@@ -524,11 +530,13 @@ function DiagnosticsCard({
);
}
-// VisibilityReadout renders a static "Private" / "Public" pill for users
-// who can't edit the runtime. The description used to sit under the chip;
-// it now lives in the hover tooltip so the Diagnostics column stays compact
-// and matches the surrounding sections. Older backends that omit the field
-// render as "Private" to match the strict default.
+// VisibilityReadout renders a static "Private" / "Public" pill for everyone
+// who is not the runtime owner — workspace admins included (MUL-6126). Its
+// tooltip is phrased in the third person for that reason; the editor's own
+// hints stay in the second person. The description used to sit under the
+// chip; it now lives in the hover tooltip so the Diagnostics column stays
+// compact and matches the surrounding sections. Older backends that omit the
+// field render as "Private" to match the strict default.
function VisibilityReadout({ runtime }: { runtime: AgentRuntime }) {
const { t } = useT("runtimes");
const visibility = runtime.visibility === "public" ? "public" : "private";
@@ -546,15 +554,15 @@ function VisibilityReadout({ runtime }: { runtime: AgentRuntime }) {
}
/>
<TooltipContent>
- {t(($) => $.detail.visibility_hint[visibility])}
+ {t(($) => $.detail.visibility_hint_readonly[visibility])}
</TooltipContent>
</Tooltip>
);
}
-// VisibilityEditor lets the runtime owner (or workspace admin) flip
-// public↔private. The PATCH endpoint also re-checks; this is a UI gate, not
-// a security boundary. Per-choice description text lives in the hover
+// VisibilityEditor lets the runtime owner flip public↔private. Owner only —
+// the PATCH endpoint refuses a workspace admin here (canSetRuntimeVisibility);
+// this is a UI gate, not a security boundary. Per-choice description text lives in the hover
// tooltip so the two buttons stay a tight icon+label pair instead of the
// previous two-line block that competed with the surrounding cards.
function VisibilityEditor({ runtime }: { runtime: AgentRuntime }) {
diff --git a/server/cmd/server/integration_test.go b/server/cmd/server/integration_test.go
index 60c0901b76..e62cc9943a 100644
--- a/server/cmd/server/integration_test.go
+++ b/server/cmd/server/integration_test.go
@@ -126,14 +126,18 @@ func setupIntegrationTestFixture(ctx context.Context, pool *pgxpool.Pool) (strin
return "", "", err
}
+ // Owned by the fixture user, like every runtime a real daemon registers
+ // with a member credential: a private runtime is bindable only by its
+ // owner, so an ownerless one could not host the agents these tests create
+ // through the API.
var runtimeID string
if err := pool.QueryRow(ctx, `
INSERT INTO agent_runtime (
- workspace_id, daemon_id, name, runtime_mode, provider, status, device_info, metadata, last_seen_at
+ workspace_id, daemon_id, name, runtime_mode, provider, status, device_info, metadata, owner_id, last_seen_at
)
- VALUES ($1, NULL, $2, 'cloud', $3, 'online', $4, '{}'::jsonb, now())
+ VALUES ($1, NULL, $2, 'cloud', $3, 'online', $4, '{}'::jsonb, $5, now())
RETURNING id
- `, workspaceID, "Integration Test Runtime", "integration_test_runtime", "Integration test runtime").Scan(&runtimeID); err != nil {
+ `, workspaceID, "Integration Test Runtime", "integration_test_runtime", "Integration test runtime", userID).Scan(&runtimeID); err != nil {
return "", "", err
}
diff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.go
index 3958e4e82d..4ba9724222 100644
--- a/server/internal/handler/agent.go
+++ b/server/internal/handler/agent.go
@@ -1127,7 +1127,7 @@ func (h *Handler) CreateAgent(w http.ResponseWriter, r *http.Request) {
return
}
if !canUseRuntimeForAgent(member, runtime) {
- writeError(w, http.StatusForbidden, "this runtime is private; only its owner or a workspace admin can create agents on it")
+ writeError(w, http.StatusForbidden, "this runtime is private; only its owner can create agents on it")
return
}
@@ -1638,7 +1638,7 @@ func (h *Handler) UpdateAgent(w http.ResponseWriter, r *http.Request) {
return
}
if !canUseRuntimeForAgent(member, runtime) {
- writeError(w, http.StatusForbidden, "this runtime is private; only its owner or a workspace admin can move agents onto it")
+ writeError(w, http.StatusForbidden, "this runtime is private; only its owner can move agents onto it")
return
}
params.RuntimeID = runtime.ID
diff --git a/server/internal/handler/agent_builder.go b/server/internal/handler/agent_builder.go
index e29fb1bfbf..0860a7cd2c 100644
--- a/server/internal/handler/agent_builder.go
+++ b/server/internal/handler/agent_builder.go
@@ -355,7 +355,7 @@ func (h *Handler) resolveBuilderRuntime(w http.ResponseWriter, r *http.Request,
return db.AgentRuntime{}, false
}
if !canUseRuntimeForAgent(member, runtime) {
- writeError(w, http.StatusForbidden, "this runtime is private; only its owner or a workspace admin can use it")
+ writeError(w, http.StatusForbidden, "this runtime is private; only its owner can use it")
return db.AgentRuntime{}, false
}
if runtime.Status != "online" {
diff --git a/server/internal/handler/agent_builder_test.go b/server/internal/handler/agent_builder_test.go
index d5a719e76d..8dfbb9f811 100644
--- a/server/internal/handler/agent_builder_test.go
+++ b/server/internal/handler/agent_builder_test.go
@@ -1211,9 +1211,8 @@ func TestSwitchAgentBuilderRuntimeEnforcesRuntimeAndSessionOwnership(t *testing.
}
ctx := context.Background()
- // A plain member, so canUseRuntimeForAgent's owner/admin bypass does not
- // apply — the fixture user is the workspace owner and may legitimately use
- // anyone's private runtime.
+ // A plain member who owns none of the runtimes below — the fixture user
+ // owns them, and a private runtime is usable only by its owner.
var plainMemberID string
if err := testPool.QueryRow(ctx, `
INSERT INTO "user" (name, email) VALUES ('Builder Switch Plain Member', '[email protected]')
diff --git a/server/internal/handler/onboarding_shim.go b/server/internal/handler/onboarding_shim.go
index 702253f1e1..1ba3327276 100644
--- a/server/internal/handler/onboarding_shim.go
+++ b/server/internal/handler/onboarding_shim.go
@@ -189,7 +189,7 @@ func (h *Handler) BootstrapOnboardingRuntime(w http.ResponseWriter, r *http.Requ
return
}
if !canUseRuntimeForAgent(member, runtime) {
- writeError(w, http.StatusForbidden, "this runtime is private; only its owner or a workspace admin can create agents on it")
+ writeError(w, http.StatusForbidden, "this runtime is private; only its owner can create agents on it")
return
}
diff --git a/server/internal/handler/runtime.go b/server/internal/handler/runtime.go
index dc19c55b00..87d0145b4e 100644
--- a/server/internal/handler/runtime.go
+++ b/server/internal/handler/runtime.go
@@ -36,9 +36,9 @@ type AgentRuntimeResponse struct {
DeviceInfo string `json:"device_info"`
Metadata any `json:"metadata"`
OwnerID *string `json:"owner_id"`
- // Visibility is "private" (default — only the owner / workspace admins
- // can bind agents) or "public" (any workspace member can). See migration
- // 083 and canUseRuntimeForAgent.
+ // Visibility is "private" (default — only the owner can bind agents) or
+ // "public" (any workspace member can). See migration 083 and
+ // canUseRuntimeForAgent.
Visibility string `json:"visibility"`
// ProfileID is set when this runtime is an instance of a custom
// runtime_profile (MUL-3284); null for built-in runtimes.
@@ -489,8 +489,9 @@ func (h *Handler) resolveViewingTZ(r *http.Request) string {
// (provider, daemon_id, status…) flows in from the daemon and is read-only here.
type UpdateAgentRuntimeRequest struct {
// Visibility flips a runtime between "private" (default — only the owner
- // or workspace admins can bind agents) and "public" (any workspace
- // member can). Owner / workspace admin only, gated by canEditRuntime.
+ // can bind agents) and "public" (any workspace member can). Runtime owner
+ // only, gated by canSetRuntimeVisibility — narrower than the rest of this
+ // request, which admins may also send.
Visibility *string `json:"visibility,omitempty"`
// CustomName sets or clears a user-facing display override (MUL-4217).
// An empty / whitespace-only string clears it (revert to the
@@ -511,7 +512,8 @@ const maxRuntimeCustomNameLen = 100
// UpdateAgentRuntime handles PATCH /api/runtimes/:id. Currently visibility
// is editable; the request shape is open-ended so future fields (display
// name, description) can be added without a route change.
-// Workspace-membership-checked; write access is gated by canEditRuntime.
+// Workspace-membership-checked; write access is gated by canEditRuntime, and
+// `visibility` carries the narrower owner-only gate on top (MUL-6126).
func (h *Handler) UpdateAgentRuntime(w http.ResponseWriter, r *http.Request) {
runtimeID := chi.URLParam(r, "runtimeId")
runtimeUUID, ok := parseUUIDOrBadRequest(w, runtimeID, "runtime_id")
@@ -552,7 +554,16 @@ func (h *Handler) UpdateAgentRuntime(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, "visibility must be 'private' or 'public'")
return
}
+ // Only a real change is gated. An admin renaming a runtime through a
+ // PATCH-as-PUT client that echoes the unchanged visibility back is not
+ // trying to share anyone's machine, so that no-op is dropped rather
+ // than turned into a 403 — same tolerance UpdateAgent applies to
+ // resubmitted agent permissions.
if v != rt.Visibility {
+ if !canSetRuntimeVisibility(member, rt) {
+ writeError(w, http.StatusForbidden, "only the runtime owner can change its visibility")
+ return
+ }
newVisibility = v
needVisibility = true
}
@@ -667,18 +678,39 @@ func (h *Handler) runtimeHasLiveProfile(ctx context.Context, rt db.AgentRuntime)
// canUseRuntimeForAgent reports whether a workspace member is allowed to
// bind a new agent to — or move an existing agent onto — the given runtime.
-// Mirrors canEditRuntime but layers on the runtime's visibility flag so a
-// `public` runtime is usable by anyone in the workspace while a `private`
-// runtime stays bound to its owner. Workspace owners/admins keep an
-// administrative override for both. See migration 083 for the visibility
-// column.
+// A `public` runtime is usable by anyone in the workspace; a `private` one is
+// usable only by its owner, with NO workspace owner/admin override (MUL-6126):
+// a private runtime is someone's own machine, and running an agent on it
+// spends their credentials and their local files, which is not an
+// administrative decision. Sharing it is the owner's call, which is why
+// canSetRuntimeVisibility is owner-only too — otherwise an admin would keep
+// the same override with one extra step.
+//
+// An ownerless runtime is refused whatever its visibility: task claim needs an
+// owner to mint the agent's task token and cancels the task without one
+// (MUL-3292), so binding to one only produces agents that fail at run time.
+//
+// This is the same rule the clients enforce (`isRuntimeUsableForUser` in
+// packages/core/runtimes/access.ts), so UI, API and CLI agree. See migration
+// 083 for the visibility column.
func canUseRuntimeForAgent(member db.Member, rt db.AgentRuntime) bool {
- if roleAllowed(member.Role, "owner", "admin") {
- return true
+ if !rt.OwnerID.Valid {
+ return false
}
if rt.Visibility == "public" {
return true
}
+ return uuidToString(rt.OwnerID) == uuidToString(member.UserID)
+}
+
+// canSetRuntimeVisibility reports whether a member may flip this runtime
+// between `private` and `public`. Owner-only, and deliberately narrower than
+// canEditRuntime: visibility is the owner's consent to lend their machine to
+// the workspace, so an admin who could flip it would still hold the override
+// canUseRuntimeForAgent removed. Admins keep canEditRuntime for the
+// organisational actions — rename, delete — that do not hand anyone else's
+// credentials out.
+func canSetRuntimeVisibility(member db.Member, rt db.AgentRuntime) bool {
return rt.OwnerID.Valid && uuidToString(rt.OwnerID) == uuidToString(member.UserID)
}
diff --git a/server/internal/handler/runtime_visibility_test.go b/server/internal/handler/runtime_visibility_test.go
index 084f75014e..935feeb6ae 100644
--- a/server/internal/handler/runtime_visibility_test.go
+++ b/server/internal/handler/runtime_visibility_test.go
@@ -12,11 +12,14 @@ import (
)
// TestCanUseRuntimeForAgent_Pure exercises the pure predicate behind the
-// CreateAgent / UpdateAgent runtime gate. The truth table mirrors the issue
-// (MUL-2062) acceptance criteria: workspace owner / admin can use any
-// runtime, runtime owners can use their own runtime regardless of
-// visibility, and any member can use a public runtime; everyone else gets
-// denied for a private runtime owned by someone else.
+// CreateAgent / UpdateAgent runtime gate. The truth table is the single
+// product contract shared with the clients (MUL-6126): a private runtime is
+// usable only by its owner — workspace owners and admins included, since a
+// private runtime is another member's own machine — while a public runtime is
+// usable by anyone in the workspace. An ownerless runtime is usable by nobody,
+// public included: it cannot run tasks either (task claim requires a runtime
+// owner to mint the agent token, MUL-3292), so the gate refuses it up front
+// instead of letting the binding succeed and every task on it fail.
func TestCanUseRuntimeForAgent_Pure(t *testing.T) {
ownerUserID := "11111111-1111-1111-1111-111111111111"
otherUserID := "22222222-2222-2222-2222-222222222222"
@@ -29,6 +32,8 @@ func TestCanUseRuntimeForAgent_Pure(t *testing.T) {
OwnerID: util.MustParseUUID(ownerUserID),
Visibility: "public",
}
+ ownerlessPrivateRT := db.AgentRuntime{Visibility: "private"}
+ ownerlessPublicRT := db.AgentRuntime{Visibility: "public"}
cases := []struct {
name string
@@ -37,17 +42,24 @@ func TestCanUseRuntimeForAgent_Pure(t *testing.T) {
rt db.AgentRuntime
want bool
}{
- // workspace owner / admin override
- {"workspace owner on private runtime owned by another", otherUserID, "owner", privateRT, true},
- {"workspace admin on private runtime owned by another", otherUserID, "admin", privateRT, true},
+ // no workspace owner / admin override: role never widens access
+ {"workspace owner on private runtime owned by another", otherUserID, "owner", privateRT, false},
+ {"workspace admin on private runtime owned by another", otherUserID, "admin", privateRT, false},
+ {"workspace admin on someone else's public runtime", otherUserID, "admin", publicRT, true},
// runtime owner
{"runtime owner on own private runtime", ownerUserID, "member", privateRT, true},
{"runtime owner on own public runtime", ownerUserID, "member", publicRT, true},
+ {"runtime owner who is also a workspace admin", ownerUserID, "admin", privateRT, true},
// public runtime allows anyone in workspace
{"plain member on someone else's public runtime", otherUserID, "member", publicRT, true},
- // the hole the issue closes
+ // private runtime owned by someone else is denied to everyone
{"plain member on someone else's private runtime", otherUserID, "member", privateRT, false},
{"plain member with empty role on private runtime", otherUserID, "", privateRT, false},
+ // ownerless runtimes are refused whatever their visibility — nobody
+ // can be issued a task token for them (MUL-3292)
+ {"workspace owner on an ownerless private runtime", otherUserID, "owner", ownerlessPrivateRT, false},
+ {"plain member on an ownerless public runtime", otherUserID, "member", ownerlessPublicRT, false},
+ {"workspace admin on an ownerless public runtime", otherUserID, "admin", ownerlessPublicRT, false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
@@ -131,9 +143,10 @@ func runtimeVisibilityFixture(t *testing.T) (runtimeID, runtimeOwnerID, plainMem
}
// TestCreateAgent_RejectsPrivateRuntimeForNonOwner walks the gate end-to-end:
-// the runtime is private and owned by a non-admin member, so a workspace
-// owner and the runtime owner can both create agents on it, but a plain
-// workspace member cannot.
+// the runtime is private and owned by a plain member, so only that owner can
+// create agents on it. Neither a plain workspace member nor the workspace
+// owner may — the admin override is gone (MUL-6126), which is what keeps the
+// API/CLI answer identical to the disabled runtime row the web UI renders.
func TestCreateAgent_RejectsPrivateRuntimeForNonOwner(t *testing.T) {
if testHandler == nil {
t.Skip("database not available")
@@ -157,12 +170,13 @@ func TestCreateAgent_RejectsPrivateRuntimeForNonOwner(t *testing.T) {
}
}
- // Workspace owner (testUserID): allowed via admin override even though
- // the runtime is private and owned by someone else.
+ // Workspace owner (testUserID): refused. This is the API/CLI half of
+ // MUL-6126 — the web UI has always disabled this row, and an admin who
+ // needs the machine flips its visibility to public instead.
w := httptest.NewRecorder()
testHandler.CreateAgent(w, newRequest(http.MethodPost, "/api/agents", body("runtime-visibility-test-admin")))
- if w.Code != http.StatusCreated {
- t.Fatalf("CreateAgent as workspace owner: expected 201, got %d: %s", w.Code, w.Body.String())
+ if w.Code != http.StatusForbidden {
+ t.Fatalf("CreateAgent as workspace owner on another member's private runtime: expected 403, got %d: %s", w.Code, w.Body.String())
}
// Runtime owner: allowed because they own the runtime.
@@ -274,6 +288,122 @@ func TestUpdateAgent_RejectsRebindToPrivateRuntime(t *testing.T) {
}
}
+// TestUpdateAgent_WorkspaceAdminCannotRebindToMemberPrivateRuntime walks the
+// whole MUL-6126 contract as one story: a workspace owner cannot move an agent
+// onto a member's private runtime, cannot open that runtime up either, and
+// only once the runtime's own owner shares it does the same rebind go through.
+// Together those three steps are what makes owner-only real — a visibility
+// flip the admin could perform themselves would just be the old override with
+// an extra request.
+func TestUpdateAgent_WorkspaceAdminCannotRebindToMemberPrivateRuntime(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+
+ memberPrivateRuntimeID, runtimeOwnerID, _ := runtimeVisibilityFixture(t)
+
+ ctx := context.Background()
+ // The admin's own agent, on the fixture runtime they own — so the only
+ // thing this update can trip over is the runtime gate.
+ var agentID string
+ if err := testPool.QueryRow(ctx, `
+ INSERT INTO agent (
+ workspace_id, name, description, runtime_mode, runtime_config,
+ runtime_id, visibility, max_concurrent_tasks, owner_id,
+ instructions, custom_env, custom_args
+ )
+ VALUES ($1, 'admin-rebind-test-agent', '', 'cloud', '{}'::jsonb,
+ $2, 'private', 1, $3, '', '{}'::jsonb, '[]'::jsonb)
+ RETURNING id
+ `, testWorkspaceID, testRuntimeID, testUserID).Scan(&agentID); err != nil {
+ t.Fatalf("create agent on the workspace owner's runtime: %v", err)
+ }
+ t.Cleanup(func() {
+ testPool.Exec(context.Background(), `DELETE FROM agent WHERE id = $1`, agentID)
+ })
+
+ rebind := func() *httptest.ResponseRecorder {
+ w := httptest.NewRecorder()
+ req := newRequest(http.MethodPut, "/api/agents/"+agentID, map[string]any{
+ "runtime_id": memberPrivateRuntimeID,
+ })
+ testHandler.UpdateAgent(w, withURLParam(req, "id", agentID))
+ return w
+ }
+
+ setVisibility := func(actorID, visibility string) *httptest.ResponseRecorder {
+ w := httptest.NewRecorder()
+ req := newRequestAs(actorID, http.MethodPatch, "/api/runtimes/"+memberPrivateRuntimeID, map[string]any{
+ "visibility": visibility,
+ })
+ testHandler.UpdateAgentRuntime(w, withURLParam(req, "runtimeId", memberPrivateRuntimeID))
+ return w
+ }
+
+ if w := rebind(); w.Code != http.StatusForbidden {
+ t.Fatalf("UpdateAgent as workspace owner onto a member's private runtime: expected 403, got %d: %s",
+ w.Code, w.Body.String())
+ }
+
+ // …and cannot route around it by publishing the member's machine itself.
+ if w := setVisibility(testUserID, "public"); w.Code != http.StatusForbidden {
+ t.Fatalf("UpdateAgentRuntime as workspace owner on a member's runtime: expected 403, got %d: %s",
+ w.Code, w.Body.String())
+ }
+
+ // The runtime's owner shares it deliberately.
+ if w := setVisibility(runtimeOwnerID, "public"); w.Code != http.StatusOK {
+ t.Fatalf("UpdateAgentRuntime as runtime owner → public: expected 200, got %d: %s",
+ w.Code, w.Body.String())
+ }
+
+ if w := rebind(); w.Code != http.StatusOK {
+ t.Fatalf("UpdateAgent onto the same runtime once public: expected 200, got %d: %s",
+ w.Code, w.Body.String())
+ }
+}
+
+// TestCanSetRuntimeVisibility_Pure pins the narrower gate: only the runtime
+// owner may flip private↔public. Workspace owners/admins keep canEditRuntime
+// for rename and delete, but sharing a machine is the owner's call — otherwise
+// the MUL-6126 bind rule would be one PATCH away from being bypassed.
+func TestCanSetRuntimeVisibility_Pure(t *testing.T) {
+ ownerUserID := "11111111-1111-1111-1111-111111111111"
+ otherUserID := "22222222-2222-2222-2222-222222222222"
+
+ ownedRT := db.AgentRuntime{
+ OwnerID: util.MustParseUUID(ownerUserID),
+ Visibility: "private",
+ }
+ ownerlessRT := db.AgentRuntime{Visibility: "private"}
+
+ cases := []struct {
+ name string
+ userID string
+ role string
+ rt db.AgentRuntime
+ want bool
+ }{
+ {"runtime owner", ownerUserID, "member", ownedRT, true},
+ {"workspace owner who does not own the runtime", otherUserID, "owner", ownedRT, false},
+ {"workspace admin who does not own the runtime", otherUserID, "admin", ownedRT, false},
+ {"plain member", otherUserID, "member", ownedRT, false},
+ {"workspace owner on an ownerless runtime", otherUserID, "owner", ownerlessRT, false},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ member := db.Member{
+ UserID: util.MustParseUUID(tc.userID),
+ Role: tc.role,
+ }
+ if got := canSetRuntimeVisibility(member, tc.rt); got != tc.want {
+ t.Fatalf("canSetRuntimeVisibility(role=%s, caller=%s) = %v; want %v",
+ tc.role, tc.userID, got, tc.want)
+ }
+ })
+ }
+}
+
// TestUpdateAgentRuntime_VisibilityPatchApplies pins the invariant that
// a PATCH carrying `visibility` correctly updates the runtime.
func TestUpdateAgentRuntime_VisibilityPatchApplies(t *testing.T) {
@@ -366,9 +496,10 @@ func TestUpdateAgentRuntime_InvalidVisibilityReturns400(t *testing.T) {
}
}
-// TestUpdateAgentRuntime_VisibilityToggle covers the PATCH endpoint:
-// runtime owner / workspace admin can flip private↔public; plain members
-// cannot; an unknown value is rejected with 400.
+// TestUpdateAgentRuntime_VisibilityToggle covers the PATCH endpoint: the
+// runtime owner can flip private↔public; nobody else can — a workspace owner
+// is refused exactly like a plain member (MUL-6126) — and an unknown value is
+// rejected with 400.
func TestUpdateAgentRuntime_VisibilityToggle(t *testing.T) {
if testHandler == nil {
t.Skip("database not available")
@@ -399,9 +530,16 @@ func TestUpdateAgentRuntime_VisibilityToggle(t *testing.T) {
}
}
- // Workspace owner (testUserID) flips it back.
- if w := patch(testUserID, "private"); w.Code != http.StatusOK {
- t.Fatalf("UpdateAgentRuntime as workspace owner → private: expected 200, got %d: %s", w.Code, w.Body.String())
+ // Workspace owner (testUserID) cannot flip it back: canEditRuntime still
+ // admits them to this endpoint for rename/delete, and the visibility field
+ // alone is what refuses them.
+ if w := patch(testUserID, "private"); w.Code != http.StatusForbidden {
+ t.Fatalf("UpdateAgentRuntime as workspace owner → private: expected 403, got %d: %s", w.Code, w.Body.String())
+ }
+
+ // Its owner can, and the runtime is back to private for the rest of the case.
+ if w := patch(runtimeOwnerID, "private"); w.Code != http.StatusOK {
+ t.Fatalf("UpdateAgentRuntime as runtime owner → private: expected 200, got %d: %s", w.Code, w.Body.String())
}
// Plain member: forbidden, regardless of intent.
@@ -414,3 +552,38 @@ func TestUpdateAgentRuntime_VisibilityToggle(t *testing.T) {
t.Fatalf("UpdateAgentRuntime with invalid visibility: expected 400, got %d: %s", w.Code, w.Body.String())
}
}
+
+// TestUpdateAgentRuntime_AdminMayEchoUnchangedVisibility guards the edge the
+// owner-only gate must not break: an admin renaming someone else's runtime
+// through a PATCH-as-PUT client that resends the current visibility is not
+// trying to share that machine, so the no-op is dropped rather than turned
+// into a 403. Only a real change is refused.
+func TestUpdateAgentRuntime_AdminMayEchoUnchangedVisibility(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+
+ runtimeID, _, _ := runtimeVisibilityFixture(t)
+
+ w := httptest.NewRecorder()
+ req := newRequest(http.MethodPatch, "/api/runtimes/"+runtimeID, map[string]any{
+ "visibility": "private", // unchanged — the fixture runtime is private
+ "custom_name": "Renamed By Admin",
+ })
+ req = withURLParam(req, "runtimeId", runtimeID)
+ testHandler.UpdateAgentRuntime(w, req)
+ if w.Code != http.StatusOK {
+ t.Fatalf("admin rename echoing unchanged visibility: expected 200, got %d: %s", w.Code, w.Body.String())
+ }
+
+ var resp AgentRuntimeResponse
+ if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
+ t.Fatalf("decode response: %v", err)
+ }
+ if resp.CustomName == nil || *resp.CustomName != "Renamed By Admin" {
+ t.Errorf("custom name was not applied: %v", resp.CustomName)
+ }
+ if resp.Visibility != "private" {
+ t.Errorf("visibility drifted: got %q, want private", resp.Visibility)
+ }
+}