Skip to content

fix(pi): run plannotator_submit_plan sequentially so it never reads a stale plan - #1623

Merged
backnotprop merged 1 commit into
mainfrom
fix/1622-pi-submit-sequential
Sep 28, 2026
Merged

backnotprop merged 1 commit into
mainfrom
fix/1622-pi-submit-sequential

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Problem

In the Pi extension, plannotator_submit_plan could 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:

  • Pi runs one assistant message's tool calls in parallel by default (executeToolCalls in pi-agent-core/dist/agent-loop.js).
  • Pi's edit/write apply changes asynchronously through withFileMutationQueue.
  • plannotator_submit_plan reads the file synchronously (statSync + readFileSync) as soon as its execute starts, so it could read the pre-edit content. That stale text also went to saveToHistory.

Fix

Declare the submit tool executionMode: "sequential". In pi's agent loop, if any tool call in a batch belongs to a tool with executionMode === "sequential", the whole batch goes through executeToolCallsSequential. 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 awaited for loop over the batch).
  • pi-coding-agent/dist/core/extensions/wrapper.js: wrapRegisteredTool → wrapToolDefinition, which forwards executionMode (core/tools/tool-definition-wrapper.js).
  • ToolDefinition.executionMode?: ToolExecutionMode in core/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 of pi-agent-core and pi-coding-agent: executionMode is already declared, forwarded by the wrapper, and honored by executeToolCalls. It works on every supported pi, so the race stays open on none of them. registerTool does no schema validation of the definition, so an older host would ignore the field instead of rejecting it.

Scope

  • plannotator_mark_done is 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.
  • Submit does not also take part in 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.
  • Out of scope, as noted in the issue: plans edited through non-pi file tools (e.g. IDE buffer MCP tools) that are not yet flushed to disk.

Test

phase-tools-runtime.test.ts now asserts that the submit tool is registered with executionMode: "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

… 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
@backnotprop
backnotprop merged commit 73b6d28 into main Sep 28, 2026
28 checks passed
@backnotprop
backnotprop deleted the fix/1622-pi-submit-sequential branch September 28, 2026 08:56
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.

[pi] plannotator_submit_plan can review a stale plan when batched with a write/edit (parallel tool execution race)

1 participant