Skip to content

Commit 7c6163c

Browse files
authored
fix(codex): show app access approval prompts (pingdotgg#8058)
1 parent 10626c5 commit 7c6163c

24 files changed

Lines changed: 1096 additions & 95 deletions

‎apps/mobile/src/features/threads/PendingApprovalCard.tsx‎

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { ApprovalRequestId, ProviderApprovalDecision } from "@t3tools/contracts";
1+
import type {
2+
ApprovalRequestId,
3+
ProviderApprovalDecision,
4+
ProviderApprovalOption,
5+
} from "@t3tools/contracts";
26
import { Pressable, View } from "react-native";
37

48
import { AppText as Text } from "../../components/AppText";
@@ -13,7 +17,14 @@ export interface PendingApprovalCardProps {
1317
) => Promise<unknown>;
1418
}
1519

20+
const DEFAULT_APPROVAL_OPTIONS = [
21+
{ decision: "accept", label: "Allow once" },
22+
{ decision: "acceptForSession", label: "Allow session" },
23+
{ decision: "decline", label: "Decline" },
24+
] satisfies ReadonlyArray<ProviderApprovalOption>;
25+
1626
export function PendingApprovalCard(props: PendingApprovalCardProps) {
27+
const options = props.approval.options ?? DEFAULT_APPROVAL_OPTIONS;
1728
// Opaque for the same reason as PendingUserInputCard: nothing blurs the feed
1829
// behind this card, so a translucent surface bleeds messages through it.
1930
return (
@@ -22,37 +33,40 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {
2233
Approval needed
2334
</Text>
2435
<Text className="font-t3-bold text-lg text-neutral-950 dark:text-neutral-50">
25-
{props.approval.requestKind}
36+
{props.approval.appName ?? props.approval.requestKind}
2637
</Text>
2738
{props.approval.detail ? (
2839
<Text className="font-sans text-sm leading-normal text-neutral-600 dark:text-neutral-400">
2940
{props.approval.detail}
3041
</Text>
3142
) : null}
3243
<View className="flex-row flex-wrap gap-2.5">
33-
<Pressable
34-
className="items-center justify-center rounded-[14px] bg-blue-500 px-3.5 py-3"
35-
disabled={props.respondingApprovalId === props.approval.requestId}
36-
onPress={() => void props.onRespond(props.approval.requestId, "accept")}
37-
>
38-
<Text className="font-t3-extrabold text-sm text-white">Allow once</Text>
39-
</Pressable>
40-
<Pressable
41-
className="items-center justify-center rounded-[14px] bg-neutral-200 px-3.5 py-3 dark:bg-neutral-800"
42-
disabled={props.respondingApprovalId === props.approval.requestId}
43-
onPress={() => void props.onRespond(props.approval.requestId, "acceptForSession")}
44-
>
45-
<Text className="font-t3-bold text-sm text-neutral-950 dark:text-neutral-50">
46-
Allow session
47-
</Text>
48-
</Pressable>
49-
<Pressable
50-
className="items-center justify-center rounded-[14px] bg-rose-100 px-3.5 py-3 dark:bg-rose-500/18"
51-
disabled={props.respondingApprovalId === props.approval.requestId}
52-
onPress={() => void props.onRespond(props.approval.requestId, "decline")}
53-
>
54-
<Text className="font-t3-bold text-sm text-rose-700 dark:text-rose-300">Decline</Text>
55-
</Pressable>
44+
{options.map((option) => (
45+
<Pressable
46+
key={option.decision}
47+
className={`items-center justify-center rounded-[14px] px-3.5 py-3 ${
48+
option.decision === "accept"
49+
? "bg-blue-500"
50+
: option.decision === "decline"
51+
? "bg-rose-100 dark:bg-rose-500/18"
52+
: "bg-neutral-200 dark:bg-neutral-800"
53+
}`}
54+
disabled={props.respondingApprovalId === props.approval.requestId}
55+
onPress={() => void props.onRespond(props.approval.requestId, option.decision)}
56+
>
57+
<Text
58+
className={`text-sm ${
59+
option.decision === "accept"
60+
? "font-t3-extrabold text-white"
61+
: option.decision === "decline"
62+
? "font-t3-bold text-rose-700 dark:text-rose-300"
63+
: "font-t3-bold text-neutral-950 dark:text-neutral-50"
64+
}`}
65+
>
66+
{option.label}
67+
</Text>
68+
</Pressable>
69+
))}
5670
</View>
5771
</View>
5872
);

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
buildPendingUserInputAnswers,
1717
buildThreadFeed,
18+
derivePendingApprovals,
1819
deriveThreadFeedPresentation,
1920
isPendingUserInputOptionSelected,
2021
setPendingUserInputCustomAnswer,
@@ -142,6 +143,59 @@ describe("pending user input answers", () => {
142143
});
143144
});
144145

