Skip to content

fix(session): persist plan mode reminders#26743

Open
ipogosov wants to merge 1 commit into
anomalyco:devfrom
ipogosov:pr-plan-mode-stable-reminders
Open

fix(session): persist plan mode reminders#26743
ipogosov wants to merge 1 commit into
anomalyco:devfrom
ipogosov:pr-plan-mode-stable-reminders

Conversation

@ipogosov
Copy link
Copy Markdown

@ipogosov ipogosov commented May 10, 2026

Issue for this PR

Closes #26749

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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:

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 typecheck from packages/opencode
  • bun 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Plan mode reminders are not persisted in history, breaking prefix cache stability

1 participant