:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): preserve native codex approval choices (#97542)
Peter Kirkhama97c643b6f10
diff --git a/products/desktop/docs/TROUBLESHOOTING.md b/products/desktop/docs/TROUBLESHOOTING.mdindex d3fc3d4628d0..6d67c771d5b2 100644--- a/products/desktop/docs/TROUBLESHOOTING.md+++ b/products/desktop/docs/TROUBLESHOOTING.md@@ -1,5 +1,24 @@# Troubleshooting+## Codex asks for the same permissions again++Codex Auto keeps approvals for actions outside its allowed scope.+On macOS, it allows workspace writes but restricts network access.+Auto is not Full access.+These settings apply to all GPT models in the Codex adapter.++Choose **Allow these permissions for this session** to reuse a permission grant across turns.+**Allow for this turn** does not grant access for later turns.+Both choices grant only the permissions shown in the request.++For network approvals, Codex can offer an option to allow or block a host for future requests.+The desktop app shows these options only when Codex supplies them and returns the selected decision unchanged.+Codex owns rule storage and enforcement; the desktop app does not create a separate allowlist.++These choices follow the native Codex 0.144.0 approval dialog.+They preserve the current session permission mode and do not enable automatic approval review or remove sandbox limits.+Compare clients with the same workspace, permission settings, saved rules, and approval reviewer.+## Black screen during developmentIf the app launches but renders a blank/black screen, it's almost always a stale Vite cache.diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.test.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.test.tsindex 82e85b830e35..ff9bfcd80cc1 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.test.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.test.ts@@ -257,13 +257,14 @@ describe("handleServerRequest", () => {});it.each([- // "allow_once" grants for the turn, not session-wide; reject grants nothing.- { optionId: "allow", expected: { network: { enabled: true } } },- { optionId: "reject", expected: {} },+ { optionId: "allow", scope: "turn", granted: true },+ { optionId: "allow_session", scope: "session", granted: true },+ { optionId: "reject", scope: "turn", granted: false },+ { optionId: "unknown", scope: "turn", granted: false },])("resolves a permission approval on $optionId",- async ({ optionId, expected }) => {- const { client } = fakeClient([{ outcome: "selected", optionId }]);+ async ({ optionId, scope, granted }) => {+ const { client, calls } = fakeClient([{ outcome: "selected", optionId }]);const params = {threadId: "t",@@ -275,7 +276,7 @@ describe("handleServerRequest", () => {reason: "needs network",permissions: {network: { enabled: true },- fileSystem: null,+ fileSystem: { read: null, write: ["/repo/build"] },},};@@ -288,9 +289,19 @@ describe("handleServerRequest", () => {expect(result.handled).toBe(true);expect(result.response).toEqual({- permissions: expected,- scope: "turn",+ permissions: granted ? params.permissions : {},+ scope,+ });+ expect(calls[0].options).toContainEqual({+ kind: "allow_always",+ name: "Allow these permissions for this session",+ optionId: "allow_session",+ _meta: {+ description: JSON.stringify(params.permissions, null, 2),+ preservePermissionMode: true,+ },});+ expect(calls[0].toolCall.rawInput).toEqual(params.permissions);},);diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.tsindex 5f9a1dfc887a..06048b73fb02 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/approvals.ts@@ -132,6 +132,52 @@ export interface HandleServerRequestOptions {}) => boolean;}+export function networkApprovalOptions(+ availableDecisions: unknown[],+): Array<{ option: PermissionOption; decision: unknown }> {+ return availableDecisions.flatMap((decision, index) => {+ if (+ !decision ||+ typeof decision !== "object" ||+ !("applyNetworkPolicyAmendment" in decision)+ ) {+ return [];+ }+ const amendment = decision.applyNetworkPolicyAmendment;+ if (+ !amendment ||+ typeof amendment !== "object" ||+ !("network_policy_amendment" in amendment)+ ) {+ return [];+ }+ const policy = amendment.network_policy_amendment;+ if (+ !policy ||+ typeof policy !== "object" ||+ !("host" in policy) ||+ typeof policy.host !== "string" ||+ !policy.host ||+ !("action" in policy) ||+ (policy.action !== "allow" && policy.action !== "deny")+ ) {+ return [];+ }+ const allow = policy.action === "allow";+ return [+ {+ option: {+ optionId: `network_${index}`,+ kind: allow ? "allow_always" : "reject_always",+ name: `${allow ? "Allow" : "Block"} ${policy.host} for future requests`,+ _meta: { preservePermissionMode: true },+ },+ decision,+ },+ ];+ });+}+/*** Routes a server-initiated request to the matching richer-response handler.* Returns `{ handled: false }` for anything this module doesn't own.@@ -294,16 +340,29 @@ async function handlePermissionsApproval(let response: RequestPermissionResponse;try {+ const description = JSON.stringify(params.permissions, null, 2);response = await client.requestPermission({sessionId: opts.sessionId,options: [- { kind: "allow_once", name: "Allow", optionId: "allow" },+ {+ kind: "allow_once",+ name: "Allow for this turn",+ optionId: "allow",+ _meta: { description },+ },+ {+ kind: "allow_always",+ name: "Allow these permissions for this session",+ optionId: "allow_session",+ _meta: { description, preservePermissionMode: true },+ },{ kind: "reject_once", name: "Reject", optionId: "reject" },],toolCall: {toolCallId: params.itemId,title: params.reason ?? "Grant additional permissions",kind: "other",+ rawInput: params.permissions,},});} catch (err) {@@ -316,12 +375,12 @@ async function handlePermissionsApproval(if (response.outcome.outcome === "selected" &&- response.outcome.optionId === "allow"+ (response.outcome.optionId === "allow" ||+ response.outcome.optionId === "allow_session")) {- // Grant only what was requested, scoped to this turn (option is "allow_once").return {permissions: grantedFromRequested(params.permissions),- scope: "turn",+ scope: response.outcome.optionId === "allow_session" ? "session" : "turn",};}return denied;diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.tsindex 9c53c4eecea8..e5380fff4929 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.test.ts@@ -1391,6 +1391,70 @@ describe("CodexAppServerAgent", () => {expect(decision).toEqual({ decision: "acceptForSession" });});+ it.each([+ { action: "allow", kind: "allow_always", label: "Allow" },+ { action: "deny", kind: "reject_always", label: "Block" },+ ])(+ "preserves the native network $action decision",+ async ({ action, kind, label }) => {+ const { agent, stub, permissionOptions } = makeApprovalAgent("network_1");+ await agent.initialize(init);+ await agent.newSession({ cwd: "/repo" } as unknown as NewSessionRequest);++ const amendment = {+ applyNetworkPolicyAmendment: {+ network_policy_amendment: { host: "example.com", action },+ },+ };+ const decision = await stub.invokeRequest(+ "item/commandExecution/requestApproval",+ {+ itemId: "network-1",+ command: "curl https://example.com",+ networkApprovalContext: { host: "example.com", protocol: "https" },+ availableDecisions: ["accept", amendment, "decline"],+ },+ );++ expect(permissionOptions[0]).toContainEqual({+ optionId: "network_1",+ kind,+ name: `${label} example.com for future requests`,+ _meta: { preservePermissionMode: true },+ });+ expect((decision as { decision: unknown }).decision).toBe(amendment);+ },+ );++ it.each([+ null,+ { network_policy_amendment: null },+ { network_policy_amendment: { host: "example.com", action: "unknown" } },+ { network_policy_amendment: { action: "allow" } },+ ])("does not grant an invalid network decision %j", async (payload) => {+ const { agent, stub, permissionOptions } = makeApprovalAgent("network_1");+ await agent.initialize(init);+ await agent.newSession({ cwd: "/repo" } as unknown as NewSessionRequest);++ const decision = await stub.invokeRequest(+ "item/commandExecution/requestApproval",+ {+ itemId: "network-1",+ command: "curl https://example.com",+ availableDecisions: [+ "accept",+ { applyNetworkPolicyAmendment: payload },+ "decline",+ ],+ },+ );++ expect(permissionOptions[0].map((option) => option.optionId)).not.toContain(+ "network_1",+ );+ expect(decision).toEqual({ decision: "decline" });+ });+it("omits Allow-always when codex offers no remember decision for a command", async () => {const { agent, stub, permissionOptions } = makeApprovalAgent("allow");await agent.initialize(init);diff --git a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.tsindex b230a543f6a5..ff6b540e7a13 100644--- a/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts+++ b/products/desktop/packages/agent/src/adapters/codex-app-server/codex-app-server-agent.ts@@ -74,7 +74,7 @@ import {type AppServerClientHandlers,type AppServerRpc,} from "./app-server-client";-import { handleServerRequest } from "./approvals";+import { handleServerRequest, networkApprovalOptions } from "./approvals";import {buildSdkSessionParams,buildTurnCompleteParams,@@ -2368,6 +2368,9 @@ export class CodexAppServerAgent extends BaseAcpAgent {const availableDecisions = Array.isArray(detail.availableDecisions)? detail.availableDecisions: [];+ const networkOptions = isFileChange+ ? []+ : networkApprovalOptions(availableDecisions);const offeredRememberDecision =availableDecisions.find((d) =>@@ -2454,6 +2457,7 @@ export class CodexAppServerAgent extends BaseAcpAgent {},]: []),+ ...networkOptions.map(({ option }) => option),{ optionId: "reject", name: "Reject", kind: "reject_once" },{optionId: "reject_with_feedback",@@ -2464,6 +2468,13 @@ export class CodexAppServerAgent extends BaseAcpAgent {],});if (response.outcome.outcome === "selected") {+ const selectedOptionId = response.outcome.optionId;+ const networkOption = networkOptions.find(+ ({ option }) => option.optionId === selectedOptionId,+ );+ if (networkOption) {+ return { decision: networkOption.decision };+ }if (response.outcome.optionId === "allow_always" && rememberDecision) {// Echo codex's "approve and remember" decision so it applies the proposed amendment.return { decision: rememberDecision };diff --git a/products/desktop/packages/core/src/sessions/permissionResponse.test.ts b/products/desktop/packages/core/src/sessions/permissionResponse.test.tsindex 6ef63d7c0d8b..3a265fc3bddd 100644--- a/products/desktop/packages/core/src/sessions/permissionResponse.test.ts+++ b/products/desktop/packages/core/src/sessions/permissionResponse.test.ts@@ -103,6 +103,25 @@ describe("planPermissionResponse", () => {expect(plan.applyAllowAlwaysUpgrade).toBe(false);});+ it.each(["allow_session", "network_1"])(+ "preserves the session mode for the scoped %s grant",+ (optionId) => {+ const permission = makePermission([+ {+ optionId,+ kind: "allow_always",+ _meta: { preservePermissionMode: true },+ },+ ]);++ expect(planPermissionResponse(permission, optionId)).toEqual({+ applyAllowAlwaysUpgrade: false,+ respondWithCustomInput: false,+ resendPromptText: null,+ });+ },+ );+it("keeps auto mode when always allowing a tool", () => {const modeOption: SessionConfigOption = {id: "mode",diff --git a/products/desktop/packages/core/src/sessions/permissionResponse.ts b/products/desktop/packages/core/src/sessions/permissionResponse.tsindex 279e238efcfa..7a38829d52db 100644--- a/products/desktop/packages/core/src/sessions/permissionResponse.ts+++ b/products/desktop/packages/core/src/sessions/permissionResponse.ts@@ -120,7 +120,9 @@ export function planPermissionResponse();const isModeSwitch = permission.toolCall?.kind === "switch_mode";const applyAllowAlwaysUpgrade =- selectedOption?.kind === "allow_always" && !isModeSwitch;+ selectedOption?.kind === "allow_always" &&+ !isModeSwitch &&+ selectedOption._meta?.preservePermissionMode !== true;const optionTakesCustomInput =isOtherPermissionOption(optionId) ||