Repository navigation
fix(agent): harden pair-mode cancel, tool paths, reads and turn status - #406
Merged
Merged
Conversation
…buffers Agent tool path resolution only blocked sensitive and gitignored paths, so write_file to .git/hooks/pre-commit, .red/, red.toml or .vscode/tasks.json replaced a buffer and returned applied-but-unsaved, leaving a dirty buffer a later user save could persist. Writes now share the LSP protected-path check before any buffer is opened, reads refuse version-control metadata (which can hold credential URLs), and the agent file walkers no longer descend into .git, .hg, .jj or .svn, which crowded real files out of the walk budget.
… ends Cancelling marked the session idle in the editor immediately, but Codex keeps running the turn until it confirms the interrupt. A prompt sent in that window was dropped by the worker, which skipped turn/start for a busy thread without reporting anything, and the interrupted turn's completion was then recorded as the new turn finishing. The editor now keeps a cancelled session busy until its Completed or Failed event and queues prompts for busy sessions, the worker fails loudly instead of silently skipping a turn, and a rejected interrupt can be retried. The Agent pane also closed the Codex thread after every cancel and restarted from a 6,000-character transcript recap, an ACP-era workaround that the direct app-server does not need. Cancelling now keeps the thread. Queued follow-ups pause after a stopped or failed turn instead of running unattended, and :AgentSendQueued / :AgentDiscardQueued resume or drop them.
Every agent read_file pushed a buffer that was never closed and switched the active buffer twice, each switch requesting diagnostics and repainting. A long session flooded the buffer list and made the screen flicker even with follow mode off. Reads now report an open buffer's live contents in place, and read unopened files from disk with a content-derived revision token. Write, edit, annotation and LSP tools accept that token only while the buffer still holds the same contents, so a file that changed after the read is still rejected as stale.
…urface turn state The editor tracked a turn's lifecycle in separate active and stopping sets, and terminal events carried no turn id, so the pane could not tell a late event from an earlier turn apart from the one on screen. Sessions now have a single Running/Stopping phase, the turn id survives until the turn really ends, and completed/cancelled/error events carry it so the pane ignores stale ones. The agent_activity statusline field said "following" for any running turn even with follow mode off and was not in the default layout. It now reports working, following, or stopping plus queued prompts, hides when idle, and sits on the right by default. A turn that finishes while the pane is hidden prints a notice.
Contributor
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98924eef58
ℹ️ 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".
Prompts queued in the editor behind a stopping turn were dropped and only logged if the Codex app-server died before the turn ended. The editor now hands them back in an agent:prompts_returned event, and the Agent pane keeps them as paused follow-ups that :AgentSendQueued can send once Codex restarts.
read_file no longer opens buffers, so lsp_prepare_rename, lsp_preview_rename and file diagnostics failed with "read_file must open this file" for any file the user had not opened. The LSP path now loads the buffer in the background, without changing the active buffer, and accepts the disk revision token from the read.
A rejected turn/interrupt was reported as a turn failure, so the editor ended the turn and sent the next held prompt while Codex was still running the old one; the worker then refused that prompt. The worker now emits CancelFailed for a rejected interrupt, which leaves the turn stopping, keeps held prompts waiting, and lets the pane explain the failure and offer Ctrl-C to retry.
This was referenced Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A review of the Agent pane found two ways it could lose work around Cancel and two path-safety gaps in the agent's tools. It also found that plain reads had side effects and that turn state was hard to follow. This PR fixes all four areas, one commit each.
Cancel:
Ctrl-ccould vanish.turn/interrupt.turn/startfor a busy thread, and the interrupted turn's completion was then recorded as the new prompt finishing.Paths:
write_file .git/hooks/pre-commit(or.red/,red.toml,.vscode/tasks.json) passed path resolution. It replaced a buffer's contents and returned "applied, not saved", leaving a dirty hook buffer behind. Only the save step checked protected paths, and the non-Unix save fallback didn't check them at all..git. Object files used up the 65k-entry and 5-second walk budget and crowded real files out of the firstlist_filespage, andread_filecould read.git/config, which can hold credential URLs.Reads: every
read_fileopened a buffer that was never closed and switched the active buffer twice. Each switch requested diagnostics and redrew the screen, so long sessions flooded the buffer list and the screen flickered even with follow mode off.Turn state:
agent_activitystatusline field said "following" for any running turn, even with follow mode off, and it wasn't in the default statusline.What changed
Cancel handling (
src/editor.rs,src/editor/agent_manager.rs,src/codex/mod.rs):CompletedorFailedevent arrives; its editor tools still stop immediately.agent:prompts_returnedevent and are kept as paused follow-ups, so nothing you typed is lost.Failedinstead of skipping a turn without a word.turn/interruptnow produces a newCancelFailedevent instead ofFailed. It doesn't end the turn: held prompts keep waiting, the pane says the stop failed, andCtrl-cretries.Agent pane (
plugins/agent.hk):N queued · paused.:AgentSendQueuedand:AgentDiscardQueuedresume or drop the held follow-ups.Path safety (
src/lsp/workspace_edit.rs,src/editor.rs,src/codex/mod.rs,src/inline_context.rs):write_file,apply_editsandcreate_directoryrun it before any buffer is opened, and so does the non-Unix save fallback..git,.hg,.jj,.svn) is refused by path resolution and skipped by the agent and inline-context file walkers.Reads without buffers (
src/editor.rs,src/editor/agent_annotations.rs,src/editor/agent_lsp.rs):read_filereturns an open buffer's live contents without switching to it.lsp_prepare_rename,lsp_preview_rename, file diagnostics) load an unopened file's buffer in the background, without switching to it.Turn phases and status (
src/editor/agent_manager.rs,src/editor/rendering.rs,src/config.rs,plugins/agent.hk):AgentTurnPhase(RunningorStopping). The turn ID is kept until the turn really ends.agent:completed,agent:cancelledandagent:errornow carryturn_id, and the pane ignores events from an earlier turn.agent_activityshowsagent working,agent followingoragent stopping, plus any queued count, and is empty when idle. It is now in the default right-hand statusline; while the agent is idle the layout looks the same as before.Agent finished · Space A to view.docs/AGENT_WORKFLOW.mddocuments the new behaviour and commands.How to Test
redin a git repo and pressSpace A.Ctrl-cand immediately send: "Reply with only the codeword I asked you to remember."~/.codex/sessions/**/rollout-*.jsonlshould hold both turns in one thread (turn_aborted interrupted, thentask_complete), with no second thread file.Ctrl-c.1 queued · paused · :AgentSendQueued or :AgentDiscardQueued.:AgentSendQueuedsends it to the same thread;:AgentDiscardQueuedremoves it from the pane.echo hi"..git/hooks/pre-commitbuffer appears in the buffer list, and the file isn't created..gitis never read. Ask the agent to read.git/config. Expected: refused with "inside version-control metadata".:ls) and the active buffer are unchanged afterwards, and nothing flickers.agent working, oragent followingwith follow mode on. AfterCtrl-cit showsagent stoppinguntil the turn ends, then it disappears.:AgentCloseduring a turn. When the turn finishes,Agent finished · Space A to viewappears (it's also in:messages).Targeted tests:
prompt_sent_during_a_cancel_runs_after_the_interrupted_turn_ends(fails on main)busy_turn_rejects_prompts_and_a_failed_interrupt_can_be_retriedbundled_agent_pauses_queued_follow_ups_after_a_stopped_turnagent_writes_to_protected_paths_fail_before_touching_a_bufferfile_listing_skips_version_control_metadataagent_reads_of_unopened_files_leave_buffers_alone_and_guard_later_writesstatusline_agent_activity_reports_turn_phase_and_queuebundled_agent_ignores_terminal_events_from_an_earlier_turnbundled_agent_announces_turns_that_finish_while_the_pane_is_hiddena_lost_bridge_returns_prompts_held_behind_a_stopping_turnbundled_agent_keeps_prompts_returned_by_a_lost_app_server_as_pausedagent_lsp_works_on_files_read_from_disk_without_switching_buffers(tests/lsp_lazy.rs)bundled_agent_explains_a_failed_cancel_and_keeps_the_turn_runningExisting tests updated:
bundled_agent_rotates_*tests now assert that the thread is kept.agent_activity.Not covered here:
session_starting,restoring,pending_prompt, …) with a stringui_phase. Folding those into one phase type is a larger refactor ofplugins/agent.hk, left for a follow-up.