mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-23 10:55:31 -06:00
fix(codex): stop Computer Use readiness stalls across fallbacks (#113393)
* fix(codex): bound computer use readiness preflight * chore(codex): keep service status internal
This commit is contained in:
@@ -3,9 +3,10 @@ import { randomUUID } from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type {
|
||||
CodexBundleMcpThreadConfig,
|
||||
EmbeddedRunAttemptParams,
|
||||
import {
|
||||
AgentHarnessPreflightError,
|
||||
type CodexBundleMcpThreadConfig,
|
||||
type EmbeddedRunAttemptParams,
|
||||
} from "openclaw/plugin-sdk/agent-harness-runtime";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { startCodexAttemptThread } from "./attempt-startup.js";
|
||||
@@ -674,7 +675,9 @@ describe("startCodexAttemptThread", () => {
|
||||
});
|
||||
|
||||
await expect(run).rejects.toThrow("stop after option capture");
|
||||
expect(clientFactory).toHaveBeenCalledWith(expect.objectContaining({ preparedAuth }));
|
||||
expect(clientFactory).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ preparedAuth, pluginConfig }),
|
||||
);
|
||||
expect(clientFactory.mock.calls[0]?.[0]?.preparedAuth).toBe(preparedAuth);
|
||||
expect(clientFactory).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ authProfileId: expect.anything() }),
|
||||
@@ -818,9 +821,10 @@ describe("startCodexAttemptThread", () => {
|
||||
await vi.advanceTimersByTimeAsync(1_000);
|
||||
|
||||
const error = await runError;
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect(isCodexAppServerRequestTimeoutError(error)).toBe(true);
|
||||
expect((error as Error).message).toBe("plugin/list timed out");
|
||||
expect(error).toBeInstanceOf(AgentHarnessPreflightError);
|
||||
const cause = (error as Error).cause;
|
||||
expect(isCodexAppServerRequestTimeoutError(cause)).toBe(true);
|
||||
expect((cause as Error).message).toBe("plugin/list timed out");
|
||||
expect(harness.process.stdin.destroyed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* leasing, plugin thread config, sandbox environment, and thread lifecycle binding.
|
||||
*/
|
||||
import {
|
||||
AgentHarnessPreflightError,
|
||||
embeddedAgentLog,
|
||||
formatErrorMessage,
|
||||
type AgentHarnessRuntimeArtifactBinding,
|
||||
@@ -226,6 +227,7 @@ export async function startCodexAttemptThread(params: {
|
||||
const attemptParams = params.buildAttemptParams();
|
||||
startupClient = await params.attemptClientFactory({
|
||||
startOptions: params.appServer.start,
|
||||
pluginConfig: params.pluginConfig,
|
||||
...(params.startupPreparedAuth
|
||||
? { preparedAuth: params.startupPreparedAuth }
|
||||
: { authProfileId: params.startupAuthProfileId }),
|
||||
@@ -313,14 +315,24 @@ export async function startCodexAttemptThread(params: {
|
||||
config: params.config,
|
||||
});
|
||||
const turnRouter = getCodexAppServerTurnRouter(activeStartupClient);
|
||||
await ensureCodexComputerUse({
|
||||
client: activeStartupClient,
|
||||
pluginConfig: params.pluginConfig,
|
||||
config: params.config,
|
||||
agentDir: params.agentDir,
|
||||
timeoutMs: params.appServer.requestTimeoutMs,
|
||||
signal: startupAbandonController.signal,
|
||||
});
|
||||
try {
|
||||
await ensureCodexComputerUse({
|
||||
client: activeStartupClient,
|
||||
pluginConfig: params.pluginConfig,
|
||||
config: params.config,
|
||||
agentDir: params.agentDir,
|
||||
timeoutMs: params.appServer.requestTimeoutMs,
|
||||
signal: startupAbandonController.signal,
|
||||
});
|
||||
} catch (error) {
|
||||
if (startupAbandonController.signal.aborted) {
|
||||
throw error;
|
||||
}
|
||||
throw new AgentHarnessPreflightError(
|
||||
`Codex Computer Use readiness failed: ${formatErrorMessage(error)}`,
|
||||
{ cause: error },
|
||||
);
|
||||
}
|
||||
const startupRuntimeIdentity = activeStartupClient.getRuntimeIdentity();
|
||||
const pluginAppCacheKey = buildCodexPluginAppCacheKey({
|
||||
appServer: params.appServer,
|
||||
|
||||
@@ -30,6 +30,13 @@ const oauthMocks = vi.hoisted(() => ({
|
||||
refreshOpenAICodexToken: vi.fn(),
|
||||
}));
|
||||
|
||||
const computerUseServiceMocks = vi.hoisted(() => ({
|
||||
ensureCodexComputerUseServiceApp: vi.fn(async () => ({
|
||||
status: "already_installed" as const,
|
||||
changed: false,
|
||||
})),
|
||||
}));
|
||||
|
||||
const providerRuntimeMocks = vi.hoisted(() => ({
|
||||
formatProviderAuthProfileApiKeyWithPlugin: vi.fn(),
|
||||
refreshProviderOAuthCredentialWithPlugin: vi.fn(
|
||||
@@ -117,12 +124,17 @@ vi.mock("openclaw/plugin-sdk/agent-runtime", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./computer-use-service.js", () => ({
|
||||
ensureCodexComputerUseServiceApp: computerUseServiceMocks.ensureCodexComputerUseServiceApp,
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
clearRuntimeAuthProfileStoreSnapshots();
|
||||
oauthMocks.refreshOpenAICodexToken.mockReset();
|
||||
providerRuntimeMocks.formatProviderAuthProfileApiKeyWithPlugin.mockReset();
|
||||
providerRuntimeMocks.refreshProviderOAuthCredentialWithPlugin.mockClear();
|
||||
computerUseServiceMocks.ensureCodexComputerUseServiceApp.mockClear();
|
||||
});
|
||||
|
||||
function createStartOptions(
|
||||
@@ -241,6 +253,50 @@ describe("bridgeCodexAppServerStartOptions", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("provisions the native Computer Use client before auto-install startup", async () => {
|
||||
await withTempDir("openclaw-codex-computer-use-service-", async (agentDir) => {
|
||||
const startOptions = createStartOptions();
|
||||
const codexHome = resolveCodexAppServerHomeDir(agentDir);
|
||||
|
||||
await bridgeCodexAppServerStartOptions({
|
||||
startOptions,
|
||||
agentDir,
|
||||
pluginConfig: { computerUse: { enabled: true, autoInstall: true } },
|
||||
});
|
||||
|
||||
expect(computerUseServiceMocks.ensureCodexComputerUseServiceApp).toHaveBeenCalledWith({
|
||||
codexHome,
|
||||
appServerCommand: startOptions.command,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("does not provision the native client without auto-install authorization", async () => {
|
||||
await withTempDir("openclaw-codex-computer-use-service-", async (agentDir) => {
|
||||
await bridgeCodexAppServerStartOptions({
|
||||
startOptions: createStartOptions(),
|
||||
agentDir,
|
||||
pluginConfig: { computerUse: { enabled: true, autoInstall: false } },
|
||||
});
|
||||
|
||||
expect(computerUseServiceMocks.ensureCodexComputerUseServiceApp).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("classifies native client provisioning failures as harness preflight", async () => {
|
||||
computerUseServiceMocks.ensureCodexComputerUseServiceApp.mockRejectedValueOnce(
|
||||
new Error("copy failed"),
|
||||
);
|
||||
|
||||
await expect(
|
||||
bridgeCodexAppServerStartOptions({
|
||||
startOptions: createStartOptions(),
|
||||
agentDir: "/tmp/openclaw-codex-computer-use-failed",
|
||||
pluginConfig: { computerUse: { enabled: true, autoInstall: true } },
|
||||
}),
|
||||
).rejects.toMatchObject({ name: "AgentHarnessPreflightError" });
|
||||
});
|
||||
|
||||
it("uses the native user Codex home for coexistence mode", async () => {
|
||||
await withTempDir("openclaw-codex-user-home-", async (root) => {
|
||||
const agentDir = path.join(root, "agent");
|
||||
|
||||
@@ -6,6 +6,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import { AgentHarnessPreflightError } from "openclaw/plugin-sdk/agent-harness-runtime";
|
||||
import {
|
||||
ensureAuthProfileStore,
|
||||
findPersistedAuthProfileCredential,
|
||||
@@ -24,6 +25,7 @@ import { hasUsableOAuthCredential } from "openclaw/plugin-sdk/provider-auth";
|
||||
import { resolveCodexAppServerHomeDir, withEphemeralCodexAuthStore } from "./auth-start-options.js";
|
||||
import type { CodexAppServerClient } from "./client.js";
|
||||
import { ensureCodexComputerUseSharedPluginCache } from "./computer-use-cache.js";
|
||||
import { ensureCodexComputerUseServiceApp } from "./computer-use-service.js";
|
||||
import {
|
||||
resolveCodexAppServerUserHomeDir,
|
||||
resolveCodexComputerUseConfig,
|
||||
@@ -437,10 +439,23 @@ async function withCodexHomeEnvironment(
|
||||
? startOptions.env[HOME_ENV_VAR]
|
||||
: undefined;
|
||||
await fs.mkdir(codexHome, { recursive: true });
|
||||
const computerUseConfig = resolveCodexComputerUseConfig({ pluginConfig });
|
||||
await ensureCodexComputerUseSharedPluginCache({
|
||||
codexHome,
|
||||
config: resolveCodexComputerUseConfig({ pluginConfig }),
|
||||
config: computerUseConfig,
|
||||
});
|
||||
if (computerUseConfig.enabled && computerUseConfig.autoInstall) {
|
||||
try {
|
||||
await ensureCodexComputerUseServiceApp({
|
||||
codexHome,
|
||||
appServerCommand: startOptions.command,
|
||||
});
|
||||
} catch (error) {
|
||||
throw new AgentHarnessPreflightError("Codex Computer Use client provisioning failed.", {
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (nativeHome) {
|
||||
await fs.mkdir(nativeHome, { recursive: true });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
// Codex tests cover native Computer Use service provisioning.
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { ensureCodexComputerUseServiceApp } from "./computer-use-service.js";
|
||||
import { resolveMacOSDesktopCodexComputerUseServiceAppCandidates } from "./desktop-app-paths.js";
|
||||
import { useAutoCleanupTempDirTracker } from "./test-support.js";
|
||||
|
||||
const CLIENT_RELATIVE_PATH = path.join(
|
||||
"Contents",
|
||||
"SharedSupport",
|
||||
"SkyComputerUseClient.app",
|
||||
"Contents",
|
||||
"MacOS",
|
||||
"SkyComputerUseClient",
|
||||
);
|
||||
|
||||
describe("Codex Computer Use native service", () => {
|
||||
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
|
||||
|
||||
it("installs the official client beneath the isolated Codex home", async () => {
|
||||
const root = tempDirs.make("openclaw-computer-use-service-");
|
||||
const sourcePath = path.join(root, "source", "Codex Computer Use.app");
|
||||
const codexHome = path.join(root, "agent", "codex-home");
|
||||
await writeExecutableClient(sourcePath);
|
||||
|
||||
const result = await ensureCodexComputerUseServiceApp({
|
||||
codexHome,
|
||||
platform: "darwin",
|
||||
sourceAppCandidates: [sourcePath],
|
||||
copyServiceApp: async (source, target) => await fs.cp(source, target, { recursive: true }),
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({ status: "installed", changed: true, sourcePath });
|
||||
await expect(
|
||||
fs.access(
|
||||
path.join(codexHome, "computer-use", "Codex Computer Use.app", CLIENT_RELATIVE_PATH),
|
||||
),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("reuses a complete home-owned client without consulting desktop sources", async () => {
|
||||
const root = tempDirs.make("openclaw-computer-use-service-");
|
||||
const codexHome = path.join(root, "codex-home");
|
||||
await writeExecutableClient(path.join(codexHome, "computer-use", "Codex Computer Use.app"));
|
||||
const copyServiceApp = vi.fn();
|
||||
|
||||
const result = await ensureCodexComputerUseServiceApp({
|
||||
codexHome,
|
||||
platform: "darwin",
|
||||
sourceAppCandidates: [],
|
||||
copyServiceApp,
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({ status: "already_installed", changed: false });
|
||||
expect(copyServiceApp).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports a missing source without creating a partial target", async () => {
|
||||
const root = tempDirs.make("openclaw-computer-use-service-");
|
||||
const codexHome = path.join(root, "codex-home");
|
||||
|
||||
const result = await ensureCodexComputerUseServiceApp({
|
||||
codexHome,
|
||||
platform: "darwin",
|
||||
sourceAppCandidates: [path.join(root, "missing.app")],
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({ status: "source_missing", changed: false });
|
||||
await expect(fs.access(path.join(codexHome, "computer-use"))).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
});
|
||||
|
||||
it("replaces an incomplete home-owned service app", async () => {
|
||||
const root = tempDirs.make("openclaw-computer-use-service-");
|
||||
const sourcePath = path.join(root, "source", "Codex Computer Use.app");
|
||||
const codexHome = path.join(root, "codex-home");
|
||||
const targetPath = path.join(codexHome, "computer-use", "Codex Computer Use.app");
|
||||
await writeExecutableClient(sourcePath);
|
||||
await fs.mkdir(targetPath, { recursive: true });
|
||||
await fs.writeFile(path.join(targetPath, "partial"), "incomplete");
|
||||
|
||||
const result = await ensureCodexComputerUseServiceApp({
|
||||
codexHome,
|
||||
platform: "darwin",
|
||||
sourceAppCandidates: [sourcePath],
|
||||
copyServiceApp: async (source, target) => await fs.cp(source, target, { recursive: true }),
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({ status: "installed", changed: true });
|
||||
await expect(fs.access(path.join(targetPath, CLIENT_RELATIVE_PATH))).resolves.toBeUndefined();
|
||||
await expect(fs.access(path.join(targetPath, "partial"))).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not provision the macOS service on other platforms", async () => {
|
||||
const result = await ensureCodexComputerUseServiceApp({
|
||||
codexHome: "/tmp/codex-home",
|
||||
platform: "linux",
|
||||
});
|
||||
|
||||
expect(result).toEqual({ status: "unsupported", changed: false });
|
||||
});
|
||||
|
||||
it("prefers service assets owned by the selected desktop app-server", () => {
|
||||
expect(
|
||||
resolveMacOSDesktopCodexComputerUseServiceAppCandidates(
|
||||
"darwin",
|
||||
"/Applications/Codex.app/Contents/Resources/codex",
|
||||
)[0],
|
||||
).toBe(
|
||||
"/Applications/Codex.app/Contents/Resources/plugins/openai-bundled/plugins/computer-use/Codex Computer Use.app",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
async function writeExecutableClient(appPath: string): Promise<void> {
|
||||
const clientPath = path.join(appPath, CLIENT_RELATIVE_PATH);
|
||||
await fs.mkdir(path.dirname(clientPath), { recursive: true });
|
||||
await fs.writeFile(clientPath, "client");
|
||||
await fs.chmod(clientPath, 0o755);
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/** Native Computer Use service provisioning for isolated Codex homes. */
|
||||
import { constants as fsConstants } from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { runExec } from "openclaw/plugin-sdk/process-runtime";
|
||||
import { resolveMacOSDesktopCodexComputerUseServiceAppCandidates } from "./desktop-app-paths.js";
|
||||
|
||||
const SERVICE_APP_NAME = "Codex Computer Use.app";
|
||||
const CLIENT_RELATIVE_PATH = path.join(
|
||||
"Contents",
|
||||
"SharedSupport",
|
||||
"SkyComputerUseClient.app",
|
||||
"Contents",
|
||||
"MacOS",
|
||||
"SkyComputerUseClient",
|
||||
);
|
||||
const COPY_TIMEOUT_MS = 120_000;
|
||||
const activeInstalls = new Map<string, Promise<CodexComputerUseServiceStatus>>();
|
||||
|
||||
type CodexComputerUseServiceStatus = {
|
||||
status: "installed" | "already_installed" | "source_missing" | "unsupported";
|
||||
changed: boolean;
|
||||
targetPath?: string;
|
||||
sourcePath?: string;
|
||||
};
|
||||
|
||||
type CopyServiceApp = (sourcePath: string, targetPath: string) => Promise<void>;
|
||||
|
||||
/** Ensures the official native client exists beneath the CODEX_HOME used by its launcher. */
|
||||
export async function ensureCodexComputerUseServiceApp(params: {
|
||||
codexHome: string;
|
||||
platform?: NodeJS.Platform;
|
||||
appServerCommand?: string;
|
||||
sourceAppCandidates?: readonly string[];
|
||||
copyServiceApp?: CopyServiceApp;
|
||||
}): Promise<CodexComputerUseServiceStatus> {
|
||||
const platform = params.platform ?? process.platform;
|
||||
if (platform !== "darwin") {
|
||||
return { status: "unsupported", changed: false };
|
||||
}
|
||||
const targetPath = path.join(path.resolve(params.codexHome), "computer-use", SERVICE_APP_NAME);
|
||||
const active = activeInstalls.get(targetPath);
|
||||
if (active) {
|
||||
return await active;
|
||||
}
|
||||
const install = ensureCodexComputerUseServiceAppOnce({ ...params, targetPath, platform });
|
||||
activeInstalls.set(targetPath, install);
|
||||
try {
|
||||
return await install;
|
||||
} finally {
|
||||
if (activeInstalls.get(targetPath) === install) {
|
||||
activeInstalls.delete(targetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureCodexComputerUseServiceAppOnce(params: {
|
||||
codexHome: string;
|
||||
targetPath: string;
|
||||
platform: NodeJS.Platform;
|
||||
appServerCommand?: string;
|
||||
sourceAppCandidates?: readonly string[];
|
||||
copyServiceApp?: CopyServiceApp;
|
||||
}): Promise<CodexComputerUseServiceStatus> {
|
||||
if (await hasExecutableClient(params.targetPath)) {
|
||||
return { status: "already_installed", changed: false, targetPath: params.targetPath };
|
||||
}
|
||||
const candidates =
|
||||
params.sourceAppCandidates ??
|
||||
resolveMacOSDesktopCodexComputerUseServiceAppCandidates(
|
||||
params.platform,
|
||||
params.appServerCommand,
|
||||
);
|
||||
const sourcePath = await findUsableServiceApp(candidates);
|
||||
if (!sourcePath) {
|
||||
return { status: "source_missing", changed: false, targetPath: params.targetPath };
|
||||
}
|
||||
|
||||
const targetParent = path.dirname(params.targetPath);
|
||||
await fs.mkdir(targetParent, { recursive: true });
|
||||
const stagingRoot = await fs.mkdtemp(path.join(targetParent, ".service-app.staging-"));
|
||||
const stagedPath = path.join(stagingRoot, SERVICE_APP_NAME);
|
||||
const backupPath = path.join(targetParent, `.service-app.backup-${process.pid}-${Date.now()}`);
|
||||
let backupCreated = false;
|
||||
try {
|
||||
await (params.copyServiceApp ?? copyServiceAppWithDitto)(sourcePath, stagedPath);
|
||||
if (!(await hasExecutableClient(stagedPath))) {
|
||||
throw new Error(`Copied Computer Use service app is incomplete at ${stagedPath}.`);
|
||||
}
|
||||
if (await pathExists(params.targetPath)) {
|
||||
await fs.rename(params.targetPath, backupPath);
|
||||
backupCreated = true;
|
||||
if (await hasExecutableClient(backupPath)) {
|
||||
// A separate runtime can win after the initial target check. Restore
|
||||
// its complete signed app rather than replacing it from our staging copy.
|
||||
await fs.rename(backupPath, params.targetPath);
|
||||
backupCreated = false;
|
||||
return {
|
||||
status: "already_installed",
|
||||
changed: false,
|
||||
targetPath: params.targetPath,
|
||||
sourcePath,
|
||||
};
|
||||
}
|
||||
}
|
||||
try {
|
||||
await fs.rename(stagedPath, params.targetPath);
|
||||
} catch (error) {
|
||||
// Another runtime can finish the same isolated-home install first.
|
||||
// Preserve that complete winner instead of replacing a live signed app.
|
||||
if (!(await hasExecutableClient(params.targetPath))) {
|
||||
if (backupCreated) {
|
||||
await fs.rename(backupPath, params.targetPath);
|
||||
backupCreated = false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
if (backupCreated) {
|
||||
await fs.rm(backupPath, { recursive: true, force: true });
|
||||
backupCreated = false;
|
||||
}
|
||||
return {
|
||||
status: "already_installed",
|
||||
changed: false,
|
||||
targetPath: params.targetPath,
|
||||
sourcePath,
|
||||
};
|
||||
}
|
||||
if (backupCreated) {
|
||||
await fs.rm(backupPath, { recursive: true, force: true });
|
||||
backupCreated = false;
|
||||
}
|
||||
return { status: "installed", changed: true, targetPath: params.targetPath, sourcePath };
|
||||
} finally {
|
||||
await fs.rm(stagingRoot, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
async function pathExists(filePath: string): Promise<boolean> {
|
||||
return await fs.lstat(filePath).then(
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
}
|
||||
|
||||
async function findUsableServiceApp(candidates: readonly string[]): Promise<string | undefined> {
|
||||
for (const candidate of candidates) {
|
||||
if (await hasExecutableClient(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function hasExecutableClient(appPath: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.access(path.join(appPath, CLIENT_RELATIVE_PATH), fsConstants.X_OK);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copyServiceAppWithDitto(sourcePath: string, targetPath: string): Promise<void> {
|
||||
await runExec("/usr/bin/ditto", ["--noqtn", sourcePath, targetPath], {
|
||||
logOutput: false,
|
||||
timeoutMs: COPY_TIMEOUT_MS,
|
||||
});
|
||||
}
|
||||
@@ -370,6 +370,48 @@ describe("Codex Computer Use setup", () => {
|
||||
).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("fails fast when the named MCP server exposes no tools", async () => {
|
||||
const request = createComputerUseRequest({ installed: true, mcpToolsAvailable: false });
|
||||
|
||||
await expectSetupErrorStatus(
|
||||
ensureCodexComputerUse({
|
||||
pluginConfig: {
|
||||
computerUse: {
|
||||
enabled: true,
|
||||
strictReadiness: true,
|
||||
marketplaceName: "desktop-tools",
|
||||
},
|
||||
},
|
||||
request,
|
||||
}),
|
||||
{
|
||||
ready: false,
|
||||
reason: "mcp_missing",
|
||||
mcpServerAvailable: false,
|
||||
tools: [],
|
||||
message: "Computer Use is installed, but the computer-use MCP server exposes no tools.",
|
||||
},
|
||||
);
|
||||
expectRequestMethodNotCalled(request, "thread/start");
|
||||
expectRequestMethodNotCalled(request, "mcpServer/tool/call");
|
||||
});
|
||||
|
||||
it("reloads empty MCP exposure once during install before failing closed", async () => {
|
||||
const request = createComputerUseRequest({ installed: true, mcpToolsAvailable: false });
|
||||
|
||||
await expectSetupErrorStatus(
|
||||
installCodexComputerUse({
|
||||
pluginConfig: { computerUse: { marketplaceName: "desktop-tools" } },
|
||||
request,
|
||||
}),
|
||||
{ ready: false, reason: "mcp_missing", mcpServerAvailable: false },
|
||||
);
|
||||
expect(
|
||||
requestCalls(request).filter(([method]) => method === "config/mcpServer/reload"),
|
||||
).toHaveLength(1);
|
||||
expectRequestMethodNotCalled(request, "thread/start");
|
||||
});
|
||||
|
||||
it("does not repair stale Computer Use MCP children unless autoRepair is enabled", async () => {
|
||||
const request = createComputerUseRequest({ installed: true, liveTestFailures: 2 });
|
||||
const repairComputerUseMcpChildren = vi.fn(async () => ({
|
||||
@@ -1008,6 +1050,7 @@ function createComputerUseRequest(params: {
|
||||
enabled?: boolean;
|
||||
marketplaceAvailableAfterListCalls?: number;
|
||||
liveTestFailures?: number;
|
||||
mcpToolsAvailable?: boolean;
|
||||
}): CodexComputerUseRequest {
|
||||
let installed = params.installed;
|
||||
let enabled = params.enabled ?? installed;
|
||||
@@ -1073,12 +1116,15 @@ function createComputerUseRequest(params: {
|
||||
? [
|
||||
{
|
||||
name: "computer-use",
|
||||
tools: {
|
||||
list_apps: {
|
||||
name: "list_apps",
|
||||
inputSchema: { type: "object" },
|
||||
},
|
||||
},
|
||||
tools:
|
||||
params.mcpToolsAvailable === false
|
||||
? {}
|
||||
: {
|
||||
list_apps: {
|
||||
name: "list_apps",
|
||||
inputSchema: { type: "object" },
|
||||
},
|
||||
},
|
||||
resources: [],
|
||||
resourceTemplates: [],
|
||||
authStatus: "unsupported",
|
||||
|
||||
@@ -317,6 +317,7 @@ async function inspectCodexComputerUse(
|
||||
}
|
||||
client = await getLeasedSharedCodexAppServerClient({
|
||||
startOptions: runtime.start,
|
||||
pluginConfig: params.pluginConfig,
|
||||
timeoutMs: params.timeoutMs ?? runtime.requestTimeoutMs,
|
||||
config: params.config,
|
||||
agentDir: params.agentDir,
|
||||
@@ -480,9 +481,11 @@ async function readComputerUseTools(params: {
|
||||
repairComputerUseMcpChildren?: () => Promise<CodexComputerUseRepairStatus>;
|
||||
}): Promise<CodexComputerUseStatus> {
|
||||
let server = await readMcpServerStatus(params.request, params.config.mcpServerName);
|
||||
if (!server && params.installPlugin) {
|
||||
let tools = Object.keys(server?.tools ?? {}).toSorted();
|
||||
if ((!server || tools.length === 0) && params.installPlugin) {
|
||||
await reloadMcpServers(params.request);
|
||||
server = await readMcpServerStatus(params.request, params.config.mcpServerName);
|
||||
tools = Object.keys(server?.tools ?? {}).toSorted();
|
||||
}
|
||||
if (!server) {
|
||||
return statusFromPlugin({
|
||||
@@ -493,11 +496,20 @@ async function readComputerUseTools(params: {
|
||||
message: `Computer Use is installed, but the ${params.config.mcpServerName} MCP server is not available.`,
|
||||
});
|
||||
}
|
||||
if (tools.length === 0) {
|
||||
return statusFromPlugin({
|
||||
config: params.config,
|
||||
plugin: params.plugin,
|
||||
tools,
|
||||
reason: "mcp_missing",
|
||||
message: `Computer Use is installed, but the ${params.config.mcpServerName} MCP server exposes no tools.`,
|
||||
});
|
||||
}
|
||||
|
||||
const status = statusFromPlugin({
|
||||
config: params.config,
|
||||
plugin: params.plugin,
|
||||
tools: Object.keys(server.tools).toSorted(),
|
||||
tools,
|
||||
reason: "ready",
|
||||
message: "Computer Use is ready.",
|
||||
});
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
/** Shared path candidates for Codex's macOS desktop app bundle. */
|
||||
import { existsSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
type MacOSDesktopCodexAppPathCandidate = {
|
||||
appName: "ChatGPT.app" | "Codex.app";
|
||||
appBundlePath: string;
|
||||
appServerCommandPath: string;
|
||||
bundledMarketplacePath: string;
|
||||
computerUseServiceAppPaths: readonly string[];
|
||||
};
|
||||
|
||||
const MACOS_DESKTOP_CODEX_APP_PATH_CANDIDATES: readonly MacOSDesktopCodexAppPathCandidate[] = [
|
||||
@@ -14,12 +16,20 @@ const MACOS_DESKTOP_CODEX_APP_PATH_CANDIDATES: readonly MacOSDesktopCodexAppPath
|
||||
appBundlePath: "/Applications/ChatGPT.app",
|
||||
appServerCommandPath: "/Applications/ChatGPT.app/Contents/Resources/codex",
|
||||
bundledMarketplacePath: "/Applications/ChatGPT.app/Contents/Resources/plugins/openai-bundled",
|
||||
computerUseServiceAppPaths: [
|
||||
"/Applications/ChatGPT.app/Contents/Resources/cua_node/lib/node_modules/@oai/sky/Codex Computer Use.app",
|
||||
"/Applications/ChatGPT.app/Contents/Resources/plugins/openai-bundled/plugins/computer-use/Codex Computer Use.app",
|
||||
],
|
||||
},
|
||||
{
|
||||
appName: "Codex.app",
|
||||
appBundlePath: "/Applications/Codex.app",
|
||||
appServerCommandPath: "/Applications/Codex.app/Contents/Resources/codex",
|
||||
bundledMarketplacePath: "/Applications/Codex.app/Contents/Resources/plugins/openai-bundled",
|
||||
computerUseServiceAppPaths: [
|
||||
"/Applications/Codex.app/Contents/Resources/plugins/openai-bundled/plugins/computer-use/Codex Computer Use.app",
|
||||
"/Applications/Codex.app/Contents/Resources/cua_node/lib/node_modules/@oai/sky/Codex Computer Use.app",
|
||||
],
|
||||
},
|
||||
] as const;
|
||||
|
||||
@@ -31,6 +41,32 @@ export function resolveMacOSDesktopCodexBundledMarketplaceCandidates(
|
||||
: [];
|
||||
}
|
||||
|
||||
export function resolveMacOSDesktopCodexComputerUseServiceAppCandidates(
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
appServerCommand?: string,
|
||||
): string[] {
|
||||
if (platform !== "darwin") {
|
||||
return [];
|
||||
}
|
||||
const matchingCandidate = appServerCommand
|
||||
? MACOS_DESKTOP_CODEX_APP_PATH_CANDIDATES.find(
|
||||
(candidate) =>
|
||||
path.resolve(candidate.appServerCommandPath) === path.resolve(appServerCommand),
|
||||
)
|
||||
: undefined;
|
||||
const orderedCandidates = matchingCandidate
|
||||
? [
|
||||
matchingCandidate,
|
||||
...MACOS_DESKTOP_CODEX_APP_PATH_CANDIDATES.filter(
|
||||
(candidate) => candidate !== matchingCandidate,
|
||||
),
|
||||
]
|
||||
: MACOS_DESKTOP_CODEX_APP_PATH_CANDIDATES;
|
||||
return [
|
||||
...new Set(orderedCandidates.flatMap((candidate) => candidate.computerUseServiceAppPaths)),
|
||||
];
|
||||
}
|
||||
|
||||
export function resolveFirstExistingMacOSDesktopCodexBundledMarketplacePath(
|
||||
params: {
|
||||
platform?: NodeJS.Platform;
|
||||
|
||||
Reference in New Issue
Block a user