Skip to content

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

Closed

Description

@bugs-wkettlitz

Summary

In the pi extension, plannotator_submit_plan sometimes opens the review UI with an outdated version of the plan file. This happens most often after a deny: the agent edits the plan and resubmits in the same assistant message, and the browser shows the previous version.

Cause

pi runs the tool calls of one assistant message in parallel by default. See pi-agent-core agent-loop.js → executeToolCalls. It only runs them sequentially when toolExecution === "sequential" or when some tool in the batch declares executionMode: "sequential".

When the agent sends edit/write on the plan file and plannotator_submit_plan in one message:

  • pi's edit/write tools write asynchronously through withFileMutationQueue(absolutePath, ...).
  • plannotator_submit_plan reads the file synchronously (statSync + readFileSync, apps/pi-extension/index.ts in execute) as soon as it starts. It doesn't take part in the file-mutation queue.

The edit's closure yields on its first I/O await, the submit closure then starts, and readFileSync returns the pre-edit content. That stale text goes to openPlanReviewBrowser → saveToHistory, so history also records the wrong version.

Providers that often batch tool calls make this more likely. I hit it with pi-claude-bridge (Claude Code via the Agent SDK), where Claude routinely sends "edit plan" and "submit plan" together.

Fix

Declare the submit tool sequential so pi serializes any batch that contains it:

pi.registerTool({
	name: PLAN_SUBMIT_TOOL,
	label: "Submit Plan",
	executionMode: "sequential",
	// ...
});

executionMode is part of pi's ToolDefinition (core/extensions/types.d.ts) and is forwarded by wrapToolDefinition. I'm running this change locally.

plannotator_mark_done may be worth the same treatment if its behavior depends on ordering relative to other calls in the batch.

Environment

  • @plannotator/pi-extension 0.27.21 (same code on main today)
  • @earendil-works/pi-coding-agent 0.87.1 (default toolExecution: "parallel")
  • Provider: pi-claude-bridge 0.9.0
  • Windows 11

Related note

The planning-mode write gate only intercepts pi's write/edit. Plans written through other file tools (for example IDE MCP tools that edit the editor buffer) can also be stale on disk when submit reads them. That's probably out of scope here; the ordering race above is the main bug.

Activity

  1. added a commit that references this issue on Sep 28, 2026
    73b6d28
  2. backnotprop commented on Sep 28, 2026

    @backnotprop
    Owner

    Thanks @bugs-wkettlitz, great diagnosis. Your fix was right: #1623 marks plannotator_submit_plan as executionMode: "sequential", so pi finishes an edit/write batched in the same message before the plan is read. We checked pi's source back to 0.79.1 (our minimum), which honors the flag, so every supported version gets the fix. plannotator_mark_done doesn't need it. This will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions