Repository navigation
fix(pi): run plannotator_submit_plan sequentially so it never reads a stale plan - #1623
Merged
Merged
Conversation
… stale plan Pi runs one assistant message's tool calls in parallel by default. Its write/edit tools apply changes through an async per-file mutation queue, while plannotator_submit_plan reads the plan file synchronously as soon as it starts, so an "edit plan + submit plan" batch could review (and save to history) the pre-edit plan. Declaring executionMode "sequential" makes pi run the whole batch one call at a time, in order. Closes #1622
1 task
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.
Problem
In the Pi extension,
plannotator_submit_plancould open the review UI with an outdated plan, most often after a deny when the agent edits the plan and resubmits in the same assistant message. Diagnosis by @bugs-wkettlitz in #1622:executeToolCallsinpi-agent-core/dist/agent-loop.js).edit/writeapply changes asynchronously throughwithFileMutationQueue.plannotator_submit_planreads the file synchronously (statSync+readFileSync) as soon as itsexecutestarts, so it could read the pre-edit content. That stale text also went tosaveToHistory.Fix
Declare the submit tool
executionMode: "sequential". In pi's agent loop, if any tool call in a batch belongs to a tool withexecutionMode === "sequential", the whole batch goes throughexecuteToolCallsSequential. That path awaits each call's execute and finalize, in the assistant's source order, before starting the next one. So an edit that comes before the submit lands first.I verified this in pi's source:
pi-agent-core/dist/agent-loop.js:executeToolCalls→hasSequentialToolCall→executeToolCallsSequential(a plain awaitedforloop over the batch).pi-coding-agent/dist/core/extensions/wrapper.js:wrapRegisteredTool→wrapToolDefinition, which forwardsexecutionMode(core/tools/tool-definition-wrapper.js).ToolDefinition.executionMode?: ToolExecutionModeincore/extensions/types.d.ts.Compatibility
The peer range is
@earendil-works/pi-coding-agent >= 0.79.1. I checked the published 0.79.1 tarballs ofpi-agent-coreandpi-coding-agent:executionModeis already declared, forwarded by the wrapper, and honored byexecuteToolCalls. It works on every supported pi, so the race stays open on none of them.registerTooldoes no schema validation of the definition, so an older host would ignore the field instead of rejecting it.Scope
plannotator_mark_doneis unchanged. It does not read state that a sibling call in the same batch produces. Making it sequential would only serialize ordinary "edit code + mark step" batches, and it would not skip the mark if the edit failed.withFileMutationQueue. It is exported publicly, but in parallel mode the order in which calls register with the queue is not guaranteed. The sequential flag is the deterministic fix.Test
phase-tools-runtime.test.tsnow asserts that the submit tool is registered withexecutionMode: "sequential". It is a deliberate pin with a comment explaining why: pi's loop keys serialization on exactly this field. The test fails with the field removed.Closes #1622