Repository navigation
fix(session): remove message time replay prefixes - #4540
Merged
Merged
Conversation
chengyongru
marked this pull request as ready for review
June 26, 2026 16:58
Re-bin
approved these changes
Jun 27, 2026
Re-bin
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. This removes the model-facing [Message Time: ...] replay prefix without dropping persisted timestamps, which makes historical prompts more stable and friendlier to provider prompt/KV caching. The change is narrowly scoped to replay/context assembly and consolidation estimation; storage metadata remains intact.
Validated locally:
python -m pytest tests/agent/test_session_manager_history.py tests/agent/test_loop_save_turn.py::test_system_subagent_followup_is_persisted_before_prompt_assembly tests/agent/test_auto_compact.py::TestAgentLoopTTLParam::test_process_message_reads_history_with_token_budget tests/agent/test_context_prompt_cache.py -qpython -m ruff check nanobot/agent/loop.py nanobot/agent/memory.py nanobot/session/manager.py tests/agent/test_auto_compact.py tests/agent/test_loop_save_turn.py tests/agent/test_session_manager_history.py
GitHub Actions is green.
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.
Summary
Remove the model-facing
[Message Time: ...]replay prefix from session history.The session still persists message timestamps in
session.messages[], so this does not discard stored metadata. It only stops rewriting replayed user content before sending history to the model.Why
The previous timestamp injection changed historical user message content between turns, which made provider-facing prompt prefixes unstable and reduced prompt/KV cache friendliness. Runtime current-time context remains available separately, so normal turn metadata is still represented without polluting every historical message.
Changes
Session.get_history(include_timestamps=...)and the timestamp annotation helper.[Message Time: ...].Validation
python -m pytest tests/agent/test_session_manager_history.py tests/agent/test_loop_save_turn.py::test_system_subagent_followup_is_persisted_before_prompt_assembly tests/agent/test_auto_compact.py::TestAgentLoopTTLParam::test_process_message_reads_history_with_token_budget tests/agent/test_context_prompt_cache.py -q --cache-clearpython -m ruff check nanobot/agent/loop.py nanobot/agent/memory.py nanobot/session/manager.py tests/agent/test_auto_compact.py tests/agent/test_loop_save_turn.py tests/agent/test_session_manager_history.py