Skip to content

Commit d658fb3

Browse files
committed
fix(codex): harden legacy configured MCP rotation
1 parent fe49870 commit d658fb3

57 files changed

Lines changed: 9164 additions & 1728 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.

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Docs: https://docs.openclaw.ai
6464

6565
### Fixes
6666

67+
- **Codex configured MCP upgrades:** rotate legacy Codex-native configured-MCP bindings into the OpenClaw-owned dynamic-tool runtime, preserve ordinary predecessor history, guard descendants from stale-authority reentry, retry supervised retirement fail-forward, and repair unambiguous shipped duplicate ownership aliases with `openclaw doctor --fix`. Fixes #113475.
6768
- **Control UI read-only preferences:** keep personal preference edits browser-local without attempting unauthorized config writes or claiming server sync, preserve offline intent for a later authorized reconnect, and restore the current server value on local reset. Thanks @shakkernerd.
6869
- **Control UI owner handoff:** give browsers opened by host-issued dashboard and graphical onboarding links durable administrator access, including same-browser recovery from a limited credential, while keeping generic, Telegram, mobile, and ordinary scope-upgrade paths bounded. Thanks @shakkernerd.
6970
- **Control UI agent and skill permissions:** gate Agents, Skills, Skill Workshop, and delayed mutation dispatches by the current Gateway method catalog and operator scopes while preserving read-only browsing and legacy Gateway compatibility. Fixes #119176. Thanks @shakkernerd.

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ aa8a411ad37c1d1143b67376bf2d20255b9eedff61d80815f42e4f8ed7bd8e58 module/secret-
122122
57dcb1462d4c4f9a98d934c4ca975b163d704758af9821a64001ff3ac05637c3 module/secret-input-runtime
123123
dc0ee07d392a85c218939000b28c0138f139215da00f5592b34a68ba8e29a25d module/secret-ref-runtime
124124
f97549081955e412d8eb64070c64bb5921bb1324744d824db05767d3adcce403 module/security-runtime
125-
673c64502fdffb2d6361a7cf2ad0c33ffe15707b5e5027de1d88701ce3d8ade1 module/session-catalog
125+
d49fdad4fe46b541b4de413b2a83e2079ac25611603e418d6d06ab9db9c0c005 module/session-catalog
126126
50f5e344f98c27570b7a30e32a906b612e2383d21f102e88cd93e1d5425a6de9 module/session-discussion
127127
f112bdabc51ba8659b37d0a6f6a32a2b1d471e5b49b56e108bf750ec55a7ea71 module/session-store-runtime
128128
36affbe151431a6141664b6838e20f2d121ff210d57a3c1b4b41a8818b5c81d8 module/setup

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ change that persisted pair, and the initial snapshot can produce Codex's normal
8181
model-difference warning; the outer OpenClaw model and fallback chain never
8282
substitute for either.
8383

84+
### Configured MCP ownership upgrades
85+
86+
OpenClaw now owns configured MCP servers for Codex harness turns and exposes
87+
their allowed tools as OpenClaw dynamic tools. A thread created by an older
88+
OpenClaw release may still contain the retired Codex-native MCP configuration.
89+
On its next normal turn, OpenClaw starts a replacement thread with the current
90+
dynamic tool surface before it retires the old binding.
91+
92+
For an ordinary user-home Codex thread, OpenClaw preserves the old native
93+
thread and its history. The replacement becomes the OpenClaw session thread,
94+
while the predecessor is marked retired and is not resumed, forked, or
95+
unarchived by OpenClaw. Spawned descendants inherit the same restriction. You
96+
may explicitly archive the predecessor after verifying that you no longer need
97+
it. For a supervised thread, OpenClaw archives the predecessor automatically
98+
only after a fresh idle check proves that it has no spawned descendants.
99+
100+
If retirement cannot finish, OpenClaw keeps the safe replacement and retries
101+
retirement on the next normal turn. Reset and delete remain blocked until that
102+
retry completes, and the error explains the required recovery. If the error
103+
says that the thread has a duplicate file-keyed ownership alias, run
104+
`openclaw doctor --fix`, then retry the normal turn. Doctor removes an alias
105+
only when it exactly matches one unambiguous canonical session owner; ambiguous
106+
rows are preserved for operator review.
107+
84108
## Supervision and safe continuation
85109

