Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(spaces): Linux container create regression on 0.9.3 (CUA-1856) (#5407)
Francesco Bonaccie0c8cddff2d6
diff --git a/apps/cua-spaces-desktop/src/bridge/telemetry.ts b/apps/cua-spaces-desktop/src/bridge/telemetry.tsindex abd23bb700..85191c3a1b 100644--- a/apps/cua-spaces-desktop/src/bridge/telemetry.ts+++ b/apps/cua-spaces-desktop/src/bridge/telemetry.ts@@ -90,6 +90,32 @@ export function telemetrySignal(native: Native, raw: unknown): AppTelemetrySigna}}+/**+ * The signals of a create, power or delete step (the core's+ * `telemetry.creates`) that this app's host records itself: Electron runs+ * every create in `AppModel.runCreate`, whose `sendCreate` records them.+ * The page's store derives the same signals from its own copy of the+ * creates, so recording both counted every create twice on Windows and+ * Linux (`cua_space_create`, `cua_space_create_started`,+ * `space_create_local`, `first_space_created`, `first_space_ready`). The+ * SwiftUI host records only the page's.+ */+export function hostRecorded(raw: unknown): boolean {+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return false;+ const s = raw as Record<string, unknown>;+ switch (s.type) {+ case "space-create":+ case "space-create-started":+ return true;+ case "feature":+ return s.feature === "space_create_local" || s.feature === "space_create_cloud";+ case "step":+ return s.step === "first_space_created" || s.step === "first_space_ready";+ default:+ return false;+ }+}+/** The page's first run moved past Welcome (its usage notice was on* screen): any page left or shown other than Welcome being shown, or* "Set up later". */@@ -107,6 +133,7 @@ export function telemetryMethods({ model }: BridgeContext): Handlers {const telemetry = model.telemetry;if (!telemetry || !telemetry.status().enabled) return null;const kept = args.signals.flatMap((raw) => {+ if (hostRecorded(raw)) return [];const signal = telemetrySignal(model.native, raw);return signal ? [{ raw, signal }] : [];});diff --git a/apps/cua-spaces-desktop/src/model/app-model.ts b/apps/cua-spaces-desktop/src/model/app-model.tsindex 4d0c75fb58..1b3a9c70ba 100644--- a/apps/cua-spaces-desktop/src/model/app-model.ts+++ b/apps/cua-spaces-desktop/src/model/app-model.ts@@ -39,7 +39,7 @@ import type { CloudModel } from "./cloud";import type { DevicesModel } from "./devices";import { TeamsModel } from "./teams";import { NotchActivity } from "./activity";-import { daemonAnswered, isCancelled, words } from "./errors";+import { createErrorVariant, daemonAnswered, isCancelled, words } from "./errors";import type { HostModel } from "./host";import { KeyvaultModel } from "./keyvault";import type { AccountRunning, TelemetryRunning } from "./services";@@ -702,7 +702,7 @@ export class AppModel {return id;} catch (error) {if (isCancelled(error)) this.sendCreate(new this.native.AppCreateAction.CancelDone({ id: pendingId }));- else this.sendCreate(new this.native.AppCreateAction.Fail({ id: pendingId, error: words(error), errorVariant: "" }));+ else this.sendCreate(new this.native.AppCreateAction.Fail({ id: pendingId, error: words(error), errorVariant: createErrorVariant(error) }));throw error;}}diff --git a/apps/cua-spaces-desktop/src/model/errors.ts b/apps/cua-spaces-desktop/src/model/errors.tsindex b9b58c6992..55167d15bd 100644--- a/apps/cua-spaces-desktop/src/model/errors.ts+++ b/apps/cua-spaces-desktop/src/model/errors.ts@@ -22,6 +22,18 @@ export function sdkErrorKind(error: unknown): string | null {return typeof tag === "string" ? tag : null;}+/**+ * The error enum case a failed create records (`error_kind`): the SDK's+ * variant (`Runtime`, `DaemonNotRunning`, `ImagePull`, ...), as the SwiftUI+ * app sends it, or "" for anything else (the app core then reads the cause+ * from the text). Electron sent "" for every failure, so its creates showed+ * almost only `other`.+ */+export function createErrorVariant(error: unknown): string {+ const kind = sdkErrorKind(error);+ return kind && /^[A-Za-z0-9_]{1,64}$/.test(kind) ? kind : "";+}+/** A create ended because it was cancelled (here, or `cua spaces cancel`), not because it failed. */export const isCancelled = (error: unknown) => sdkErrorKind(error) === "Cancelled";diff --git a/apps/cua-spaces-desktop/test/bridge-native.test.ts b/apps/cua-spaces-desktop/test/bridge-native.test.tsindex ac018b1289..ebc1869da2 100644--- a/apps/cua-spaces-desktop/test/bridge-native.test.ts+++ b/apps/cua-spaces-desktop/test/bridge-native.test.ts@@ -20,7 +20,7 @@ import { OPERATIONS, type OpArgs, type OpName } from "../../cua-spaces-web/src/bimport { createBridge, type Bridge } from "../src/bridge";import type { BridgeEvent } from "../src/bridge/host";import { createOptions } from "../src/bridge/spaces";-import { telemetrySignal } from "../src/bridge/telemetry";+import { hostRecorded, telemetrySignal } from "../src/bridge/telemetry";import { AppModel } from "../src/model/app-model";import { CloudModel } from "../src/model/cloud";import { DevicesModel } from "../src/model/devices";@@ -332,11 +332,11 @@ describe.skipIf(!built)("the bridge on the app core", () => {signals: [{ type: "feature", feature: "space_open" },{ type: "feature", feature: "Not A Word" },- { type: "space-create", location: "local", guestOs: "linux", kind: "container", outcome: "ready", failedPhase: "none", stalled: false, elapsedMs: 1200, gpu: false, errorVariant: "" },+ { type: "space-wizard", action: "opened" },],});const after = telemetry.recorded.slice(-2);- expect(after.map((s) => (s as unknown as { tag: string }).tag)).toEqual(["Feature", "SpaceCreate"]);+ expect(after.map((s) => (s as unknown as { tag: string }).tag)).toEqual(["Feature", "SpaceWizard"]);telemetry.current = { ...telemetry.current, enabled: false };const before = telemetry.recorded.length;await call("telemetry.track", { signals: [{ type: "feature", feature: "space_open" }] });@@ -347,6 +347,26 @@ describe.skipIf(!built)("the bridge on the app core", () => {expect(telemetrySignal(native, { type: "launched", onboardingEligible: null })).not.toBeNull();});+ it("leaves a create's signals to the host, which records them from the create it runs", async () => {+ const before = telemetry.recorded.length;+ await call("telemetry.track", {+ signals: [+ { type: "feature", feature: "space_create_local" },+ { type: "space-create-started", location: "local", guestOs: "linux", kind: "container", gpu: false },+ { type: "step", step: "first_space_created", ok: true },+ { type: "space-create", location: "local", guestOs: "linux", kind: "container", outcome: "error", failedPhase: "preparing", stalled: false, elapsedMs: 900, gpu: false, errorVariant: "" },+ { type: "step", step: "first_space_ready", ok: true },+ ],+ });+ expect(telemetry.recorded.length).toBe(before);+ // The page's other signals still count.+ await call("telemetry.track", { signals: [{ type: "feature", feature: "space_open" }, { type: "step", step: "onboarding_shown", ok: true }] });+ expect(telemetry.recorded.length).toBe(before + 2);+ expect(hostRecorded({ type: "feature", feature: "space_create_cloud" })).toBe(true);+ expect(hostRecorded({ type: "step", step: "checklist_create_space", ok: true })).toBe(false);+ expect(hostRecorded(null)).toBe(false);+ });+it("records that the usage notice was seen once the first run leaves Welcome", async () => {telemetry.current = { enabled: true, lockedBy: undefined, noticeShown: false };const before = telemetry.acknowledged;diff --git a/apps/cua-spaces-desktop/test/live-telemetry.test.ts b/apps/cua-spaces-desktop/test/live-telemetry.test.tsindex 645011a3a7..b659c5c8b2 100644--- a/apps/cua-spaces-desktop/test/live-telemetry.test.ts+++ b/apps/cua-spaces-desktop/test/live-telemetry.test.ts@@ -6,7 +6,8 @@// first session's signals until Welcome is left, then sends them in order// (CUA-1739: Windows and Linux sent no first run, sign-in or Space events).import { describe, expect, it } from "vitest";-import { leftWelcome } from "../src/bridge/telemetry";+import { hostRecorded, leftWelcome } from "../src/bridge/telemetry";+import { createErrorVariant } from "../src/model/errors";import { LiveTelemetry } from "../src/model/services";import type { Native } from "../src/native/load";@@ -106,3 +107,43 @@ describe("leaving Welcome", () => {expect(leftWelcome(null)).toBe(false);});});++describe("a create's signals from the page", () => {+ // The host records them from the create it runs (AppModel.sendCreate):+ // the page's copies counted every Windows and Linux create twice.+ it("are left to the host; the page's other signals are not", () => {+ for (const raw of [+ { type: "space-create", outcome: "error" },+ { type: "space-create-started" },+ { type: "feature", feature: "space_create_local" },+ { type: "feature", feature: "space_create_cloud" },+ { type: "step", step: "first_space_created", ok: true },+ { type: "step", step: "first_space_ready", ok: true },+ ]) {+ expect(hostRecorded(raw)).toBe(true);+ }+ for (const raw of [+ { type: "feature", feature: "space_open" },+ { type: "step", step: "checklist_create_space", ok: true },+ { type: "space-wizard", action: "opened" },+ { type: "onboarding-page", page: "done", action: "shown", choice: "none" },+ null,+ [],+ ]) {+ expect(hostRecorded(raw)).toBe(false);+ }+ });+});++describe("a failed create's error case", () => {+ const sdkError = (tag: string) => Object.assign(new Error(`CuaError.${tag}: boom`), { [Symbol.for("typeName")]: "CuaError", tag });+ it("is the SDK's variant, as the SwiftUI app records it", () => {+ expect(createErrorVariant(sdkError("DaemonNotRunning"))).toBe("DaemonNotRunning");+ expect(createErrorVariant(sdkError("Runtime"))).toBe("Runtime");+ });+ it("is empty for anything else, so the core reads the cause from the text", () => {+ expect(createErrorVariant(new Error("socket hang up"))).toBe("");+ expect(createErrorVariant(sdkError("not a word"))).toBe("");+ expect(createErrorVariant("text")).toBe("");+ });+});