Skip to content

fix(pi): append-only phase framing so plan transitions keep the prompt cache - #1381

Merged
backnotprop merged 1 commit into
mainfrom
fix/1380-append-only-pi-framing
Aug 23, 2026
Merged

fix(pi): append-only phase framing so plan transitions keep the prompt cache#1381
backnotprop merged 1 commit into
mainfrom
fix/1380-append-only-pi-framing

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Problem

On Pi, finishing plan execution invalidated the provider's prompt cache (#1380). Plannotator injects its phase framing as conversation messages, and a context filter removed them from the middle of history at phase transitions. Pi only applies that filter to the outgoing request, but the provider cache keys on the exact request prefix, so deleting an already-sent message shifts everything after it. In the reporter's attached payloads the executing framing was message 31 of 119, so one plan completion re-billed 88 messages as uncached input.

Change

The conversation is now append-only. The context filter is removed entirely: delivered framing and todo snapshots stay in history for the life of the session. Stale instructions are neutralized by countermands instead of deletion:

Compaction is unchanged: it rewrites history anyway and invalidates the cache by itself, and the framing re-delivery latch still handles a swallowed framing message.

Why safe

The countermand language mostly existed already. The executing framing has always opened with "The planning phase is over ... planning-phase restrictions no longer apply", and the plan-mode-off notice already says to disregard all earlier Plannotator instructions. Models follow the most recent instruction; the filter was belt and braces on top of text that was doing the work.

Tests

  • New prefix-stability test simulates planning, then executing, then idle across real handler calls and asserts each outgoing request begins with the previous one byte for byte, with only suffix appends. The removed filter fails this test at both transitions.
  • New test pins the superseding sentences in both phase templates so they cannot silently drift out.
  • The old filter tests are removed with the filter; the Mid-session plan-mode toggle leaves stale planning instructions in the model context #1320 countermand suite and the compaction latch tests pass unchanged.
  • Full pi-extension suite and repo typecheck run clean (six pre-existing server.test.ts failures reproduce identically on unmodified main in this sandbox and are unrelated).

Fixes #1380

AI-assisted (Claude) under maintainer direction.

…t cache

The context filter stripped delivered framing from mid-history at phase
transitions, shifting every later message and invalidating the provider's
cached prefix (88 of 119 messages re-billed in the reporter's session).
History is now append-only: delivered framing stays, and stale instructions
are neutralized by superseding language in the phase templates plus the
existing plan-mode-off countermand.

Fixes #1380
@backnotprop
backnotprop merged commit 776fcb4 into main Aug 23, 2026
28 checks passed
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: cache miss after finished plan execution

1 participant