Skip to content

The agent that grows with you

fix: stamp user message timestamps in turn_context

Tuckd61558793e85
diff --git a/agent/turn_context.py b/agent/turn_context.py
index a4b2f14c272..a90bee9a1a1 100644
--- a/agent/turn_context.py
+++ b/agent/turn_context.py
@@ -42,6 +42,7 @@ from agent.context_engine import automatic_compaction_status_message
from agent.iteration_budget import IterationBudget
from agent.memory_manager import build_memory_context_block
from agent.memory_provider import is_trivial_prompt
+from agent.message_metadata import append_message, stamp_message_timestamp
from agent.model_metadata import (
estimate_messages_tokens_rough,
estimate_request_tokens_rough,
@@ -637,9 +638,15 @@ def build_turn_context(
# the same dict and any close-path durable marker.
user_msg["content"] = user_message
else:
- user_msg = {"role": "user", "content": user_message}
+ user_msg = stamp_message_timestamp(
+ {"role": "user", "content": user_message},
+ timestamp=persist_user_timestamp,
+ )
if isinstance(pending_cli_message, dict):
agent._pending_cli_user_message = None
+ # CLI input is stamped when staged. Gateway input may carry the platform
+ # event time. Preserve either value and cover any legacy unstamped handoff.
+ stamp_message_timestamp(user_msg, timestamp=persist_user_timestamp)
# Hydrate todo store from conversation history.
if conversation_history and not agent._todo_store.has_items():
@@ -671,7 +678,7 @@ def build_turn_context(
if persist_user_display_metadata:
user_msg["display_metadata"] = persist_user_display_metadata
- messages.append(user_msg)
+ append_message(messages, user_msg)
current_turn_user_idx = len(messages) - 1
agent._persist_user_message_idx = current_turn_user_idx