Skip to content

Commit bc5081c

Browse files
authored
feat(codex): support remote app-server plugins (#94203)
* feat(codex): support remote app-server plugins * fix(codex): refresh remote plugin apps after install * fix(codex): infer remote app-server topology * docs(codex): document remote app-server plugin config * fix(codex): remove remote mutation policy * fix(codex): simplify remote workspace root * docs(codex): fix remote app-server PR docs
1 parent 20534c5 commit bc5081c

27 files changed

Lines changed: 801 additions & 83 deletions

‎docs/plugins/codex-harness-reference.md‎

Lines changed: 29 additions & 20 deletions
Large diffs are not rendered by default.

‎docs/plugins/codex-harness.md‎

Lines changed: 24 additions & 20 deletions
Large diffs are not rendered by default.

‎extensions/codex/openclaw.plugin.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
"type": "array",
162162
"items": { "type": "string" }
163163
},
164+
"remoteWorkspaceRoot": {
165+
"type": "string"
166+
},
164167
"codeModeOnly": {
165168
"type": "boolean",
166169
"default": false
@@ -386,6 +389,11 @@
386389
"help": "Environment variable names removed from the spawned stdio app-server process after overrides are applied.",
387390
"advanced": true
388391
},
392+
"appServer.remoteWorkspaceRoot": {
393+
"label": "Remote Workspace Root",
394+
"help": "Remote Codex app-server workspace root used to project OpenClaw cwd suffixes before starting Codex threads.",
395+
"advanced": true
396+
},
389397
"appServer.codeModeOnly": {
390398
"label": "Code Mode Only",
391399
"help": "Expose Codex's code-mode-only tool surface. OpenClaw dynamic tools remain available through Codex nested tool calls.",

‎extensions/codex/src/app-server/app-inventory-cache.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,35 @@ describe("Codex app inventory cache", () => {
5353
expect(request).not.toHaveBeenCalled();
5454
});
5555

56+
it("stops paginated refresh once target app ids are found", async () => {
57+
const cache = new CodexAppInventoryCache({ ttlMs: 100 });
58+
const request = vi.fn(async (_method: "app/list", params: v2.AppsListParams) => {
59+
if (!params.cursor) {
60+
return { data: [app("app-1")], nextCursor: "page-2" } satisfies v2.AppsListResponse;
61+
}
62+
if (params.cursor === "page-2") {
63+
return {
64+
data: [app("google-calendar-app")],
65+
nextCursor: "page-3",
66+
} satisfies v2.AppsListResponse;
67+
}
68+
return { data: [app("app-3")], nextCursor: null } satisfies v2.AppsListResponse;
69+
});
70+
71+
const snapshot = await cache.refreshNow({
72+
key: "runtime",
73+
request,
74+
targetAppIds: ["google-calendar-app"],
75+
});
76+
77+
expect(snapshot.apps.map((item) => item.id)).toEqual(["app-1", "google-calendar-app"]);
78+
expect(request).toHaveBeenCalledTimes(2);
79+
expect(request.mock.calls.map(([, params]) => params.cursor ?? null)).toEqual([
80+
null,
81+
"page-2",
82+
]);
83+
});
84+
5685
it("uses stale inventory for the current read while still refreshing asynchronously", async () => {
5786
const cache = new CodexAppInventoryCache({ ttlMs: 10 });
5887
const request = vi.fn(async () => {

‎extensions/codex/src/app-server/app-inventory-cache.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type CodexAppInventoryRequest = (
2525
export type CodexAppInventoryCacheKeyInput = {
2626
codexHome?: string;
2727
endpoint?: string;
28+
runtimeIdentity?: Record<string, string | undefined>;
2829
authProfileId?: string;
2930
accountId?: string;
3031
envApiKeyFingerprint?: string;
@@ -70,6 +71,7 @@ type RefreshParams = {
7071
nowMs?: number;
7172
forceRefetch?: boolean;
7273
suppressRefresh?: boolean;
74+
targetAppIds?: readonly string[];
7375
};
7476

7577
/** In-memory app inventory cache with coalesced refreshes per key. */
@@ -189,7 +191,11 @@ export class CodexAppInventoryCache {
189191
): Promise<CodexAppInventorySnapshot> {
190192
const nowMs = resolveDateTimestampMs(params.nowMs);
191193
try {
192-
const apps = await listAllApps(params.request, params.forceRefetch ?? false);
194+
const apps = await listAllApps(
195+
params.request,
196+
params.forceRefetch ?? false,
197+
params.targetAppIds,
198+
);
193199
this.revision += 1;
194200
const expiresAtMs = resolveExpiresAtMsFromDurationMs(this.ttlMs, { nowMs }) ?? 0;
195201
const snapshot: CodexAppInventorySnapshot = {
@@ -251,18 +257,37 @@ export function buildCodexAppInventoryCacheKey(input: CodexAppInventoryCacheKeyI
251257
return JSON.stringify({
252258
codexHome: input.codexHome ?? null,
253259
endpoint: input.endpoint ?? null,
260+
runtimeIdentity: normalizeRuntimeIdentityForCacheKey(input.runtimeIdentity),
254261
authProfileId: input.authProfileId ?? null,
255262
accountId: input.accountId ?? null,
256263
envApiKeyFingerprint: input.envApiKeyFingerprint ?? null,
257264
appServerVersion: input.appServerVersion ?? null,
258265
});
259266
}
260267

268+
function normalizeRuntimeIdentityForCacheKey(
269+
value: Record<string, string | undefined> | undefined,
270+
): Record<string, string> | null {
271+
if (!value) {
272+
return null;
273+
}
274+
const entries = Object.entries(value)
275+
.flatMap(([key, rawValue]) => {
276+
const normalized = rawValue?.trim();
277+
return normalized ? ([[key, normalized]] as const) : [];
278+
})
279+
.toSorted(([left], [right]) => left.localeCompare(right));
280+
return entries.length > 0 ? Object.fromEntries(entries) : null;
281+
}
282+
261283
async function listAllApps(
262284
request: CodexAppInventoryRequest,
263285
forceRefetch: boolean,
286+
targetAppIds: readonly string[] = [],
264287
): Promise<v2.AppInfo[]> {
265288
const apps: v2.AppInfo[] = [];
289+
const targetIds = new Set(targetAppIds.filter(Boolean));
290+
const foundTargetIds = new Set<string>();
266291
let cursor: string | null | undefined;
267292
do {
268293
const response = await request("app/list", {
@@ -271,7 +296,15 @@ async function listAllApps(
271296
forceRefetch,
272297
});
273298
apps.push(...response.data);
299+
for (const app of response.data) {
300+
if (targetIds.has(app.id)) {
301+
foundTargetIds.add(app.id);
302+
}
303+
}
274304
cursor = response.nextCursor;
305+
if (targetIds.size > 0 && foundTargetIds.size === targetIds.size) {
306+
break;
307+
}
275308
} while (cursor);
276309
return apps;
277310
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ describe("Codex app-server attempt diagnostics", () => {
2929
approvalPolicy: "never" as const,
3030
approvalsReviewer: "user" as const,
3131
sandbox: "danger-full-access" as const,
32+
connectionClass: "local-loopback" as const,
33+
remoteAppsSubstrate: "preconfigured" as const,
3234
serviceTier: "priority" as const,
3335
};
3436
const resolvedPluginPolicy = resolveCodexPluginsPolicy({

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

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import {
3030
resolveCodexSandboxEnvironmentSelection,
3131
shouldRequireCodexSandboxExecServerEnvironment,
3232
} from "./dynamic-tool-build.js";
33-
import { buildCodexPluginAppCacheKey } from "./plugin-app-cache-key.js";
33+
import {
34+
buildCodexAppServerRuntimeFingerprint,
35+
buildCodexPluginAppCacheKey,
36+
} from "./plugin-app-cache-key.js";
3437
import {
3538
buildCodexPluginThreadConfig,
3639
buildCodexPluginThreadConfigInputFingerprint,
@@ -148,20 +151,6 @@ export async function startCodexAttemptThread(params: {
148151
const pluginThreadConfigPluginConfig = params.nativeToolSurfaceEnabled
149152
? params.pluginConfig
150153
: disableCodexPluginThreadConfig(params.pluginConfig);
151-
const pluginAppCacheKeyInput = {
152-
appServer: params.appServer,
153-
agentDir: params.agentDir,
154-
authProfileId: params.startupAuthProfileId,
155-
accountId: params.startupAuthAccountCacheKey,
156-
envApiKeyFingerprint: params.startupEnvApiKeyCacheKey,
157-
};
158-
const pluginAppCacheKey = buildCodexPluginAppCacheKey(pluginAppCacheKeyInput);
159-
const pluginThreadConfigInputFingerprint = pluginThreadConfigRequired
160-
? buildCodexPluginThreadConfigInputFingerprint({
161-
pluginConfig: pluginThreadConfigPluginConfig,
162-
appCacheKey: pluginAppCacheKey,
163-
})
164-
: undefined;
165154
const resolvedPluginPolicy = pluginThreadConfigRequired
166155
? resolveCodexPluginsPolicy(pluginThreadConfigPluginConfig)
167156
: undefined;
@@ -174,20 +163,6 @@ export async function startCodexAttemptThread(params: {
174163
.map((plugin) => plugin.configKey)
175164
.toSorted()
176165
: undefined;
177-
const attemptParams = params.buildAttemptParams();
178-
embeddedAgentLog.debug(
179-
"codex plugin thread config eligibility",
180-
buildCodexPluginThreadConfigEligibilityLogData({
181-
sessionId: attemptParams.sessionId,
182-
sessionKey: attemptParams.sessionKey ?? "",
183-
pluginThreadConfigRequired,
184-
resolvedPluginPolicy,
185-
enabledPluginConfigKeys,
186-
pluginAppCacheKey,
187-
startupAuthProfileId: params.startupAuthProfileId,
188-
appServer: params.appServer,
189-
}),
190-
);
191166
pluginAppServer = mcpElicitationDelegationRequired
192167
? {
193168
...params.appServer,
@@ -243,6 +218,41 @@ export async function startCodexAttemptThread(params: {
243218
timeoutMs: params.appServer.requestTimeoutMs,
244219
signal: startupAbandonController.signal,
245220
});
221+
const startupRuntimeIdentity = activeStartupClient.getRuntimeIdentity();
222+
const pluginAppCacheKey = buildCodexPluginAppCacheKey({
223+
appServer: params.appServer,
224+
agentDir: params.agentDir,
225+
authProfileId: params.startupAuthProfileId,
226+
accountId: params.startupAuthAccountCacheKey,
227+
envApiKeyFingerprint: params.startupEnvApiKeyCacheKey,
228+
appServerVersion: activeStartupClient.getServerVersion(),
229+
runtimeIdentity: startupRuntimeIdentity,
230+
});
231+
const appServerRuntimeFingerprint = buildCodexAppServerRuntimeFingerprint({
232+
appServer: params.appServer,
233+
appServerVersion: activeStartupClient.getServerVersion(),
234+
runtimeIdentity: startupRuntimeIdentity,
235+
});
236+
const pluginThreadConfigInputFingerprint = pluginThreadConfigRequired
237+
? buildCodexPluginThreadConfigInputFingerprint({
238+
pluginConfig: pluginThreadConfigPluginConfig,
239+
appCacheKey: pluginAppCacheKey,
240+
})
241+
: undefined;
242+
const attemptParams = params.buildAttemptParams();
243+
embeddedAgentLog.debug(
244+
"codex plugin thread config eligibility",
245+
buildCodexPluginThreadConfigEligibilityLogData({
246+
sessionId: attemptParams.sessionId,
247+
sessionKey: attemptParams.sessionKey ?? "",
248+
pluginThreadConfigRequired,
249+
resolvedPluginPolicy,
250+
enabledPluginConfigKeys,
251+
pluginAppCacheKey,
252+
startupAuthProfileId: params.startupAuthProfileId,
253+
appServer: params.appServer,
254+
}),
255+
);
246256
let startupSandboxEnvironment: CodexSandboxExecEnvironment | undefined;
247257
let startupSandboxEnvironmentAcquired = false;
248258
const releaseStartupSandboxEnvironment = async () => {
@@ -291,8 +301,10 @@ export async function startCodexAttemptThread(params: {
291301
);
292302
const startupExecutionCwd = resolveCodexAppServerExecutionCwd({
293303
effectiveCwd: params.effectiveCwd,
304+
localWorkspaceRoot: params.effectiveWorkspace,
294305
environment: startupSandboxEnvironment,
295306
nativeToolSurfaceEnabled: params.nativeToolSurfaceEnabled,
307+
remoteWorkspaceRoot: params.appServer.remoteWorkspaceRoot,
296308
});
297309
const startupSandboxPolicy = startupSandboxEnvironment
298310
? resolveCodexExternalSandboxPolicyForOpenClawSandbox(params.sandbox)
@@ -319,6 +331,7 @@ export async function startCodexAttemptThread(params: {
319331
mcpServersFingerprint: params.bundleMcpThreadConfig.fingerprint,
320332
mcpServersFingerprintEvaluated: params.bundleMcpThreadConfig.evaluated,
321333
environmentSelection: startupEnvironmentSelection,
334+
appServerRuntimeFingerprint,
322335
contextEngineProjection: params.contextEngineProjection,
323336
signal,
324337
pluginThreadConfig: pluginThreadConfigRequired
@@ -333,7 +346,7 @@ export async function startCodexAttemptThread(params: {
333346
activeStartupClient.request(method, requestParams, {
334347
timeoutMs: params.appServer.requestTimeoutMs,
335348
signal,
336-
}),
349+
}),
337350
appCache: defaultCodexAppInventoryCache,
338351
appCacheKey: pluginAppCacheKey,
339352
}),

‎extensions/codex/src/app-server/client.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ export type CodexServerNotificationHandler = (
103103
notification: CodexServerNotification,
104104
) => Promise<void> | void;
105105

106+
/** Runtime identity returned by the Codex app-server initialize handshake. */
107+
export type CodexAppServerRuntimeIdentity = {
108+
serverVersion: string;
109+
userAgent?: string;
110+
codexHome?: string;
111+
platformFamily?: string;
112+
platformOs?: string;
113+
};
114+
106115
/** Stateful app-server JSON-RPC client over stdio or websocket transport. */
107116
export class CodexAppServerClient {
108117
private readonly child: CodexAppServerTransport;
@@ -117,6 +126,7 @@ export class CodexAppServerClient {
117126
private closed = false;
118127
private closeError: Error | undefined;
119128
private serverVersion: string | undefined;
129+
private runtimeIdentity: CodexAppServerRuntimeIdentity | undefined;
120130
private stderrTail = "";
121131
private pendingParse:
122132
| {
@@ -193,6 +203,7 @@ export class CodexAppServerClient {
193203
},
194204
} satisfies CodexInitializeParams);
195205
this.serverVersion = assertSupportedCodexAppServerVersion(response);
206+
this.runtimeIdentity = buildCodexAppServerRuntimeIdentity(response, this.serverVersion);
196207
this.notify("initialized");
197208
this.initialized = true;
198209
}
@@ -202,6 +213,11 @@ export class CodexAppServerClient {
202213
return this.serverVersion;
203214
}
204215

216+
/** Returns runtime metadata detected during initialize. */
217+
getRuntimeIdentity(): CodexAppServerRuntimeIdentity | undefined {
218+
return this.runtimeIdentity ? { ...this.runtimeIdentity } : undefined;
219+
}
220+
205221
request<M extends CodexAppServerRequestMethod>(
206222
method: M,
207223
params: CodexAppServerRequestParams<M>,
@@ -623,6 +639,28 @@ function assertSupportedCodexAppServerVersion(response: CodexInitializeResponse)
623639
return detectedVersion;
624640
}
625641

642+
function buildCodexAppServerRuntimeIdentity(
643+
response: CodexInitializeResponse,
644+
serverVersion: string,
645+
): CodexAppServerRuntimeIdentity {
646+
const userAgent = readNonEmptyInitializeString(response.userAgent);
647+
const codexHome = readNonEmptyInitializeString(response.codexHome);
648+
const platformFamily = readNonEmptyInitializeString(response.platformFamily);
649+
const platformOs = readNonEmptyInitializeString(response.platformOs);
650+
return {
651+
serverVersion,
652+
...(userAgent ? { userAgent } : {}),
653+
...(codexHome ? { codexHome } : {}),
654+
...(platformFamily ? { platformFamily } : {}),
655+
...(platformOs ? { platformOs } : {}),
656+
};
657+
}
658+
659+
function readNonEmptyInitializeString(value: string | undefined): string | undefined {
660+
const trimmed = value?.trim();
661+
return trimmed ? trimmed : undefined;
662+
}
663+
626664
/** Extracts the Codex version from the app-server initialize user-agent field. */
627665
export function readCodexVersionFromUserAgent(userAgent: string | undefined): string | undefined {
628666
// Codex returns `<originator>/<codex-version> ...`; the originator can be

0 commit comments

Comments
 (0)