Skip to content

fix(agent): make pair-mode edits work on the first try - #408

Merged
fcoury merged 1 commit into
mainfrom
fix/agent-pair-e2e-findings
Oct 18, 2026
Merged

fcoury merged 1 commit into
mainfrom
fix/agent-pair-e2e-findings

Conversation

@fcoury

@fcoury fcoury commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

An end-to-end evaluation of pair mode against a real Codex app-server (38 threads, 63 turns) found two bugs that made agent edits fail even though nothing was wrong with the request.

Why

The agent refused to edit. Codex tells the model that its sandbox is read-only. Red's instructions said "You have no shell or native patch tool" but never said that the read-only sandbox only covers those missing tools. The model often concluded it could not change files and pasted code for the user to apply instead. On main it refused in 1 of 6 fresh sessions with a clean buffer, and in 5 of 5 when the target buffer had unsaved changes. Once a session refused, it kept refusing.

The first edit of an unopened file always failed as stale. read_file on a file without a buffer returns a disk revision token, and #406 marked those tokens with bit 63. Codex runs tool calls through a JavaScript runner, which rounds integers above 2^53, so 15400823821884425090 came back as 15400823821884424000 and apply_edits rejected it with stale_revision. The agent recovered by re-reading, at the cost of one wasted round-trip for every file it touched.

What changed

  • src/codex/mod.rs: INSTRUCTIONS now says the read-only sandbox applies only to the missing shell and patch tools, and that apply_edits and write_file are the supported way to change files.
  • src/editor.rs: disk tokens use bit 52 as their marker and a 52-bit hash, so they are exact JavaScript integers. Buffer revisions are edit counters and never reach that range.

Measured with the same prompt ("Add a doc comment to the summarize function in src/report.rs. Change nothing else.") in fresh sessions:

Build Clean buffer Unsaved changes
main 5 / 6 edited 0 / 5 edited
This PR 6 / 6 edited 5 / 5 edited

How to Test

  1. Open a Rust file in a git repo, type something without saving, then press Space A and ask "Add a doc comment to the main function. Change nothing else."
  2. Expected: the agent edits the file with apply_edits instead of replying that the session is read-only.
  3. Ask the agent to add a function to a file you have not opened.
  4. Expected: the edit lands on the first apply_edits. In the newest ~/.codex/sessions/**/rollout-*.jsonl, the revision passed to apply_edits equals the one read_file returned, and there is no stale_revision result.

Targeted tests:

  • cargo test --lib agent_disk_revisions_survive_a_javascript_number_round_trip
  • cargo test --lib agent_reads_of_unopened_files_leave_buffers_alone_and_guard_later_writes

Codex tells the model its sandbox is read-only, and Red's instructions
never said that only covers the shell and patch tools it lacks, so the
agent often refused to edit (always when the buffer had unsaved
changes). Say that apply_edits and write_file are the supported way to
change files.

Disk revision tokens used bit 63, but Codex runs tool calls through
JavaScript, which rounds integers above 2^53. Every first edit of an
unopened file came back as a stale revision. Keep tokens in 53 bits.
@fcoury

fcoury commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-18T00:11:02.709353Z e717f22 Manual request
ℹ️ 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: e717f227de

ℹ️ 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".

@fcoury
fcoury merged commit b56eea7 into main Oct 18, 2026
12 checks passed
@fcoury
fcoury deleted the fix/agent-pair-e2e-findings branch October 18, 2026 00:11
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.

1 participant