Skip to content

Show Codex file-change approvals as a diff card instead of failing them - #1639

Merged
currentbits merged 4 commits into
mainfrom
coder/codex-filechange-requestapproval-needs-a-f04a6c
Oct 15, 2026
Merged

currentbits merged 4 commits into
mainfrom
coder/codex-filechange-requestapproval-needs-a-f04a6c

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #1189.

Codex app-server's item/fileChange/requestApproval used to be fail-closed with a JSON-RPC error because no UI could show what the agent wanted to write. This PR maps it onto the existing pending-permission queue and renders the proposed changes as a diff in the permission card.

The request only names an itemId and carries no diff. The changes live on the fileChange item announced in item/started.

Changes

  • runner-provider-codex.js: keeps each in-flight file_change item's changes in codexFileChanges, keyed by item id, and drops the entry on item.completed.
  • codexApprovals.js:
    • classifyServerRequest now returns action: "fileChange" and no longer lists the method as unsupported.
    • New pendingFromFileChange builds an Edit pending permission. Its summary is the first path plus a count of any other files, and it includes the ask's reason and grantRoot.
    • New fileChangePatch turns Codex changes into a git-style patch:
      • It handles add, delete, update and move.
      • Paths inside the worktree (or the project path when there's no worktree) are shown relative; paths outside it stay absolute.
      • The whole patch is capped at 200k chars, with a truncation marker past that.
  • runner-permissions.js:
    • If no item/started was seen for the itemId, the ask still fails closed with an error, so nothing is approved without its diff.
    • Guardrails run classifyTool on every touched path, move target and grantRoot, and the strictest result applies: any deny wins over ask.
    • fileChange is passed through to the renderer in the pending-permission info.
  • src/shared/ipc.ts: adds fileChange?: { diff, reason, grantRoot } to PendingPermissionInfo.
  • cards.tsx: when fileChange is present, PermissionPrompt shows:
    • the reason, if there is one;
    • a warning when grantRoot asks for session-wide write access under a directory;
    • the patch, parsed with parsePatch and drawn with the existing FileHunks unified view.

Tests

  • Unit test for fileChangePatch covering delete, a move, and a path outside the root.
  • A new ask-file-change scenario in the fake Codex CLI sends item/started and then the approval request. An end-to-end test checks the pending diff, reason and grantRoot, and that allowAlways replies acceptForSession.
  • Renderer test in test/permissionPrompt.test.tsx for the file-change card.
  • Existing fail-closed tests were renamed to match the new behaviour: errors are now returned only when the item/started is missing or no handler takes the request.
  • The app-server test's temp dir now goes through realpathSync, so the fake's process.cwd() (/private/var/... on macOS) matches the expected relative paths.

🤖 Generated with Claude Code

Solenta-Message-Id: 42506aaf-d5c8-4b1b-8c4f-120a5fe57a74
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T15:31:32.001190Z 2786bfb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2786bfbd9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<div className={diffStyles.patch} data-permission-diff="">
{patches.map((p) => (
<Fragment key={p.path}>
<div className={diffStyles.hunkHead}>{p.path}</div>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Show the source path for moved files

For an update with move_path, parsePatch selects the +++ destination as p.path, and this heading plus FileHunks is the entire visible diff. The original c.path exists only in patch headers that are never rendered, so a pure rename with an empty diff appears as just the destination and gives no indication that the source file will disappear. Render the source-to-destination rename explicitly before allowing approval.

Useful? React with 👍 / 👎.

Comment on lines +214 to +216
return patch.length <= FILE_CHANGE_DIFF_MAX
? patch
: `${patch.slice(0, FILE_CHANGE_DIFF_MAX)}\n\\ diff truncated (${patch.length - FILE_CHANGE_DIFF_MAX} more chars)\n`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the truncation warning visible outside parsed hunks

When a patch exceeds 200,000 characters and the cutoff lands between file sections or inside a diff --git/---/+++ header, the appended truncation marker is not inside an @@ hunk. parsePatch and FileHunks therefore discard the marker, while edits in the remaining tail are also omitted and the Accept buttons remain enabled. Surface truncation as structured card metadata outside the patch parser so users cannot unknowingly approve an incomplete diff.

Useful? React with 👍 / 👎.

Willem and others added 3 commits October 15, 2026 17:40
path.relative returned src\a.js on Windows, so the git-style patch
headers read a/src\a.js and failed the windows-latest electron test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…keep #1190

main's #1190 also mapped item/fileChange/requestApproval, as a JSON dump of
the streamed item. Kept this branch's diff card and itemId lookup for file
changes; the approval action and pendingFromApproval now cover only
item/permissions/requestApproval. One ask-file-change fake scenario.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@currentbits
currentbits merged commit 58b71f3 into main Oct 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex fileChange requestApproval needs a diff card via item/started

1 participant