Skip to content

Safely reconcile repeated and prompt-only Precmd hooks#12857

Draft
vorporeal wants to merge 3 commits into
david/add-block-lifecycle-coordinatorfrom
david/reconcile-repeated-and-legacy-prompts
Draft

Safely reconcile repeated and prompt-only Precmd hooks#12857
vorporeal wants to merge 3 commits into
david/add-block-lifecycle-coordinatorfrom
david/reconcile-repeated-and-legacy-prompts

Conversation

@vorporeal

@vorporeal vorporeal commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Description

Stack PR 6/8; depends on #12856.

Context

Precmd is not always a one-time event. Shells can repaint or resend a prompt, and a newer shared-session viewer can receive prompt-only hooks from an older sharer. Re-running the original prompt path against an already populated active block can overwrite command/input state, move the cursor, mutate a finished prompt grid, or repeat once-per-block events. Ignoring every repeat is safer, but it also discards legitimate newer prompt, session, and environment context.

Prompt-only Precmd hooks need a separate policy: they are useful when the model is already safely awaiting or displaying a prompt, but they cannot prove that an executing command completed or identify the next block.

Approach

This PR adds an explicit safe refresh path. A same-active-ID Precmd with completion metadata applies normally when the active block is fresh; if that block already has a prompt, it refreshes the active prompt and context while preserving the current command content, input, and cursor position. A prompt disposition tells downstream dispatch whether this was the first application or a refresh, allowing session/environment state to update without re-emitting public once-per-block prompt events.

Prompt-only evidence is accepted only in the safe prompt phases defined by the coordinator and is ignored elsewhere with diagnostics. It never completes or advances a block. State-mutating repeated-prompt reconciliation remains selected by the recovery gate, while rejection of unsafe prompt-only transitions is unconditional.

Review guidance

  • Can a refresh alter command/input content, cursor position, block lifecycle state, or emit completion/prompt side effects a second time?
  • Does refreshed context still reach downstream session/environment tracking without a duplicate public Precmd event?
  • Is prompt-only evidence restricted to phases where no completion inference is required?

Testing

  • Added repeated and prompt-only Precmd coverage for prompt-grid, input, and cursor preservation plus exact once-per-block event counts.
  • Added a dispatcher regression proving a refreshed Precmd updates the active session without emitting a duplicate public Precmd event.
  • Final-stack validation: cargo check -p warp --tests, ./script/format, and git diff --check.

vorporeal commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

@vorporeal vorporeal changed the title Reconcile repeated and legacy prompts Safely reconcile repeated and legacy Precmd hooks Jun 20, 2026
vorporeal and others added 3 commits June 20, 2026 00:28
Co-Authored-By: Oz <oz-agent@warp.dev>
Co-Authored-By: Oz <oz-agent@warp.dev>
Co-Authored-By: Oz <oz-agent@warp.dev>
@vorporeal vorporeal force-pushed the david/add-block-lifecycle-coordinator branch from d5c5fd1 to 1ea3538 Compare June 20, 2026 05:14
@vorporeal vorporeal force-pushed the david/reconcile-repeated-and-legacy-prompts branch from 8ea8d92 to 2a89b87 Compare June 20, 2026 05:14
@vorporeal vorporeal changed the title Safely reconcile repeated and legacy Precmd hooks Safely reconcile repeated and prompt-only Precmd hooks Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant