Skip to content

Commit 0a6b95a

Browse files
authored
feat: cloud workers for the codex runtime (remote-exec placements) (#123743)
* feat(gateway): add remote-exec cloud placements * feat(codex): run cloud turns through remote exec * fix(sandbox): quote ssh_config path directives containing whitespace Crabbox lease keys default to ~/Library/Application Support/... on macOS; unquoted IdentityFile/UserKnownHostsFile/CertificateFile arguments tokenize on the space and fail as 'extra arguments'. Found via live remote-exec cloud-worker proof. * test: consolidate gateway maintenance schedule coverage * fix(ci): invalidate plugin sdk declarations on state changes
1 parent 72e6790 commit 0a6b95a

107 files changed

Lines changed: 2352 additions & 579 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/macos/Tests/OpenClawIPCTests/PortGuardianRecordStoreTests.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ struct PortGuardianRecordStoreTests {
532532
let fixture = try Self.fixture()
533533
defer { fixture.cleanup() }
534534

535-
for version in [4, 5, 6, 7] {
535+
for version in [4, 5, 6, 7, 8] {
536536
let databaseURL = fixture.root.appendingPathComponent("supported-v\(version).sqlite")
537537
try Self.seedVersionedPortGuardianDatabase(databaseURL, schemaVersion: version)
538538
let store = try PortGuardianRecordStore(databaseURL: databaseURL)
@@ -544,7 +544,7 @@ struct PortGuardianRecordStoreTests {
544544
#expect(try store.records() == [record])
545545
}
546546

547-
for version in [8, 99] {
547+
for version in [9, 99] {
548548
let databaseURL = fixture.root.appendingPathComponent("newer-v\(version).sqlite")
549549
try Self.seedVersionedPortGuardianDatabase(databaseURL, schemaVersion: version)
550550
#expect(throws: PortGuardianStoreError.self) {

‎apps/shared/OpenClawKit/Sources/OpenClawNativeState/OpenClawNativeStateSQLite.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public enum OpenClawNativeStateSQLiteValueType: Equatable, Sendable {
3737
/// One recursive connection lock serializes transactions and statement access.
3838
public final class OpenClawNativeStateSQLite: @unchecked Sendable {
3939
// Keep aligned with OPENCLAW_STATE_SCHEMA_VERSION. Native clients never upgrade this database.
40-
private static let maximumSupportedSchemaVersion: Int64 = 7
40+
private static let maximumSupportedSchemaVersion: Int64 = 8
4141
private static let defaultBusyTimeoutMilliseconds: Int32 = 5000
4242

4343
private struct SchemaObject: Hashable {

‎docs/gateway/cloud-workers.md‎

Lines changed: 33 additions & 23 deletions
Large diffs are not rendered by default.

‎extensions/codex/harness.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ describe("Codex agent harness supports()", () => {
2929

3030
it("publishes provider ids for lightweight auto selection", () => {
3131
expect(harness.autoSelection?.providerIds).toEqual(["codex", "openai"]);
32+
expect(
33+
(harness as typeof harness & { cloudPlacement?: { mode: "remote-exec" } }).cloudPlacement,
34+
).toEqual({ mode: "remote-exec" });
3235
});
3336

3437
it("keeps computer-control denies out of the native-surface exemption", () => {

‎extensions/codex/harness.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const CODEX_APP_SERVER_CONTEXT_ENGINE_HOST_CAPABILITIES = [
4848
] as const satisfies readonly ContextEngineHostCapability[];
4949

5050
type CodexAppServerAgentHarness = AgentHarnessV2 & {
51+
cloudPlacement?: { mode: "remote-exec" };
5152
compactAfterContextEngine?(
5253
params: AgentHarnessCompactParams,
5354
): Promise<AgentHarnessCompactResult | undefined>;
@@ -120,6 +121,7 @@ export function createCodexAppServerAgentHarness(options: {
120121
id: harnessRuntimeId,
121122
label: options?.label ?? "Codex agent harness",
122123
autoSelection: { providerIds: [...providerIds] },
124+
cloudPlacement: { mode: "remote-exec" },
123125
delegatedExecutionPluginIds: ["voice-call"],
124126
contextEngineHostCapabilities: CODEX_APP_SERVER_CONTEXT_ENGINE_HOST_CAPABILITIES,
125127
conversationToolPolicySupport: "exact",

‎extensions/codex/src/app-server/attempt-startup.test.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from "./config.js";
2222
import { createCodexTestHostCapabilities } from "./host-capability.test-support.js";
2323
import { defaultCodexPluginMetadataCache } from "./plugin-metadata-cache.js";
24+
import { createSandboxContext } from "./sandbox-exec-server.test-helpers.js";
2425
import {
2526
resetCodexTestBindingStore,
2627
testCodexAppServerBindingStore,
@@ -118,6 +119,8 @@ function startThreadWithHarness(
118119
runtimeArtifactRequest?: Parameters<
119120
typeof startCodexAttemptThread
120121
>[0]["runtimeArtifactRequest"];
122+
sandbox?: Parameters<typeof startCodexAttemptThread>[0]["sandbox"];
123+
sandboxExecServerEnabled?: boolean;
121124
},
122125
) {
123126
const harness = overrides?.harness ?? createClientHarness();
@@ -155,8 +158,8 @@ function startThreadWithHarness(
155158
bundleMcpThreadConfig,
156159
nativeToolSurfaceEnabled: true,
157160
nativeProviderWebSearchSupport: "supported",
158-
sandboxExecServerEnabled: false,
159-
sandbox: null,
161+
sandboxExecServerEnabled: overrides?.sandboxExecServerEnabled ?? false,
162+
sandbox: overrides?.sandbox ?? null,
160163
contextEngineProjection: undefined,
161164
startupTimeoutMs,
162165
signal,
@@ -684,6 +687,29 @@ describe("startCodexAttemptThread", () => {
684687
);
685688
});
686689

690+
it("requires app-server environment support for remote-exec placement", async () => {
691+
const sandbox = {
692+
...createSandboxContext({}),
693+
placementExecutionMode: "remote-exec" as const,
694+
};
695+
const { harness, run } = startThreadWithHarness(5_000, new AbortController().signal, {
696+
sandbox,
697+
});
698+
await answerInitialize(harness);
699+
const environmentAdd = await waitForRequest(harness, "environment/add");
700+
harness.send({
701+
id: environmentAdd.id,
702+
error: { code: -32601, message: "unknown variant environment/add" },
703+
});
704+
705+
await expect(run).rejects.toThrow(
706+
"Codex app-server did not register an OpenClaw sandbox exec-server environment.",
707+
);
708+
expect(
709+
readHarnessMessages(harness.writes).some((entry) => entry.method === "thread/start"),
710+
).toBe(false);
711+
});
712+
687713
it("closes a startup client that arrives after startup timeout", async () => {
688714
vi.useFakeTimers();
689715
let observedFactoryOptions:

‎extensions/codex/src/app-server/attempt-startup.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,12 @@ export async function startCodexAttemptThread(params: {
390390
};
391391
releaseStartupResourcesOnTimeout = releaseStartupSandboxEnvironment;
392392
try {
393-
startupSandboxEnvironment = shouldRequireCodexSandboxExecServerEnvironment({
393+
const sandboxEnvironmentRequired = shouldRequireCodexSandboxExecServerEnvironment({
394394
sandbox: params.sandbox,
395395
nativeToolSurfaceEnabled: params.nativeToolSurfaceEnabled,
396396
sandboxExecServerEnabled: params.sandboxExecServerEnabled,
397-
})
397+
});
398+
startupSandboxEnvironment = sandboxEnvironmentRequired
398399
? await ensureCodexSandboxExecServerEnvironment({
399400
client: activeStartupClient,
400401
sandbox: params.sandbox ?? null,
@@ -408,12 +409,7 @@ export async function startCodexAttemptThread(params: {
408409
await releaseStartupSandboxEnvironment();
409410
throw new CodexAppServerStartupError("aborted");
410411
}
411-
if (
412-
params.sandbox?.enabled &&
413-
params.nativeToolSurfaceEnabled &&
414-
params.sandboxExecServerEnabled &&
415-
!startupSandboxEnvironment
416-
) {
412+
if (sandboxEnvironmentRequired && !startupSandboxEnvironment) {
417413
throw new Error(
418414
"Codex app-server did not register an OpenClaw sandbox exec-server environment.",
419415
);

‎extensions/codex/src/app-server/auth-bridge.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,37 @@ describe("bridgeCodexAppServerStartOptions", () => {
789789
});
790790
});
791791

792+
it("prepares a selected profile when remote execution forbids legacy auth", async () => {
793+
const authProfileStore: AuthProfileStore = {
794+
version: 1,
795+
profiles: {
796+
"openai:remote": {
797+
type: "api_key",
798+
provider: "openai",
799+
key: "prepared-remote-key",
800+
},
801+
},
802+
};
803+
804+
await expect(
805+
resolveCodexAppServerPreparedAuthHandoff({
806+
authProfileId: "openai:remote",
807+
authProfileStore,
808+
homeScope: "agent",
809+
requirePreparedAuth: true,
810+
subscriptionProfileRequiredError: "unused",
811+
subscriptionProfileUnusableError: "unused",
812+
}),
813+
).resolves.toMatchObject({
814+
authProfileId: "openai:remote",
815+
preparedAuth: {
816+
kind: "profile",
817+
profileId: "openai:remote",
818+
snapshot: { loginParams: { type: "apiKey", apiKey: "prepared-remote-key" } },
819+
},
820+
});
821+
});
822+
792823
it("keeps an inherited OpenAI API key for an explicit Codex api-key profile", async () => {
793824
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));
794825
const startOptions = createStartOptions({ clearEnv: ["FOO"] });

‎extensions/codex/src/app-server/auth-bridge.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ export async function resolveCodexAppServerPreparedAuthHandoff(params: {
323323
agentDir?: string;
324324
/** Required: an omitted scope would silently reintroduce prepared logins on native homes. */
325325
homeScope: CodexAppServerHomeScope;
326+
/** Remote execution must never rely on ambient or native-home credentials. */
327+
requirePreparedAuth?: boolean;
326328
config?: AuthProfileOrderConfig;
327329
subscriptionProfileRequiredError: string;
328330
subscriptionProfileUnusableError: string;
@@ -332,6 +334,11 @@ export async function resolveCodexAppServerPreparedAuthHandoff(params: {
332334
// token logins, so a prepared OpenClaw handoff here would rewrite the account that
333335
// Codex CLI and Desktop share. Native homes are verified, never logged into.
334336
const usesNativeHome = params.homeScope === "user";
337+
if (params.requirePreparedAuth && usesNativeHome) {
338+
throw createCodexAppServerAuthError(
339+
'Codex remote-exec cloud placement requires prepared OpenAI auth. Configure an OpenAI API-key, OAuth, or token profile and use appServer.homeScope="agent"; ambient credentials and native Codex auth are not allowed.',
340+
);
341+
}
335342
if (params.authRequirement === "api-key" && !usesNativeHome) {
336343
const apiKey = params.resolvedApiKey?.trim();
337344
if (!apiKey) {
@@ -350,11 +357,18 @@ export async function resolveCodexAppServerPreparedAuthHandoff(params: {
350357
agentDir: params.agentDir,
351358
config: params.config,
352359
});
353-
if (usesNativeHome || params.authRequirement !== "subscription") {
360+
if (
361+
usesNativeHome ||
362+
(params.authRequirement !== "subscription" && !params.requirePreparedAuth)
363+
) {
354364
return { authProfileId, nativeAuthProfile };
355365
}
356-
if (!authProfileId || !nativeAuthProfile) {
357-
throw createCodexAppServerAuthError(params.subscriptionProfileRequiredError);
366+
if (!authProfileId || (params.authRequirement === "subscription" && !nativeAuthProfile)) {
367+
throw createCodexAppServerAuthError(
368+
params.requirePreparedAuth
369+
? "Codex remote-exec cloud placement requires prepared OpenAI auth. Configure an OpenAI API-key, OAuth, or token profile; ambient CODEX_API_KEY, OPENAI_API_KEY, and native Codex auth are not allowed."
370+
: params.subscriptionProfileRequiredError,
371+
);
358372
}
359373

360374
const snapshot = await resolveCodexAppServerPreparedAuthProfileSnapshot({
@@ -364,7 +378,11 @@ export async function resolveCodexAppServerPreparedAuthHandoff(params: {
364378
config: params.config,
365379
});
366380
if (!snapshot) {
367-
throw createCodexAppServerAuthError(params.subscriptionProfileUnusableError);
381+
throw createCodexAppServerAuthError(
382+
params.requirePreparedAuth
383+
? "Codex remote-exec cloud placement could not prepare the selected OpenAI auth profile. Repair or replace the profile, then retry."
384+
: params.subscriptionProfileUnusableError,
385+
);
368386
}
369387
return {
370388
authProfileId,

‎extensions/codex/src/app-server/auth-profile-runtime-contract.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
threadStartResult,
1414
turnStartResult,
1515
} from "./run-attempt-test-harness.js";
16+
import { createSandboxContext } from "./sandbox-exec-server.test-helpers.js";
1617
import {
1718
readCodexAppServerBinding,
1819
writeCodexAppServerBinding as writeRawCodexAppServerBinding,
@@ -424,6 +425,24 @@ describe("Auth profile runtime contract - Codex app-server adapter", () => {
424425
expect(harness.seenClientOptions).toHaveLength(0);
425426
});
426427

428+
it("rejects ambient auth before a remote-exec attempt starts", async () => {
429+
const harness = createCodexAuthProfileHarness({ startMethod: "thread/start" });
430+
const sessionFile = path.join(tmpDir, "session.jsonl");
431+
const params = createParams(sessionFile, tmpDir);
432+
vi.stubEnv("CODEX_API_KEY", "ambient-codex-key");
433+
vi.stubEnv("OPENAI_API_KEY", "ambient-openai-key");
434+
params.authProfileStore = { version: 1, profiles: {} };
435+
params.sandbox = {
436+
...createSandboxContext({}),
437+
placementExecutionMode: "remote-exec",
438+
} as NonNullable<typeof params.sandbox> & { placementExecutionMode: "remote-exec" };
439+
440+
await expect(runCodexAppServerAttempt(params)).rejects.toThrow(
441+
"Codex remote-exec cloud placement requires prepared OpenAI auth",
442+
);
443+
expect(harness.seenClientOptions).toHaveLength(0);
444+
});
445+
427446
it.each([
428447
{ label: "no forwarded profile", forwardedProfileId: undefined, profileType: "oauth" as const },
429448
{

0 commit comments

Comments
 (0)