Skip to content

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

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

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

Conversation

@namnguyen0503
Copy link
Copy Markdown

@namnguyen0503 namnguyen0503 commented May 16, 2026

Issue for this PR

Closes #26749

Type of change

  • Bug fix

What does this PR do?

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

Screenshots / recordings

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

Checklist

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

@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

github-actions Bot commented May 16, 2026

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

What needs to be fixed:

  • No "Type of change" checkbox is checked. Please select at least one.
  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

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

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

Potential Duplicate Found

PR #26743: fix(session): persist plan mode reminders

This PR appears related as it also addresses plan mode reminders. While the current PR (27863) focuses on keeping Plan/Build reminders stable across serializations to preserve prefix-cache stability, PR #26743 addresses persisting plan mode reminders. These may be related efforts around plan mode reminder handling and should be reviewed to ensure they don't conflict or duplicate work.

@namnguyen0503
Copy link
Copy Markdown
Author

Closing and recreating with the exact PR template from the start to avoid stale compliance labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

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