Skip to content

fix(session): remove message time replay prefixes - #4540

Merged
Re-bin merged 1 commit into
mainfrom
fix/remove-message-time-prefix
Jun 27, 2026
Merged

Re-bin merged 1 commit into
mainfrom
fix/remove-message-time-prefix

Conversation

@chengyongru

Copy link
Copy Markdown
Collaborator

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

  • Remove Session.get_history(include_timestamps=...) and the timestamp annotation helper.
  • Stop agent loop and consolidation token probes from requesting timestamp-prefixed history.
  • Update focused tests to assert timestamps remain persisted but replay content does not contain [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-clear
  • python -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

@chengyongru
chengyongru marked this pull request as ready for review June 26, 2026 16:58

@Re-bin Re-bin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -q
  • python -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.

@Re-bin
Re-bin merged commit 9b45fc1 into main Jun 27, 2026
4 checks passed
@chengyongru
chengyongru deleted the fix/remove-message-time-prefix branch June 30, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants