Skip to content

fix(prompt): keep plan/build reminders stable#27845

Closed
namnguyen0503 wants to merge 1 commit into
anomalyco:devfrom
namnguyen0503:fix-stable-system-reminder-history
Closed

fix(prompt): keep plan/build reminders stable#27845
namnguyen0503 wants to merge 1 commit into
anomalyco:devfrom
namnguyen0503:fix-stable-system-reminder-history

Conversation

@namnguyen0503
Copy link
Copy Markdown

@namnguyen0503 namnguyen0503 commented May 16, 2026

What does this PR do?

Fixes #26749.

This fixes prompt-history instability where Plan/Build synthetic <system-reminder> content could move between historical user turns across later request serializations.

Root cause: Plan/Build reminders were attached to the latest user turn, and one later path mutated existing message parts in place. This allowed a historical user message to serialize once as Continue plus a Plan -> Build reminder, then later serialize as only Continue.

Changes:

  • Anchor Plan/Build reminders to a stable turn boundary.
  • Clone/reconstruct messages and parts instead of mutating existing history objects.
  • Keep the later follow-up reminder rewrite immutable.
  • Add regression coverage for Plan -> Build -> Continue -> later Build turn.

This preserves prefix-cache stability for OpenAI-compatible local backends such as llama.cpp, vLLM, and LM Studio because previously seen prompt messages remain byte-stable.

How did you verify your code works?

Ran:

  • bun test test/session/prompt.test.ts -t "keeps plan/build system reminders anchored to the original user turn across later serializations"
  • bun test test/session/prompt.test.ts -t "static loop consumes queued replies across turns"
  • bun test test/session/prompt.test.ts
  • bun turbo typecheck

Result: all passed.

I also ran a source-checkout smoke test using the repository's fake OpenAI-compatible TestLLMServer, without loading a real model.

The smoke test reproduced Plan -> Build -> Continue -> later Build and verified that the historical Continue + <system-reminder> message stayed byte-stable across later serializations.

Observed:

  • continueIndex: 3
  • firstDiffMsg: 4

This means the first changed message was at the new append boundary, while the previous Continue message containing the Plan -> Build reminder stayed identical.

Screenshots / recordings

Not applicable. This is a prompt serialization / cache stability bug fix with regression tests.

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

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@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.

@namnguyen0503
Copy link
Copy Markdown
Author

Updated the PR description to use the required template sections and added Fixes #26749.

@namnguyen0503
Copy link
Copy Markdown
Author

The PR body now follows the required template and includes Fixes #26749, but the needs:issue / needs:compliance labels are still present. Could you re-run or clear the compliance check?

@namnguyen0503
Copy link
Copy Markdown
Author

All PR checks are now passing, including pr-standards/check-compliance. The stale needs:compliance label still appears to be present; could a maintainer clear it or re-run the label cleanup?

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 16, 2026
@github-actions github-actions Bot closed this May 16, 2026
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

2 participants