86110
Codex supervision is an opt-in capability of the same `codex` plugin. It discovers

‎extensions/codex/doctor-contract-api.test.ts‎

Lines changed: 246 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os from "node:os";
44
import path from "node:path";
55
import {
66
createPluginStateKeyedStoreForTests,
7+
createPluginStateSyncKeyedStoreForTests,
78
resetPluginStateStoreForTests,
89
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
910
import type {
@@ -22,6 +23,7 @@ import {
2223
CODEX_APP_SERVER_BINDING_MAX_ENTRIES,
2324
CODEX_APP_SERVER_BINDING_NAMESPACE,
2425
createStoredCodexAppServerBinding,
26+
createCodexAppServerBindingStore,
2527
hashCodexAppServerBindingFingerprint,
2628
type StoredCodexAppServerBinding,
2729
} from "./src/app-server/session-binding.js";
@@ -273,7 +275,7 @@ describe("codex doctor contract", () => {
273275
bindingId: legacyCodexConversationBindingId(fixture.transcriptPath),
274276
}),
275277
),
276-
).resolves.toMatchObject({ state: "active", binding: { threadId: "thread-1" } });
278+
).resolves.toBeUndefined();
277279
await expect(fs.access(`${fixture.sidecarPath}.migrated`)).resolves.toBeUndefined();
278280
expect(
279281
getSessionEntry({
@@ -293,6 +295,99 @@ describe("codex doctor contract", () => {
293295
await fs.rm(fixture.stateDir, { recursive: true, force: true });
294296
});
295297

298+
it.each([
299+
["user", { userMcpServersFingerprint: "legacy-user-mcp" }],
300+
["bundled", { mcpServersFingerprint: "legacy-bundled-mcp" }],
301+
] as const)(
302+
"hands a migrated %s MCP sidecar to the canonical runtime retirement flow",
303+
async (name, marker) => {
304+
const sessionKey = `agent:main:${name}-runtime-retirement`;
305+
const sessionId = `${name}-runtime-retirement`;
306+
const predecessorThreadId = `thread-${name}-predecessor`;
307+
const successorThreadId = `thread-${name}-successor`;
308+
const fixture = await createBindingMigrationFixture({
309+
name,
310+
sessionIndex: {
311+
[sessionKey]: {
312+
sessionId,
313+
sessionFile: `${name}.jsonl`,
314+
},
315+
},
316+
threadId: predecessorThreadId,
317+
binding: marker,
318+
});
319+
320+
await expect(fixture.migration.migrateLegacyState(fixture.params)).resolves.toMatchObject({
321+
warnings: [],
322+
});
323+
const runtimeState = createPluginStateSyncKeyedStoreForTests<StoredCodexAppServerBinding>(
324+
"codex",
325+
{
326+
namespace: CODEX_APP_SERVER_BINDING_NAMESPACE,
327+
maxEntries: CODEX_APP_SERVER_BINDING_MAX_ENTRIES,
328+
overflowPolicy: "reject-new",
329+
env: fixture.env,
330+
},
331+
);
332+
const runtimeStore = createCodexAppServerBindingStore(runtimeState);
333+
const identity = {
334+
kind: "session" as const,
335+
agentId: "main",
336+
sessionId,
337+
sessionKey,
338+
};
339+
const migratedMarker =
340+
"userMcpServersFingerprint" in marker
341+
? {
342+
userMcpServersFingerprint: hashCodexAppServerBindingFingerprint(
343+
marker.userMcpServersFingerprint,
344+
),
345+
}
346+
: {
347+
mcpServersFingerprint: hashCodexAppServerBindingFingerprint(
348+
marker.mcpServersFingerprint,
349+
),
350+
};
351+
await expect(runtimeStore.read(identity)).resolves.toMatchObject({
352+
threadId: predecessorThreadId,
353+
...migratedMarker,
354+
});
355+
await expect(
356+
runtimeStore.mutate(identity, {
357+
kind: "replace-legacy-mcp-thread",
358+
expectedThreadId: predecessorThreadId,
359+
binding: {
360+
threadId: successorThreadId,
361+
cwd: "/repo",
362+
dynamicToolsFingerprint: "dynamic-v2",
363+
legacyMcpRetirementThreadId: predecessorThreadId,
364+
},
365+
}),
366+
).resolves.toBe(true);
367+
await expect(runtimeStore.recordLegacyMcpThreadRetirement(predecessorThreadId)).resolves.toBe(
368+
true,
369+
);
370+
await expect(
371+
runtimeStore.mutate(identity, {
372+
kind: "complete-legacy-mcp-retirement",
373+
expectedThreadId: successorThreadId,
374+
expectedRetirementThreadId: predecessorThreadId,
375+
}),
376+
).resolves.toBe(true);
377+
await expect(runtimeStore.read(identity)).resolves.toMatchObject({
378+
threadId: successorThreadId,
379+
dynamicToolsFingerprint: "dynamic-v2",
380+
});
381+
await expect(runtimeStore.inspectThreadOwnership(predecessorThreadId)).resolves.toMatchObject(
382+
{
383+
hasUnexpectedOwner: true,
384+
hasLegacyNativeMcpOwner: true,
385+
},
386+
);
387+
await fs.rm(fixture.stateDir, { recursive: true, force: true });
388+
},
389+
);
390+
296391
it("bounds oversized legacy fingerprints before plugin-state import", async () => {
297392
const rawDynamicToolsFingerprint = JSON.stringify([
298393
{ name: "legacy_large_tool", inputSchema: { description: "dynamic-marker".repeat(8_000) } },
@@ -427,10 +522,7 @@ describe("codex doctor contract", () => {
427522
});
428523

429524
const expectedFingerprint = hashCodexAppServerBindingFingerprint(rawFingerprint);
430-
await expect(store.lookup(conversationKey)).resolves.toMatchObject({
431-
state: "active",
432-
binding: { dynamicToolsFingerprint: expectedFingerprint },
433-
});
525+
await expect(store.lookup(conversationKey)).resolves.toBeUndefined();
434526
await expect(store.lookup(sessionBindingKey)).resolves.toMatchObject({
435527
state: "active",
436528
sessionId,
@@ -499,10 +591,7 @@ describe("codex doctor contract", () => {
499591
});
500592

501593
const expectedFingerprint = hashCodexAppServerBindingFingerprint(rawFingerprint);
502-
await expect(store.lookup(conversationKey)).resolves.toMatchObject({
503-
state: "active",
504-
binding: { dynamicToolsFingerprint: expectedFingerprint },
505-
});
594+
await expect(store.lookup(conversationKey)).resolves.toBeUndefined();
506595
await expect(store.lookup(sessionBindingKey)).resolves.toMatchObject({
507596
state: "active",
508597
sessionId,
@@ -1151,6 +1240,154 @@ describe("codex doctor contract", () => {
11511240
).toBe("on-request");
11521241
});
11531242

1243+
it("collapses an exact shipped legacy binding alias into its unique session owner", async () => {
1244+
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-alias-doctor-"));
1245+
const env = { ...process.env, OPENCLAW_STATE_DIR: stateDir };
1246+
const store = openBindingStore(env);
1247+
const binding = {
1248+
threadId: "thread-legacy-alias",
1249+
cwd: "/repo",
1250+
userMcpServersFingerprint: "legacy-mcp",
1251+
};
1252+
const aliasKey = "conversation:legacy-exact";
1253+
const sessionKey = "session-key:main:exact";
1254+
await store.register(aliasKey, { version: 1, state: "active", binding });
1255+
await store.register(sessionKey, {
1256+
version: 1,
1257+
state: "active",
1258+
sessionId: "session-current",
1259+
binding,
1260+
});
1261+
const migration = stateMigrations.find(
1262+
(candidate) => candidate.id === "codex-app-server-collapse-legacy-binding-aliases",
1263+
);
1264+
if (!migration) {
1265+
throw new Error("missing binding alias migration");
1266+
}
1267+
const params = {
1268+
config: {},
1269+
env,
1270+
stateDir,
1271+
oauthDir: path.join(stateDir, "oauth"),
1272+
context: createDoctorContext(env),
1273+
};
1274+
1275+
await expect(migration.detectLegacyState(params)).resolves.toEqual({
1276+
preview: ["- Codex app-server bindings: collapse 1 duplicate file-keyed ownership alias(es)"],
1277+
});
1278+
await expect(migration.migrateLegacyState(params)).resolves.toEqual({
1279+
changes: [
1280+
"Collapsed 1 duplicate Codex app-server binding ownership alias(es) into their canonical session owners",
1281+
],
1282+
warnings: [],
1283+
});
1284+
await expect(store.lookup(aliasKey)).resolves.toBeUndefined();
1285+
await expect(store.lookup(sessionKey)).resolves.toMatchObject({
1286+
state: "active",
1287+
binding: { threadId: binding.threadId },
1288+
});
1289+
await expect(migration.migrateLegacyState(params)).resolves.toEqual({
1290+
changes: [],
1291+
warnings: [],
1292+
});
1293+
await fs.rm(stateDir, { recursive: true, force: true });
1294+
});
1295+
1296+
it("keeps ambiguous shipped legacy binding aliases for operator review", async () => {
1297+
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-alias-ambiguous-"));
1298+
const env = { ...process.env, OPENCLAW_STATE_DIR: stateDir };
1299+
const store = openBindingStore(env);
1300+
const binding = {
1301+
threadId: "thread-ambiguous-alias",
1302+
cwd: "/repo",
1303+
mcpServersFingerprint: "legacy-mcp",
1304+
};
1305+
await store.register("conversation:legacy-ambiguous", {
1306+
version: 1,
1307+
state: "active",
1308+
binding,
1309+
});
1310+
await store.register("session-key:main:first", {
1311+
version: 1,
1312+
state: "active",
1313+
sessionId: "session-first",
1314+
binding,
1315+
});
1316+
await store.register("session-key:main:second", {
1317+
version: 1,
1318+
state: "active",
1319+
sessionId: "session-second",
1320+
binding,
1321+
});
1322+
const migration = stateMigrations.find(
1323+
(candidate) => candidate.id === "codex-app-server-collapse-legacy-binding-aliases",
1324+
);
1325+
if (!migration) {
1326+
throw new Error("missing binding alias migration");
1327+
}
1328+
const params = {
1329+
config: {},
1330+
env,
1331+
stateDir,
1332+
oauthDir: path.join(stateDir, "oauth"),
1333+
context: createDoctorContext(env),
1334+
};
1335+
1336+
await expect(migration.migrateLegacyState(params)).resolves.toEqual({
1337+
changes: [],
1338+
warnings: [
1339+
"Kept 1 ambiguous Codex app-server binding alias(es); each matched multiple session owners",
1340+
],
1341+
});
1342+
await expect(store.lookup("conversation:legacy-ambiguous")).resolves.toBeDefined();
1343+
await fs.rm(stateDir, { recursive: true, force: true });
1344+
});
1345+
1346+
it("keeps a leased shipped legacy binding alias for its runtime owner", async () => {
1347+
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-alias-leased-"));
1348+
const env = { ...process.env, OPENCLAW_STATE_DIR: stateDir };
1349+
const store = openBindingStore(env);
1350+
const binding = {
1351+
threadId: "thread-leased-alias",
1352+
cwd: "/repo",
1353+
userMcpServersFingerprint: "legacy-mcp",
1354+
};
1355+
const aliasKey = "conversation:legacy-leased";
1356+
await store.register(aliasKey, {
1357+
version: 1,
1358+
state: "active",
1359+
binding,
1360+
lease: { token: "active-runtime", expiresAt: Date.now() + 60_000 },
1361+
});
1362+
await store.register("session-key:main:leased", {
1363+
version: 1,
1364+
state: "active",
1365+
sessionId: "session-current",
1366+
binding,
1367+
});
1368+
const migration = stateMigrations.find(
1369+
(candidate) => candidate.id === "codex-app-server-collapse-legacy-binding-aliases",
1370+
);
1371+
if (!migration) {
1372+
throw new Error("missing binding alias migration");
1373+
}
1374+
1375+
await expect(
1376+
migration.migrateLegacyState({
1377+
config: {},
1378+
env,
1379+
stateDir,
1380+
oauthDir: path.join(stateDir, "oauth"),
1381+
context: createDoctorContext(env),
1382+
}),
1383+
).resolves.toEqual({
1384+
changes: [],
1385+
warnings: [`Kept leased Codex app-server binding alias ${aliasKey}`],
1386+
});
1387+
await expect(store.lookup(aliasKey)).resolves.toBeDefined();
1388+
await fs.rm(stateDir, { recursive: true, force: true });
1389+
});
1390+
11541391
it("renames the retired app-server on-failure approval policy", () => {
11551392
const original = {
11561393
plugins: {

0 commit comments

Comments
 (0)