fix(pi): append-only phase framing so plan transitions keep the prompt cache - #1381
Merged
Conversation
…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
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
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
Fixes #1380
AI-assisted (Claude) under maintainer direction.