Merge remote-tracking branch 'origin/main' into codex/81234-live-main-final
# Conflicts: # tui_gateway/methods_prompt.py # tui_gateway/server.py
This commit is contained in:
+21
-2
@@ -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,
|
||||
@@ -493,6 +494,17 @@ def build_turn_context(
|
||||
# after primary restoration has settled the runtime.
|
||||
try:
|
||||
from agent.auxiliary_client import set_runtime_main
|
||||
from agent.prompt_cache_scope import resolve_prompt_cache_scope_safe
|
||||
# Rotation-stable prompt-cache scope. Memoized per segment on the
|
||||
# agent, so this is a DB walk at most once per segment — except a
|
||||
# brand-new session whose row lands later in turn setup
|
||||
# (_ensure_db_session); that first turn falls back to the physical
|
||||
# id here and the first build_api_kwargs re-resolves. Stays valid
|
||||
# through a mid-turn compression rotation because the lineage root
|
||||
# is by definition rotation-invariant (#79017). Resolved with the
|
||||
# never-raising variant OUTSIDE the argument list, so a resolution
|
||||
# failure can only lose the scope — never the whole runtime binding.
|
||||
_cache_scope = resolve_prompt_cache_scope_safe(agent) or ""
|
||||
set_runtime_main(
|
||||
getattr(agent, "provider", "") or "",
|
||||
getattr(agent, "model", "") or "",
|
||||
@@ -502,6 +514,7 @@ def build_turn_context(
|
||||
api_mode=getattr(agent, "api_mode", "") or "",
|
||||
auth_mode=getattr(agent, "auth_mode", "") or "",
|
||||
session_id=getattr(agent, "session_id", "") or "",
|
||||
cache_scope=_cache_scope,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -633,9 +646,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():
|
||||
@@ -667,7 +686,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user