Skip to content

Bugfix: Preserve replayed message whitespace and queued follow-up prompts - #3483

Open
namore wants to merge 3 commits into
charmbracelet:mainfrom
namore:fix/session-prompt-replay
Open

Bugfix: Preserve replayed message whitespace and queued follow-up prompts#3483
namore wants to merge 3 commits into
charmbracelet:mainfrom
namore:fix/session-prompt-replay

Conversation

@namore

@namore namore commented Aug 2, 2026

Copy link
Copy Markdown

Issue description:

  • I have noticed that the prompt cache was often missed with crush after a turn or queued user message. Especially if you write a user message while the agent is running and the message is queued, later on, the session will revert back the previous user message's prompt cache prefix and do prompt processing again without utilising the cache. The impact is for local AI (llama-server) often very long prompt processing and for cloud providers increased cost due to expensive read cache misses. Debugging into the issue I found two root causes (see below).

Disclaimer: The analysis/coding was mostly carried out by AI tooling; I reviewed the final change and test coverage and guided the analysis.

This fixes two session-continuity issues:

  • Preserve user and assistant whitespace when rebuilding persisted conversation history, keeping later prompts byte-for-byte consistent with the original context for prompt-cache reuse.
  • Retain queued follow-up prompts across autonomous tool-use steps so they are not lost when the model advances to another step.

Tests cover whitespace round-tripping, short and long history replay, and queued prompts during autonomous runs. Of the six new tests, five pertain to the smaller whitespace fix and one pertains to the larger queued follow-up prompt fix. I have tested the fix locally with llama-server and the prompt cache works much more reliable now (no more misses during active sessions).

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

@charmcli

charmcli commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@namore

namore commented Aug 2, 2026

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

@namore

namore commented Aug 2, 2026

Copy link
Copy Markdown
Author

recheck

@namore
namore force-pushed the fix/session-prompt-replay branch from 785a93d to b221e08 Compare August 9, 2026 18:47
@namore

namore commented Aug 9, 2026

Copy link
Copy Markdown
Author

(Added the CI-requested formatting fix)

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.

2 participants