The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 11:00 UTC
fix(codex): keep browser access prompts available in full access (#37104)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Yash Singh committed
Nov 15, 2026 at 04:00 UTC
96290af4e0d74f5385b2e1886543ce62757827c5
5 files changed
+195
-18
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+143
-1
@@ -225,7 +225,15 @@ describe("CodexAdapterV2 runtime policy", () => {
225
assert.equal(auto.approvalPolicy, "on-request");
226
assert.equal(auto.approvalsReviewer, "auto_review");
227
assert.equal(auto.sandboxPolicy?.type, "workspaceWrite");
228
- assert.equal(fullAccess.approvalPolicy, "never");
228
+ assert.deepEqual(fullAccess.approvalPolicy, {
229
+ granular: {
230
+ mcp_elicitations: true,
231
+ request_permissions: false,
232
+ rules: false,
233
+ sandbox_approval: false,
234
+ skill_approval: false,
235
+ },
236
+ });
237
assert.equal(fullAccess.approvalsReviewer, "user");
238
assert.equal(fullAccess.sandboxPolicy?.type, "dangerFullAccess");
239
}),
@@ -657,6 +665,10 @@ function codexReplayPreamble(input: {
665
readonly prompt: string;
666
readonly sentPrompt?: string;
667
readonly effort?: string;
668
+ readonly turnPolicy?: Pick<
669
+ typeof CodexClient.V2TurnStartParams.Type,
670
+ "approvalPolicy" | "sandboxPolicy"
671
+ >;
672
}): Array<CodexReplay.CodexAppServerReplayEntry> {
673
return [
674
{
@@ -754,6 +766,7 @@ function codexReplayPreamble(input: {
766
approvalPolicy: "never",
767
approvalsReviewer: "user",
768
sandboxPolicy: { type: "dangerFullAccess" },
769
+ ...input.turnPolicy,
770
summary: "auto",
771
...(input.effort === undefined ? {} : { effort: input.effort }),
772
collaborationMode: {
@@ -1603,6 +1616,135 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1616
};
1617
});
1618
1619
+ it.effect.each([
1620
+ { runtimeMode: "full-access", turnIdKind: "present" },
1621
+ { runtimeMode: "auto-accept-edits", turnIdKind: "null" },
1622
+ ] as const)(
1623
+ "handles MCP access approvals in $runtimeMode with a $turnIdKind turn id",
1624
+ ({ runtimeMode, turnIdKind }) =>
1625
+ Effect.gen(function* () {
1626
+ const nativeThreadId = "mcp-approval-thread";
1627
+ const nativeTurnId = "mcp-approval-turn";
1628
+ const prompt = "Read the dashboard in Chrome.";
1629
+ const pending = yield* Queue.unbounded<OrchestrationV2RuntimeRequest>();
1630
+ const harness = yield* makeCodexReplayHarness(
1631
+ makeCodexReplayTranscript({
1632
+ scenario: `mcp-approval-${turnIdKind}`,
1633
+ entries: [
1634
+ ...codexReplayPreamble({
1635
+ nativeThreadId,
1636
+ nativeTurnId,
1637
+ prompt,
1638
+ ...(runtimeMode === "full-access"
1639
+ ? {}
1640
+ : {
1641
+ turnPolicy: {
1642
+ approvalPolicy: "on-request",
1643
+ sandboxPolicy: { type: "workspaceWrite" },
1644
+ },
1645
+ }),
1646
+ }),
1647
+ {
1648
+ type: "emit_inbound",
1649
+ frame: {
1650
+ id: 0,
1651
+ method: "mcpServer/elicitation/request",
1652
+ params: {
1653
+ threadId: nativeThreadId,
1654
+ turnId: turnIdKind === "null" ? null : nativeTurnId,
1655
+ serverName: "browser",
1656
+ mode: "form",
1657
+ message: "Allow ChatGPT to use Google Chrome?",
1658
+ requestedSchema: {
1659
+ type: "object",
1660
+ properties: { approval: { type: "string", enum: ["once", "always"] } },
1661
+ required: ["approval"],
1662
+ },
1663
+ },
1664
+ },
1665
+ },
1666
+ {
1667
+ type: "expect_outbound",
1668
+ frame: { id: 0, result: { action: "accept", content: { approval: "once" } } },
1669
+ },
1670
+ {
1671
+ type: "emit_inbound",
1672
+ frame: {
1673
+ method: "turn/completed",
1674
+ params: {
1675
+ threadId: nativeThreadId,
1676
+ turn: makeCodexReplayTurn({ id: nativeTurnId, status: "completed" }),
1677
+ },
1678
+ },
1679
+ },
1680
+ ],
1681
+ }),
1682
+ (event) =>
1683
+ event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending"
1684
+ ? Queue.offer(pending, event.runtimeRequest)
1685
+ : Effect.void,
1686
+ );
1687
+ const turnInput = makeCodexTestTurnInput({
1688
+ threadId: harness.threadId,
1689
+ providerThread: harness.providerThread,
1690
+ now: yield* DateTime.now,
1691
+ attemptId: RunAttemptId.make(`mcp-approval-${turnIdKind}-attempt`),
1692
+ text: prompt,
1693
+ });
1694
+ yield* harness.runtime.startTurn({
1695
+ ...turnInput,
1696
+ runtimePolicy: { ...turnInput.runtimePolicy, runtimeMode },
1697
+ });
1698
+ if (runtimeMode === "full-access") {
1699
+ const request = yield* Effect.raceFirst(
1700
+ harness.firstTerminal.pipe(Effect.as(undefined)),
1701
+ Queue.take(pending),
1702
+ );
1703
+ assert.isUndefined(request, "Full access must not wait for an MCP approval");
1704
+ assert.deepEqual(
1705
+ harness.terminalEvents().map((event) => event.status),
1706
+ ["completed"],
1707
+ );
1708
+ return;
1709
+ }
1710
+ const request = yield* Effect.raceFirst(
1711
+ Queue.take(pending),
1712
+ harness.firstTerminal.pipe(Effect.andThen(Effect.die("MCP approval was not presented"))),
1713
+ );
1714
+ assert.equal(request.kind, "mcp-elicitation");
1715
+ const approvals = harness.events.flatMap((event) =>
1716
+ event.type === "turn_item.updated" &&
1717
+ event.turnItem.type === "approval_request" &&
1718
+ event.turnItem.requestId === request.id
1719
+ ? [event.turnItem]
1720
+ : [],
1721
+ );
1722
+ assert.deepEqual(
1723
+ approvals.map((approval) => [approval.threadId, approval.appName, approval.prompt]),
1724
+ [[harness.threadId, "Google Chrome", "Allow ChatGPT to use Google Chrome?"]],
1725
+ );
1726
+ yield* harness.runtime.respondToRuntimeRequest({
1727
+ requestId: request.id,
1728
+ decision: "accept",
1729
+ });
1730
+ yield* harness.firstTerminal;
1731
+ assert.deepEqual(
1732
+ harness.terminalEvents().map((event) => event.status),
1733
+ ["completed"],
1734
+ );
1735
+ }).pipe(
1736
+ Effect.scoped,
1737
+ Effect.provide(
1738
+ Layer.mergeAll(
1739
+ IdAllocator.layer,
1740
+ McpProviderSessions.layer,
1741
+ NodeServices.layer,
1742
+ NodeCrypto.layer,
1743
+ ),
1744
+ ),
1745
+ ),
1746
+ );
1747
+
1748
it.effect.each(["native", "ordinary"] as const)(
1749
"resumes Codex without a prompt only for an existing conversation (%s)",
1750
(mode) =>
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+32
-12
@@ -766,7 +766,16 @@ function codexRuntimeModeTurnDefaults(runtimeMode: RuntimeMode): {
766
};
767
case "full-access":
768
return {
769
- approvalPolicy: "never",
769
+ // `never` also rejects browser and app access prompts before the client sees them.
770
+ approvalPolicy: {
771
+ granular: {
772
+ mcp_elicitations: true,
773
+ request_permissions: false,
774
+ rules: false,
775
+ sandbox_approval: false,
776
+ skill_approval: false,
777
+ },
778
+ },
779
approvalsReviewer: "user",
780
sandboxPolicy: {
781
type: "dangerFullAccess",
@@ -2526,19 +2535,25 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2535
);
2536
});
2537
2529
- // Streaming updates repeatedly await this context, including retries before registration.
2530
- const awaitActiveTurn = Effect.fnUntraced(function* (
2531
- nativeTurnId: string,
2538
+ // Native events can arrive before their turn registers, so lookups retry briefly.
2539
+ const awaitRegisteredTurn = Effect.fnUntraced(function* (
2540
+ lookup: Effect.Effect<ActiveCodexTurnContext | undefined>,
2541
attemptsRemaining = 1_000,
2542
): Effect.fn.Return<ActiveCodexTurnContext | undefined> {
2534
- const context = (yield* Ref.get(activeTurns)).get(nativeTurnId);
2543
+ const context = yield* lookup;
2544
if (context !== undefined || attemptsRemaining <= 0) {
2545
return context;
2546
}
2547
yield* Effect.yieldNow;
2539
- return yield* awaitActiveTurn(nativeTurnId, attemptsRemaining - 1);
2548
+ return yield* awaitRegisteredTurn(lookup, attemptsRemaining - 1);
2549
});
2550
2551
+ // Streaming updates repeatedly await this context; avoid a span for each update.
2552
+ const awaitActiveTurn = (nativeTurnId: string) =>
2553
+ awaitRegisteredTurn(
2554
+ Ref.get(activeTurns).pipe(Effect.map((turns) => turns.get(nativeTurnId))),
2555
+ );
2556
+
2557
const resolveItemEventContext =
2558
/* Provider events include streaming deltas; avoid a span for each update. */
2559
Effect.fnUntraced(function* (nativeTurnId: string) {
@@ -6044,29 +6059,34 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
6059
6060
yield* client.handleServerRequest("mcpServer/elicitation/request", (payload) =>
6061
Effect.gen(function* () {
6047
- if (toMcpElicitationResponse(payload, "accept").action !== "accept") {
6048
- yield* Effect.logWarning("Declined an unsupported MCP elicitation.", {
6062
+ const acceptance = toMcpElicitationResponse(payload, "accept");
6063
+ if (acceptance.action !== "accept") {
6064
+ yield* Effect.logWarning("Cancelled an unsupported MCP elicitation.", {
6065
serverName: payload.serverName,
6066
mode: payload.mode,
6067
});
6068
return {
6053
- action: "decline",
6069
+ action: "cancel",
6070
} satisfies CodexSchema.McpServerElicitationRequestResponse;
6071
}
6072
const context =
6073
payload.turnId === undefined || payload.turnId === null
6058
- ? undefined
6074
+ ? yield* awaitRegisteredTurn(findActiveTurnByNativeThreadId(payload.threadId))
6075
: yield* awaitActiveTurn(payload.turnId);
6076
if (context === undefined) {
6077
yield* Effect.logWarning(
6062
- "Declined an MCP elicitation without an active Codex turn context.",
6078
+ "Cancelled an MCP elicitation without an active Codex turn context.",
6079
{ serverName: payload.serverName },
6080
);
6081
return {
6066
- action: "decline",
6082
+ action: "cancel",
6083
} satisfies CodexSchema.McpServerElicitationRequestResponse;
6084
}
6085
6086
+ if (context.input.runtimePolicy.runtimeMode === "full-access") {
6087
+ return acceptance;
6088
+ }
6089
+
6090
const nativeRequestId =
6091
payload.mode === "url"
6092
? payload.elicitationId
apps/server/src/provider/CodexMcpElicitation.test.ts
+2
-2
@@ -146,7 +146,7 @@ describe("Codex MCP elicitation approvals", () => {
146
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
147
148
NodeAssert.deepStrictEqual(toMcpElicitationResponse(inputRequest, "accept"), {
149
- action: "decline",
149
+ action: "cancel",
150
});
151
});
152
@@ -162,7 +162,7 @@ describe("Codex MCP elicitation approvals", () => {
162
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
163
164
NodeAssert.deepStrictEqual(toMcpElicitationResponse(urlRequest, "accept"), {
165
- action: "decline",
165
+ action: "cancel",
166
});
167
});
168
apps/server/src/provider/CodexMcpElicitation.ts
+4
-2
@@ -185,8 +185,10 @@ export function toMcpElicitationResponse(
185
return { action: decision };
186
}
187
188
+ // T3 cannot answer these itself. `decline` reads as the user's refusal, and Codex's browser
189
+ // plugin saves it as a thread-wide site denial; `cancel` leaves no saved decision.
190
if (payload.mode === "url") {
189
- return { action: "decline" };
191
+ return { action: "cancel" };
192
}
193
194
const persist =
@@ -217,7 +219,7 @@ export function toMcpElicitationResponse(
219
}
220
221
if (form?.required?.some((key) => !Object.hasOwn(content, key))) {
220
- return { action: "decline" };
222
+ return { action: "cancel" };
223
}
224
225
return {
packages/effect-codex-app-server/src/replay.ts
+14
-1
@@ -203,7 +203,20 @@ function normalizeReplayFrame(value: unknown): unknown {
203
normalized.params !== null
204
) {
205
const params = { ...(normalized.params as Record<string, unknown>) };
206
- if (params.approvalPolicy === "never") {
206
+ // Older recordings used `never` for full access, before MCP prompts were kept interactive.
207
+ if (
208
+ params.approvalPolicy === "never" ||
209
+ stableStringify(params.approvalPolicy) ===
210
+ stableStringify({
211
+ granular: {
212
+ mcp_elicitations: true,
213
+ request_permissions: false,
214
+ rules: false,
215
+ sandbox_approval: false,
216
+ skill_approval: false,
217
+ },
218
+ })
219
+ ) {
220
delete params.approvalPolicy;
221
}
222
if (