fix(session): persist plan mode reminders#26743
Open
ipogosov wants to merge 1 commit into
Open
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
|
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This was referenced May 16, 2026
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.
Issue for this PR
Closes #26749
Type of change
What does this PR do?
OpenCode appends a synthetic plan-mode reminder to the user message before sending the prompt, but the synthetic part is not stored in message history. On the next turn, the same historical user message is replayed without the reminder, so the model-visible serialization of that turn changes between request 1 and request 2.
This PR persists the non-experimental plan / build synthetic reminder into the user message itself when it is added, so the message that lives in history is identical to what the model saw on the original turn. As a result, the prompt prefix on every later turn matches the prefix that was seen first, which is what prefix caches in OpenAI-compatible backends (LM Studio, llama.cpp, vLLM, LiteLLM proxies) require to actually hit.
It also guards against duplicate reminder parts when a prompt is retried or reprocessed, by checking whether the same reminder text is already present on the user message before appending another one.
This is intentionally narrow:
textpart on the same user message, just like before, only persisted instead of dropped after the request).prompt.ts.The change works because OpenCode's history is the source of truth replayed to the model on every turn, so persisting the synthetic part once means the next turn replays the exact same tokens for that historical user message instead of re-deriving them from a runtime branch.
How did you verify your code works?
bun typecheckfrompackages/opencodebun test test/session/prompt.test.ts --timeout 30000 --grep "plan mode reminders remain stable"— new live-session test that drives a plan turn, advances the session so that the user message becomes history, then asserts the plan reminder text is still present on that historical user message.Screenshots / recordings
N/A, non-UI change.
Checklist