Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces-web): a message from Home starts a new Home Space (#6612)

ddupont5101142e8e45
diff --git a/apps/cua-spaces-web/src/__tests__/agent-home-box.test.tsx b/apps/cua-spaces-web/src/__tests__/agent-home-box.test.tsx
index 60a67d9f5e..e101c159a7 100644
--- a/apps/cua-spaces-web/src/__tests__/agent-home-box.test.tsx
+++ b/apps/cua-spaces-web/src/__tests__/agent-home-box.test.tsx
@@ -85,7 +85,7 @@ describe.skipIf(!wasmBuilt)("the box with an agent home", () => {
await waitFor(() => expect(askTasks()[0]).toMatchObject({ home: true, inSpace: true }));
});
- it("reuses the agent's Home when it already has one, with no second create", async () => {
+ it("starts a new Home for a Home message, and continues the existing one only when it is picked", async () => {
const calls: { op: string; args: Record<string, unknown> }[] = [];
const { router } = await mountApp("/home", { ...HOME, intercept: (op, args) => (calls.push({ op, args: args as Record<string, unknown> }), undefined) });
const box = (await screen.findByLabelText("What should it do?")) as HTMLTextAreaElement;
@@ -95,13 +95,33 @@ describe.skipIf(!wasmBuilt)("the box with an agent home", () => {
await waitFor(() => expect(q("[data-ask-agent]")!.textContent).toBe("Claude Code"));
// The tree is read from the host and the Home is found by its label.
await new Promise((r) => setTimeout(r, 300));
+ // A plain Home message makes a new Home, even though the agent already has one.
fireEvent.change(box, { target: { value: "run the tests" } });
await act(async () => {
fireEvent.keyDown(box, { key: "Enter" });
});
- await waitFor(() => expect(router.state.location.pathname).toBe("/spaces/local%3Aagent-home-demo"));
+ await waitFor(() => expect(calls.some((c) => c.op === "spaces.create")).toBe(true));
+ await waitFor(() => expect(router.state.location.pathname).toMatch(/^\/spaces\/(?!local%3Aagent-home-demo)/));
+ // Picking "in your existing Home" continues it: no second create, the job goes to the existing Home.
+ await act(async () => {
+ await router.navigate({ to: "/home" });
+ });
+ calls.length = 0;
+ const box2 = (await screen.findByLabelText("What should it do?")) as HTMLTextAreaElement;
+ fireEvent.change(box2, { target: { value: "run the tests on @" } });
+ await act(async () => {
+ fireEvent.click(await waitFor(() => q('[data-picker="where"]')!));
+ });
+ await act(async () => {
+ fireEvent.click(await screen.findByText("Let the agent decide, in your existing Home"));
+ });
+ fireEvent.change(box2, { target: { value: "run the tests again" } });
+ await act(async () => {
+ fireEvent.keyDown(box2, { key: "Enter" });
+ });
+ await waitFor(() => expect(router.state.location.pathname).toMatch(/^\/spaces\/local%3A(home-run-the-tests|agent-home-demo)/));
expect(calls.some((c) => c.op === "spaces.create")).toBe(false);
- await waitFor(() => expect(calls.some((c) => c.op === "thread.post" && c.args.text === "@claude run the tests")).toBe(true), { timeout: 15000 });
+ await waitFor(() => expect(calls.some((c) => c.op === "thread.post" && c.args.text === "@claude run the tests again")).toBe(true), { timeout: 15000 });
});
it("names the Space's handle for the Home's agent, never the host's unique name for it", async () => {
@@ -112,7 +132,7 @@ describe.skipIf(!wasmBuilt)("the box with an agent home", () => {
...HOME,
intercept: (op, args) => {
calls.push({ op, args: args as Record<string, unknown> });
- return op === "thread.members" && (args as { spaceId: string }).spaceId === "local:agent-home-demo" ? { members: [member] } : undefined;
+ return op === "thread.members" ? { members: [member] } : undefined;
},
});
const box = (await screen.findByLabelText("What should it do?")) as HTMLTextAreaElement;
@@ -124,7 +144,8 @@ describe.skipIf(!wasmBuilt)("the box with an agent home", () => {
await act(async () => {
fireEvent.keyDown(box, { key: "Enter" });
});
- await waitFor(() => expect(router.state.location.pathname).toBe("/spaces/local%3Aagent-home-demo"));
+ // A Home message makes a new Home; the handle is still the Space's own.
+ await waitFor(() => expect(router.state.location.pathname).toMatch(/^\/spaces\//));
await waitFor(() => expect(calls.some((c) => c.op === "thread.post" && c.args.text === "@claude hi")).toBe(true), { timeout: 15000 });
// Adding the standby agent names the handle too (it is the same member), and nothing is posted to @claude-8.
expect(calls.filter((c) => c.op === "thread.agentAdd").every((c) => c.args.name === "claude")).toBe(true);
diff --git a/apps/cua-spaces-web/src/components/ask-first/ask-box.tsx b/apps/cua-spaces-web/src/components/ask-first/ask-box.tsx
index 227e37790a..84dee91f1d 100644
--- a/apps/cua-spaces-web/src/components/ask-first/ask-box.tsx
+++ b/apps/cua-spaces-web/src/components/ask-first/ask-box.tsx
@@ -28,7 +28,7 @@ const OS_WORD: Record<SpaceOs, string> = { linux: "Linux", macos: "Mac", windows
/** Where it runs is a Space: "New Space", then quieter "Linux on This Mac". */
export function whereSpaceLabel(where: TaskWhere): { title: string; detail: string | null } {
- if (where.kind === "agent") return { title: where.fresh ? "Agent decides, new Home" : "Agent decides", detail: null };
+ if (where.kind === "agent") return { title: where.reuse ? "Agent decides, existing Home" : "Agent decides", detail: null };
if (where.kind === "machine") return { title: where.machine.name, detail: null };
if (where.kind === "new") return { title: "New Space", detail: `${OS_WORD[where.os]} on ${where.on?.name ?? thisComputerLabel()}` };
return { title: where.kind === "this-mac" ? thisComputerLabel() : where.space.name, detail: null };
@@ -176,7 +176,7 @@ export function AskBox({
machines?: NameableMachine[];
/** The job goes to the agent's Home Space, which makes the Spaces it needs: no where picker until a place is named. */
agentHome?: boolean;
- /** The person already has a Home Space: the picker offers a fresh one. */
+ /** The person already has a Home Space: the picker offers to continue in it. */
hasHome?: boolean;
busy: boolean;
onSubmit: () => void;
@@ -197,7 +197,7 @@ export function AskBox({
const label = whereSpaceLabel(where);
// With agent homes the agent decides where, so nothing about it shows until the person names a place: with @ in the
// text, or by picking one (the "..." button then shows).
- const placed = where.kind !== "agent" || Boolean(where.fresh);
+ const placed = where.kind !== "agent" || Boolean(where.reuse);
const naming = placed || /(^|\s)@/.test(text);
return (
<div data-ask-box="" className="rounded-2xl border bg-card shadow-xs dark:bg-white/[0.03]">
@@ -346,7 +346,7 @@ export function WherePicker({
machines?: NameableMachine[];
/** Leads with "Let the agent decide". */
agentHome?: boolean;
- /** The person already has a Home Space (the next request reuses it): offers a fresh one. */
+ /** The person already has a Home Space: offers to continue in it (a request starts a new Home otherwise). */
hasHome?: boolean;
trigger: ReactElement;
open?: boolean;
@@ -407,7 +407,7 @@ export function WherePicker({
}
title="Let the agent decide"
note="It picks what the job needs, within your budget"
- selected={where?.kind === "agent" && !where.fresh}
+ selected={where?.kind === "agent" && !where.reuse}
onSelect={() => onWhere({ kind: "agent" })}
/>
) : null}
@@ -418,10 +418,10 @@ export function WherePicker({
<SparklesIcon className="size-4" />
</span>
}
- title="Let the agent decide, in a new Home"
- note="Starts a fresh Home Space instead of reusing yours"
- selected={where?.kind === "agent" && Boolean(where.fresh)}
- onSelect={() => onWhere({ kind: "agent", fresh: true })}
+ title="Let the agent decide, in your existing Home"
+ note="Continues in the Home you already have instead of starting a new one"
+ selected={where?.kind === "agent" && Boolean(where.reuse)}
+ onSelect={() => onWhere({ kind: "agent", reuse: true })}
/>
) : null}
{agentHome ? (
diff --git a/apps/cua-spaces-web/src/components/ask-first/use-start-task.ts b/apps/cua-spaces-web/src/components/ask-first/use-start-task.ts
index a4ff25da0b..5ceaa3521d 100644
--- a/apps/cua-spaces-web/src/components/ask-first/use-start-task.ts
+++ b/apps/cua-spaces-web/src/components/ask-first/use-start-task.ts
@@ -11,7 +11,7 @@ import { enqueue, flushQueue, resolveQueue } from "@/components/space-thread/que
import { useConnectors } from "@/hooks/use-connectors";
import { containerHome } from "@/lib/agent-home/container";
import { grantsFor, homeGrantsArg, homeMentionsArg } from "@/lib/agent-home/grants";
-import { rememberHome, reusableHome } from "@/lib/agent-home/home-space";
+import { homeForRequest, rememberHome } from "@/lib/agent-home/home-space";
import { parseMentions } from "@/lib/agent-home/mentions";
import { homeBrief, homePrompt } from "@/lib/agent-home/prompt";
import type { AskRepo } from "@/lib/ask-first-repo";
@@ -45,9 +45,11 @@ const posted = new Set<string>();
* (`retry(task, where)`).
*
* With Child Spaces on and the agent left to decide (or a computer named), the
- * Space is the agent's home (CUA-2630): the slim Linux image, made on the first
- * request and reused by the next ones (one per agent unless the person asks for
- * a fresh one), its spawn capability on. The agent decides where the work runs,
+ * Space is the agent's home (CUA-2630): the slim Linux image, a new one for
+ * every request from Home (cheap: it claims a warm Space), its spawn capability
+ * on. An existing home is continued only when the person picks it ("Let the agent
+ * decide, in your existing Home"), opens it from Your agents or Spaces (its thread
+ * posts in place), or retries a task (which keeps the Space it was made in). The agent decides where the work runs,
* unless the person said where, and the Spaces it makes appear under the home.
*/
export function useStartTask(): {
@@ -112,7 +114,7 @@ export function useStartTask(): {
if (!spaceId) throw new Error(HOST_NOT_SHARED);
updateAskTask(id, { spaceId, onHost: true });
}
- // The agent's home is made on the first request and reused by the next ones.
+ // A home the person chose to continue (`place.reuse`); otherwise one is made below.
if (!spaceId && isHome && place?.reuse) {
spaceId = place.reuse;
updateAskTask(id, { spaceId, pendingId: null });
@@ -188,9 +190,8 @@ export function useStartTask(): {
const target = taskTarget(where);
// With Child Spaces on, the agent decides (or is told a computer): its home Space takes the request.
const home = Boolean(children) && (where.kind === "agent" || where.kind === "machine");
- const fresh = where.kind === "agent" && Boolean(where.fresh);
const mentions = named(prompt, where);
- const reuse = home ? reusableHome(agent, spaces, fresh, children?.homesOf(agent)) : null;
+ const reuse = home ? homeForRequest(where, agent, spaces, children?.homesOf(agent)) : null;
// The new setup (Labs) made a Linux Space for this agent while the person was in the first run: the job is
// kept by the preparing driver, which sends it exactly once when the agent is ready, even across a quit.
const preparing = getDriver();
diff --git a/apps/cua-spaces-web/src/lib/agent-home/agent-home.test.ts b/apps/cua-spaces-web/src/lib/agent-home/agent-home.test.ts
index 9f73be2671..aa4274b9d9 100644
--- a/apps/cua-spaces-web/src/lib/agent-home/agent-home.test.ts
+++ b/apps/cua-spaces-web/src/lib/agent-home/agent-home.test.ts
@@ -14,7 +14,8 @@ import { allowListAll, allowMachine, grantsFor, homeMentionsArg, resetGrants } f
import { parseMentions, saidWhere } from "./mentions";
import { abilityOfAction, approvalAction, homePrompt } from "./prompt";
import { askText, covered, openAbilityRequests } from "./requests";
-import { forgetHome, homeSpaceId, isHomeSpaceId, rememberHome, resetHomes, reusableHome } from "./home-space";
+import { retryTarget } from "@/lib/ask-first";
+import { forgetHome, homeSpaceId, isHomeSpaceId, homeForRequest, rememberHome, resetHomes, reusableHome } from "./home-space";
beforeEach(() => {
localStorage.clear();
@@ -218,4 +219,27 @@ describe("the home Space is made once and reused", () => {
rememberHome("claude-code", "local:other");
expect(reusableHome("claude-code", spaces, false, ["local:home-a"])).toBe("local:other");
});
+
+ it("a message from Home makes a new home every time; only picking the existing home continues it", () => {
+ rememberHome("claude-code", "local:home-a");
+ // First and second Home messages: neither reuses, so each makes its own home.
+ expect(homeForRequest({ kind: "agent" }, "claude-code", spaces, ["local:home-a"])).toBeNull();
+ expect(homeForRequest({ kind: "machine" }, "claude-code", spaces, ["local:home-a"])).toBeNull();
+ // The second home is remembered as the newest; the first stays in the list.
+ rememberHome("claude-code", "local:home-b");
+ expect(homeSpaceId("claude-code")).toBe("local:home-b");
+ expect(isHomeSpaceId("local:home-a")).toBe(false);
+ // Explicitly continuing the existing home reuses it (the newest, found again by label on a new device).
+ const both = [{ id: "local:home-a", status: "running" as const }, { id: "local:home-b", status: "running" as const }];
+ expect(homeForRequest({ kind: "agent", reuse: true }, "claude-code", both, ["local:home-a"])).toBe("local:home-b");
+ // A home that is gone is not reused even when asked.
+ expect(homeForRequest({ kind: "agent", reuse: true }, "claude-code", [], [])).toBeNull();
+ // A picked Space is not a home request at all.
+ expect(homeForRequest({ kind: "space" }, "claude-code", both)).toBeNull();
+ });
+
+ it("retry keeps the Space the task was made in (a new home only when none was made yet)", () => {
+ expect(retryTarget({ spaceId: "local:home-a", os: "linux", onHost: false })).toEqual({ kind: "space", spaceId: "local:home-a" });
+ expect(retryTarget({ spaceId: null, os: "linux", onHost: false })).toEqual({ kind: "create", os: "linux" });
+ });
});
diff --git a/apps/cua-spaces-web/src/lib/agent-home/home-space.ts b/apps/cua-spaces-web/src/lib/agent-home/home-space.ts
index 0d77ff644b..71ae5d978b 100644
--- a/apps/cua-spaces-web/src/lib/agent-home/home-space.ts
+++ b/apps/cua-spaces-web/src/lib/agent-home/home-space.ts
@@ -2,14 +2,15 @@
// Copyright (c) 2026 Cua AI, Inc.
/**
- * The agent home is a Space like any other (CUA-2630): made on the first
- * request, reused by the next ones, listed with the person's Spaces. This
- * remembers, per agent on this device, which Space is its home so a later
- * request goes to the same one (`localStorage`, like the grants), and lets
- * the Spaces list tag it "Home".
- *
- * One home per person and agent unless they ask for a fresh one: a fresh one
- * replaces the remembered id; the old Space stays in the list as any Space.
+ * The agent home is a Space like any other (CUA-2630), listed with the person's
+ * Spaces. A message typed on Home makes a NEW home every time (cheap: it claims
+ * a warm Space); the earlier homes and their agents stay in the list. This
+ * remembers, per agent on this device, the newest home (`localStorage`, like the
+ * grants), which is the one continued when the person explicitly picks "Let the
+ * agent decide, in your existing Home", and lets the Spaces list tag it "Home".
+ * Opening a Space (from Your agents or Spaces) and writing in its thread never
+ * goes through here: it posts to that Space. Many homes can accumulate (1 CPU and
+ * 1 GB each), so idle ones are worth stopping.
*/
import { useSyncExternalStore } from "react";
@@ -89,6 +90,20 @@ export function reusableHome(agent: string, spaces: readonly HomeCandidate[] | u
return found ? found.id : null;
}
+/**
+ * The home a Home-composer request goes to: none (a new home is made) unless the person picked "Let the
+ * agent decide, in your existing Home" (`where.reuse`). Naming a Space or a computer, or any other place, never reuses.
+ */
+export function homeForRequest(
+ where: { kind: string; reuse?: boolean },
+ agent: string,
+ spaces: readonly HomeCandidate[] | undefined,
+ labelled: readonly string[] = [],
+): string | null {
+ const continuing = where.kind === "agent" && Boolean(where.reuse);
+ return reusableHome(agent, spaces, !continuing, labelled);
+}
+
const subscribe = (l: () => void) => {
listeners.add(l);
const onStorage = (e: StorageEvent) => {
diff --git a/apps/cua-spaces-web/src/lib/ask-first.ts b/apps/cua-spaces-web/src/lib/ask-first.ts
index 7f597c19f8..61c36f8049 100644
--- a/apps/cua-spaces-web/src/lib/ask-first.ts
+++ b/apps/cua-spaces-web/src/lib/ask-first.ts
@@ -233,7 +233,7 @@ export type TaskWhere =
| { kind: "new"; os: SpaceOs; on?: NewSpaceOn }
| { kind: "space"; space: Space }
| { kind: "this-mac" }
- | { kind: "agent"; fresh?: boolean }
+ | { kind: "agent"; /** Continue in the agent's existing Home; absent, a message starts a new Home. */ reuse?: boolean }
| { kind: "machine"; machine: { id: string; name: string } };
/** Another of your computers a new Space is made on ("New Space on Studio Mac mini"); absent: this Mac. */