Skip to content

Commit 08786d3

Browse files
feat(codex): show sessions from additional homes (#124660)
* feat(codex): register additional session homes * fix(codex): preserve automatic session homes * docs(codex): explain automatic home discovery around sessionCatalog.homes --------- Co-authored-by: IWhatsskill <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 34bfcdb commit 08786d3

8 files changed

Lines changed: 149 additions & 28 deletions

File tree

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Top-level fields:
4646
| `codexDynamicToolsExclude` | `[]` | Additional OpenClaw dynamic tool names to omit from Codex app-server turns. |
4747
| `codexPlugins` | disabled | Native Codex plugin/app support, including opt-in access to connected account apps. See [Native Codex plugins](/plugins/codex-native-plugins). |
4848
| `computerUse` | disabled | Codex Computer Use setup. See [Codex Computer Use](/plugins/codex-computer-use). |
49-
| `sessionCatalog` | enabled | Native Codex session discovery for the sidebar. Set `enabled: false` to disable discovery without disabling the provider or harness. |
49+
| `sessionCatalog` | enabled | Native Codex session discovery for the sidebar. Set `enabled: false` to disable it, or set `homes` to include additional local Codex stores. |
5050
| `supervision` | disabled | Agent-facing native-session transcript and write-control policy. See [Codex supervision](/plugins/codex-supervision). |
5151

5252
## Supervision
@@ -71,6 +71,42 @@ computer and opted-in paired nodes by default. Disable only that catalog with:
7171
}
7272
```
7373

74+
Discovery automatically covers the Gateway process Codex home (`CODEX_HOME` or
75+
`~/.codex`) and the Codex home of every configured OpenClaw agent. Register
76+
additional local Codex stores only when sessions live in a home OpenClaw does
77+
not already know about, for example a store created with a custom `CODEX_HOME`
78+
outside OpenClaw:
79+
80+
```json5
81+
{
82+
plugins: {
83+
entries: {
84+
codex: {
85+
enabled: true,
86+
config: {
87+
sessionCatalog: {
88+
homes: ["/path/to/additional-codex-home"],
89+
},
90+
},
91+
},
92+
},
93+
},
94+
}
95+
```
96+
97+
Configured stores appear in the sidebar alongside automatically discovered
98+
ones, labeled `Local Codex · configured <n>` and grouped by each session's
99+
working directory. Sessions in these stores support the same view, continue,
100+
and archive actions, and the selected OpenClaw agent still owns the resulting
101+
connection; `homes` only adds catalog sources.
102+
103+
Only existing directories are included. Equivalent paths are canonicalized and
104+
deduplicated against the automatic homes, and automatic homes keep priority
105+
under the 100-source catalog cap. Changes require a Gateway restart.
106+
`sessionCatalog.homes` needs the default managed stdio app-server transport;
107+
Unix and WebSocket transports reject it with a visible error because they
108+
cannot start a source-bound app-server for each home.
109+
74110
`supervision` separately controls agent-facing tools:
75111

76112
| Field | Default | Meaning |

‎docs/plugins/codex-harness.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ rules, paired-node limits, metadata exposure, and troubleshooting.
218218
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------- |
219219
| Enable the harness | `plugins.entries.codex.enabled: true` | OpenClaw config |
220220
| Hide native Codex session discovery | `plugins.entries.codex.config.sessionCatalog.enabled: false` | Codex plugin config |
221+
| Include additional local Codex stores (stdio only) | `plugins.entries.codex.config.sessionCatalog.homes` | Codex plugin config |
221222
| Keep an allowlisted plugin install | Include `codex` in `plugins.allow` | OpenClaw config |
222223
| Allow eligible OpenAI turns to use Codex implicitly | Exact official HTTPS Responses/ChatGPT route, no authored provider request override, runtime unset/`auto` | OpenAI provider/model config |
223224
| Sign in with ChatGPT/Codex OAuth | `openclaw models auth login --provider openai` | CLI auth profile |

‎extensions/codex/openclaw.plugin.json‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"onConfigPaths": [
5353
"plugins.entries.codex.config.appServer.transport",
5454
"plugins.entries.codex.config.sessionCatalog.enabled",
55+
"plugins.entries.codex.config.sessionCatalog.homes",
5556
"plugins.entries.codex.config.supervision.enabled"
5657
]
5758
},
@@ -80,7 +81,11 @@
8081
"type": "object",
8182
"additionalProperties": false,
8283
"properties": {
83-
"enabled": { "type": "boolean", "default": true }
84+
"enabled": { "type": "boolean", "default": true },
85+
"homes": {
86+
"type": "array",
87+
"items": { "type": "string", "minLength": 1, "pattern": "\\S" }
88+
}
8489
}
8590
},
8691
"discovery": {
@@ -399,6 +404,11 @@
399404
"label": "Discover Codex Sessions",
400405
"help": "List native Codex sessions in the sidebar from this Gateway and eligible paired nodes."
401406
},
407+
"sessionCatalog.homes": {
408+
"label": "Additional Codex Homes",
409+
"help": "Existing local Codex home directories to include in native session discovery. Paths are canonicalized and deduplicated. Requires appServer.transport=stdio and a Gateway restart.",
410+
"advanced": true
411+
},
402412
"codexDynamicToolsLoading": {
403413
"label": "Dynamic Tools Loading",
404414
"help": "Use searchable to defer OpenClaw dynamic tools behind Codex tool search, or direct to expose them in the initial context.",

‎extensions/codex/src/app-server/config-runtime.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ export function resolveCodexAppServerRuntimeOptions(
107107
const config = pluginConfig.appServer ?? {};
108108
const transport = resolveTransport(config.transport);
109109
const homeScope = resolveCodexAppServerHomeScope({ appServer: config });
110+
if (transport !== "stdio" && pluginConfig.sessionCatalog?.homes?.length) {
111+
throw new Error(
112+
"plugins.entries.codex.config.sessionCatalog.homes requires appServer.transport=stdio",
113+
);
114+
}
110115
const configCommand = readNonEmptyString(config.command);
111116
const envCommand = readNonEmptyString(env.OPENCLAW_CODEX_APP_SERVER_BIN);
112117
const command = configCommand ?? envCommand ?? "codex";

‎extensions/codex/src/app-server/config.test.ts‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,27 @@ describe("Codex app-server config", () => {
367367
).toStrictEqual({});
368368
});
369369

370-
it("parses the native session discovery toggle", () => {
371-
expect(readCodexPluginConfig({ sessionCatalog: { enabled: false } }).sessionCatalog).toEqual({
372-
enabled: false,
373-
});
370+
it("parses native session discovery options", () => {
371+
expect(
372+
readCodexPluginConfig({
373+
sessionCatalog: { enabled: false, homes: [" /srv/codex-extra "] },
374+
}).sessionCatalog,
375+
).toEqual({ enabled: false, homes: ["/srv/codex-extra"] });
376+
expect(readCodexPluginConfig({ sessionCatalog: { homes: [" "] } })).toStrictEqual({});
377+
});
378+
379+
it.each([
380+
{ transport: "unix", homeScope: "user" },
381+
{ transport: "websocket", url: "ws://127.0.0.1:39175" },
382+
] as const)("rejects additional session homes for $transport app servers", (appServer) => {
383+
expect(() =>
384+
resolveRuntimeForTest({
385+
pluginConfig: { appServer, sessionCatalog: { homes: ["/srv/codex-extra"] } },
386+
env: {},
387+
}),
388+
).toThrow(
389+
"plugins.entries.codex.config.sessionCatalog.homes requires appServer.transport=stdio",
390+
);
374391
});
375392

376393
it("rejects unknown app-server fields", () => {

‎extensions/codex/src/app-server/session-discovery-config.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { z } from "zod";
22

33
export const codexSessionCatalogConfigSchema = z
4-
.object({ enabled: z.boolean().optional() })
4+
.object({
5+
enabled: z.boolean().optional(),
6+
homes: z.array(z.string().trim().min(1)).optional(),
7+
})
58
.strict();
69

710
export const codexDiscoveryConfigSchema = z

‎extensions/codex/src/session-catalog-homes.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
resolveCodexAppServerLocalHomeDir,
99
} from "./app-server/auth-start-options.js";
1010
import {
11+
readCodexPluginConfig,
1112
resolveCodexAppServerUserHomeDir,
1213
resolveCodexSupervisionAppServerRuntimeOptions,
1314
} from "./app-server/config.js";
@@ -35,6 +36,15 @@ function canonicalCatalogHome(value: string): string {
3536
}
3637
}
3738

39+
function existingCanonicalCatalogHome(value: string): string | undefined {
40+
try {
41+
const codexHome = fs.realpathSync.native(path.resolve(value));
42+
return fs.statSync(codexHome).isDirectory() ? codexHome : undefined;
43+
} catch {
44+
return undefined;
45+
}
46+
}
47+
3848
function catalogHomeId(codexHome: string): string {
3949
return createHash("sha256")
4050
.update("openclaw:codex-session-catalog-home:v1\0")
@@ -51,6 +61,7 @@ function resolveCodexCatalogHomes(params: {
5161
}): CodexCatalogHome[] {
5262
const { config, env, ownerAgentId, pluginConfig } = params;
5363
const ownerAgentDir = resolveAgentDir(config, ownerAgentId, env);
64+
const configuredHomes = readCodexPluginConfig(pluginConfig).sessionCatalog?.homes ?? [];
5465
const base = resolveCodexSupervisionAppServerRuntimeOptions({
5566
pluginConfig,
5667
env,
@@ -91,6 +102,20 @@ function resolveCodexCatalogHomes(params: {
91102
: [];
92103
}),
93104
);
105+
candidates.push(
106+
...configuredHomes.flatMap((value, index) => {
107+
const codexHome = existingCanonicalCatalogHome(value);
108+
return codexHome
109+
? [
110+
{
111+
codexHome,
112+
label: `Local Codex · configured ${index + 1}`,
113+
usesProcessHomeFallback: false,
114+
},
115+
]
116+
: [];
117+
}),
118+
);
94119
}
95120

96121
const seen = new Set<string>();

‎extensions/codex/src/session-catalog-listing.test.ts‎

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Codex supervision tests cover passive listing and safe local session takeover.
22
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+
import { MAX_HOST_COUNT } from "./session-catalog-parsing.js";
34
import {
45
tempDirs,
56
createCodexSessionCatalogControl,
@@ -285,7 +286,7 @@ describe("Codex supervision catalog", () => {
285286
});
286287
});
287288

288-
it("discovers every existing Codex home while retaining the route owner directory", async () => {
289+
it("discovers configured and automatic Codex homes while retaining the route owner", async () => {
289290
const root = await fs.realpath(
290291
await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-catalog-homes-")),
291292
);
@@ -295,11 +296,21 @@ describe("Codex supervision catalog", () => {
295296
const processCodexHome = path.join(root, "process-codex-home");
296297
const alphaCodexHome = resolveCodexAppServerHomeDir(alphaAgentDir);
297298
const betaCodexHome = resolveCodexAppServerHomeDir(betaAgentDir);
299+
const configuredCodexHomes = Array.from({ length: MAX_HOST_COUNT }, (_, index) =>
300+
path.join(root, "configured-codex-home", String(index)),
301+
);
302+
const configuredCodexHome = configuredCodexHomes[0]!;
303+
const configuredCodexHomeAlias = path.join(root, "configured-codex-home-alias");
304+
const configuredFile = path.join(root, "not-a-codex-home");
298305
await Promise.all(
299-
[processCodexHome, alphaCodexHome, betaCodexHome].map((dir) =>
306+
[processCodexHome, alphaCodexHome, betaCodexHome, ...configuredCodexHomes].map((dir) =>
300307
fs.mkdir(dir, { recursive: true }),
301308
),
302309
);
310+
await Promise.all([
311+
fs.symlink(configuredCodexHome, configuredCodexHomeAlias, "dir"),
312+
fs.writeFile(configuredFile, "not a directory"),
313+
]);
303314
const runtimeConfig = {
304315
agents: {
305316
ownership: "explicit",
@@ -315,21 +326,34 @@ describe("Codex supervision catalog", () => {
315326
config: runtimeConfig,
316327
env,
317328
getRuntimeConfig: () => runtimeConfig,
318-
getPluginConfig: () => ({ supervision: { enabled: true } }),
329+
getPluginConfig: () => ({
330+
supervision: { enabled: true },
331+
sessionCatalog: {
332+
homes: [
333+
configuredCodexHome,
334+
configuredCodexHomeAlias,
335+
alphaCodexHome,
336+
path.join(root, "missing-codex-home"),
337+
configuredFile,
338+
...configuredCodexHomes.slice(1),
339+
],
340+
},
341+
}),
319342
});
320343
const homes = control.homesForAgent("beta");
321344

322-
expect(
323-
new Set(
324-
homes.map((home) =>
325-
resolveCodexAppServerLocalHomeDir(home.appServer.start, home.agentDir, env),
326-
),
327-
),
328-
).toEqual(new Set([processCodexHome, alphaCodexHome, betaCodexHome]));
329-
expect(homes.map((home) => home.agentDir)).toEqual([betaAgentDir, betaAgentDir, betaAgentDir]);
345+
const resolvedHomes = homes.map((home) =>
346+
resolveCodexAppServerLocalHomeDir(home.appServer.start, home.agentDir, env),
347+
);
348+
expect(homes).toHaveLength(MAX_HOST_COUNT);
349+
expect(resolvedHomes.slice(0, 3)).toEqual([processCodexHome, betaCodexHome, alphaCodexHome]);
350+
expect(resolvedHomes.filter((home) => configuredCodexHomes.includes(home))).toHaveLength(
351+
MAX_HOST_COUNT - 3,
352+
);
353+
expect(homes.map((home) => home.agentDir)).toEqual(Array(MAX_HOST_COUNT).fill(betaAgentDir));
330354
expect(homes[0]?.hostId).toBe(CODEX_LOCAL_SESSION_HOST_ID);
331355
expect(homes.slice(1).every((home) => home.hostId.startsWith("gateway:local:"))).toBe(true);
332-
expect(new Set(homes.map((home) => home.sourceHomeId)).size).toBe(3);
356+
expect(new Set(homes.map((home) => home.sourceHomeId)).size).toBe(MAX_HOST_COUNT);
333357
expect(
334358
JSON.stringify(homes.map(({ hostId, sourceHomeId }) => ({ hostId, sourceHomeId }))),
335359
).not.toContain(root);
@@ -338,18 +362,18 @@ describe("Codex supervision catalog", () => {
338362
pinnedConnectionMocks.request.mockResolvedValue({
339363
thread: idleThread({ id: "thread-source" }),
340364
});
341-
const alphaSource = homes.find(
365+
const configuredSource = homes.find(
342366
(home) =>
343367
resolveCodexAppServerLocalHomeDir(home.appServer.start, home.agentDir, env) ===
344-
alphaCodexHome,
368+
configuredCodexHome,
345369
);
346-
expect(alphaSource).toBeDefined();
370+
expect(configuredSource).toBeDefined();
347371

348-
const alphaFingerprint = buildCodexAppServerConnectionFingerprint(
349-
alphaSource!.appServer,
350-
alphaSource!.agentDir,
372+
const configuredFingerprint = buildCodexAppServerConnectionFingerprint(
373+
configuredSource!.appServer,
374+
configuredSource!.agentDir,
351375
);
352-
const boundControl = control.forUpstream("beta", alphaFingerprint);
376+
const boundControl = control.forUpstream("beta", configuredFingerprint);
353377
expect(boundControl).toBeDefined();
354378
expect(control.forUpstream("beta", "unknown-fingerprint")).toBeUndefined();
355379
await boundControl!.listPage({});
@@ -359,13 +383,13 @@ describe("Codex supervision catalog", () => {
359383

360384
expect(commandRpcMocks.codexControlRequest.mock.calls[0]?.[3]).toMatchObject({
361385
agentDir: betaAgentDir,
362-
startOptions: { env: { CODEX_HOME: alphaCodexHome } },
386+
startOptions: { env: { CODEX_HOME: configuredCodexHome } },
363387
});
364388
expect(pinnedConnectionMocks.getClient).toHaveBeenCalledWith(
365389
expect.objectContaining({
366390
agentDir: betaAgentDir,
367391
startOptions: expect.objectContaining({
368-
env: expect.objectContaining({ CODEX_HOME: alphaCodexHome }),
392+
env: expect.objectContaining({ CODEX_HOME: configuredCodexHome }),
369393
}),
370394
}),
371395
);

0 commit comments

Comments
 (0)