146+
describe("pending approvals", () => {
147+
it("keeps app access approvals and persistence choices from remote environments", () => {
148+
const options = [
149+
{ decision: "decline", label: "Decline" },
150+
{ decision: "acceptAlways", label: "Always allow Safari" },
151+
{ decision: "accept", label: "Approve" },
152+
];
153+
const activity = makeActivity({
154+
id: EventId.make("approval-safari"),
155+
kind: "approval.requested",
156+
summary: "App access approval requested",
157+
createdAt: "2026-08-24T00:00:00.000Z",
158+
payload: {
159+
requestId: "req-safari",
160+
requestType: "mcp_elicitation_approval",
161+
detail: "Allow ChatGPT to use Safari?",
162+
appName: "Safari",
163+
options,
164+
},
165+
});
166+
167+
expect(derivePendingApprovals([activity])).toEqual([
168+
{
169+
requestId: "req-safari",
170+
requestKind: "mcp-elicitation",
171+
createdAt: "2026-08-24T00:00:00.000Z",
172+
detail: "Allow ChatGPT to use Safari?",
173+
appName: "Safari",
174+
options,
175+
},
176+
]);
177+
});
178+
179+
it("removes an app access approval after a remote client rejects it", () => {
180+
const requested = makeActivity({
181+
id: EventId.make("approval-safari-open"),
182+
kind: "approval.requested",
183+
summary: "App access approval requested",
184+
createdAt: "2026-08-24T00:00:00.000Z",
185+
payload: { requestId: "req-safari", requestKind: "mcp-elicitation" },
186+
});
187+
const resolved = makeActivity({
188+
id: EventId.make("approval-safari-resolved"),
189+
kind: "approval.resolved",
190+
summary: "Approval resolved",
191+
createdAt: "2026-08-24T00:00:01.000Z",
192+
payload: { requestId: "req-safari", decision: "decline" },
193+
});
194+
195+
expect(derivePendingApprovals([requested, resolved])).toEqual([]);
196+
});
197+
});
198+
145199
function makeActivity(
146200
input: Partial<OrchestrationThreadActivity> &
147201
Pick<OrchestrationThreadActivity, "id" | "kind" | "summary" | "createdAt">,

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { ApprovalRequestId, isToolLifecycleItemType } from "@t3tools/contracts";
1+
import {
2+
ApprovalRequestId,
3+
isToolLifecycleItemType,
4+
ProviderApprovalOption,
5+
ProviderRequestKind,
6+
} from "@t3tools/contracts";
27
import type {
38
OrchestrationLatestTurn,
49
OrchestrationThread,
@@ -11,14 +16,20 @@ import { formatDuration } from "@t3tools/shared/orchestrationTiming";
1116

1217
import * as Arr from "effect/Array";
1318
import * as Order from "effect/Order";
19+
import * as Schema from "effect/Schema";
1420

1521
export interface PendingApproval {
1622
readonly requestId: ApprovalRequestId;
17-
readonly requestKind: "command" | "file-read" | "file-change";
23+
readonly requestKind: ProviderRequestKind;
1824
readonly createdAt: string;
1925
readonly detail?: string;
26+
readonly appName?: string;
27+
readonly options?: ReadonlyArray<ProviderApprovalOption>;
2028
}
2129

30+
const isProviderRequestKind = Schema.is(ProviderRequestKind);
31+
const isProviderApprovalOption = Schema.is(ProviderApprovalOption);
32+
2233
export interface PendingUserInput {
2334
readonly requestId: ApprovalRequestId;
2435
readonly createdAt: string;
@@ -147,6 +158,8 @@ function requestKindFromRequestType(requestType: unknown): PendingApproval["requ
147158
case "file_change_approval":
148159
case "apply_patch_approval":
149160
return "file-change";
161+
case "mcp_elicitation_approval":
162+
return "mcp-elicitation";
150163
default:
151164
return null;
152165
}
@@ -1375,20 +1388,23 @@ export function derivePendingApprovals(
13751388
? (activity.payload as Record<string, unknown>)
13761389
: null;
13771390
const requestId = parseApprovalRequestId(payload?.requestId);
1378-
const requestKind =
1379-
payload?.requestKind === "command" ||
1380-
payload?.requestKind === "file-read" ||
1381-
payload?.requestKind === "file-change"
1382-
? payload.requestKind
1383-
: requestKindFromRequestType(payload?.requestType);
1391+
const requestKind = isProviderRequestKind(payload?.requestKind)
1392+
? payload.requestKind
1393+
: requestKindFromRequestType(payload?.requestType);
13841394
const detail = typeof payload?.detail === "string" ? payload.detail : undefined;
1395+
const appName = typeof payload?.appName === "string" ? payload.appName : undefined;
1396+
const options = Array.isArray(payload?.options)
1397+
? payload.options.filter(isProviderApprovalOption)
1398+
: undefined;
13851399

13861400
if (activity.kind === "approval.requested" && requestId && requestKind) {
13871401
openByRequestId.set(requestId, {
13881402
requestId,
13891403
requestKind,
13901404
createdAt: activity.createdAt,
13911405
...(detail ? { detail } : {}),
1406+
...(appName ? { appName } : {}),
1407+
...(options && options.length > 0 ? { options } : {}),
13921408
});
13931409
continue;
13941410
}

‎apps/server/integration/OrchestrationEngineHarness.integration.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ProviderDriverKind,
99
type OrchestrationEvent,
1010
type OrchestrationThread,
11+
type ProviderApprovalDecision,
1112
} from "@t3tools/contracts";
1213
import * as Effect from "effect/Effect";
1314
import * as Exit from "effect/Exit";
@@ -199,14 +200,14 @@ export interface OrchestrationIntegrationHarness {
199200
requestId: string,
200201
predicate: (row: {
201202
readonly status: "pending" | "resolved";
202-
readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
203+
readonly decision: ProviderApprovalDecision | null;
203204
readonly resolvedAt: string | null;
204205
}) => boolean,
205206
timeoutMs?: number,
206207
) => Effect.Effect<
207208
{
208209
readonly status: "pending" | "resolved";
209-
readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
210+
readonly decision: ProviderApprovalDecision | null;
210211
readonly resolvedAt: string | null;
211212
},
212213
never
@@ -493,15 +494,15 @@ export const makeOrchestrationIntegrationHarness = (
493494
row,
494495
): row is {
495496
readonly status: "pending" | "resolved";
496-
readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
497+
readonly decision: ProviderApprovalDecision | null;
497498
readonly resolvedAt: string | null;
498499
} => row !== null && predicate(row),
499500
`pending approval '${requestId}'`,
500501
timeoutMs,
501502
) as Effect.Effect<
502503
{
503504
readonly status: "pending" | "resolved";
504-
readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
505+
readonly decision: ProviderApprovalDecision | null;
505506
readonly resolvedAt: string | null;
506507
},
507508
never

‎apps/server/src/orchestration/Layers/ProjectionPipeline.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
15071507
const resolvedDecision =
15081508
resolvedDecisionRaw === "accept" ||
15091509
resolvedDecisionRaw === "acceptForSession" ||
1510+
resolvedDecisionRaw === "acceptAlways" ||
15101511
resolvedDecisionRaw === "decline" ||
15111512
resolvedDecisionRaw === "cancel"
15121513
? resolvedDecisionRaw

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.approval.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,41 @@ describe("runtimeEventToActivities approval details", () => {
3030
expect(activity?.kind).toBe("approval.requested");
3131
expect((activity?.payload as Record<string, unknown> | undefined)?.detail).toBe(detail);
3232
});
33+
34+
it("keeps app details and approval options available to remote clients", () => {
35+
const options = [
36+
{ decision: "decline", label: "Decline" },
37+
{ decision: "acceptAlways", label: "Always allow Safari" },
38+
{ decision: "accept", label: "Approve" },
39+
] as const;
40+
const event = {
41+
type: "request.opened",
42+
eventId: EventId.make("evt-mcp-elicitation"),
43+
provider: ProviderDriverKind.make("codex"),
44+
createdAt: "2026-08-24T00:00:00.000Z",
45+
threadId: ThreadId.make("thread-1"),
46+
requestId: RuntimeRequestId.make("approval-safari"),
47+
payload: {
48+
requestType: "mcp_elicitation_approval",
49+
detail: "Allow ChatGPT to use Safari?",
50+
appName: "Safari",
51+
options,
52+
},
53+
} satisfies ProviderRuntimeEvent;
54+
55+
const [activity] = runtimeEventToActivities(event);
56+
57+
expect(activity).toMatchObject({
58+
kind: "approval.requested",
59+
summary: "App access approval requested",
60+
payload: {
61+
requestId: "approval-safari",
62+
requestKind: "mcp-elicitation",
63+
requestType: "mcp_elicitation_approval",
64+
detail: "Allow ChatGPT to use Safari?",
65+
appName: "Safari",
66+
options,
67+
},
68+
});
69+
});
3370
});

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function sessionStatusAllowsActiveTurn(
298298

299299
function requestKindFromCanonicalRequestType(
300300
requestType: string | undefined,
301-
): "command" | "file-read" | "file-change" | undefined {
301+
): "command" | "file-read" | "file-change" | "mcp-elicitation" | undefined {
302302
switch (requestType) {
303303
case "command_execution_approval":
304304
case "exec_command_approval":
@@ -308,6 +308,8 @@ function requestKindFromCanonicalRequestType(
308308
case "file_change_approval":
309309
case "apply_patch_approval":
310310
return "file-change";
311+
case "mcp_elicitation_approval":
312+
return "mcp-elicitation";
311313
default:
312314
return undefined;
313315
}
@@ -388,12 +390,16 @@ export function runtimeEventToActivities(
388390
? "File-read approval requested"
389391
: requestKind === "file-change"
390392
? "File-change approval requested"
391-
: "Approval requested",
393+
: requestKind === "mcp-elicitation"
394+
? "App access approval requested"
395+
: "Approval requested",
392396
payload: {
393397
requestId: toApprovalRequestId(event.requestId),
394398
...(requestKind ? { requestKind } : {}),
395399
requestType: event.payload.requestType,
396400
...(event.payload.detail ? { detail: event.payload.detail } : {}),
401+
...(event.payload.appName ? { appName: event.payload.appName } : {}),
402+
...(event.payload.options ? { options: event.payload.options } : {}),
397403
},
398404
turnId: toTurnId(event.turnId) ?? null,
399405
...maybeSequence,

0 commit comments

Comments
 (0)