fix(agent): join the merged-turn prefix in one place
The merge stamped the prefix with or without the "\n\n" separator depending on whether the absorbed turn was empty, so a later non-empty override on an empty-merge row came out as "RX". Store the unanswered text as-is and join at override time with the same rule the merge uses.
This commit is contained in:
@@ -604,7 +604,7 @@ def _merge_consecutive_users(messages: List[Dict]) -> Tuple[List[Dict], int]:
|
||||
# The clean-text persist override must replace only the absorbed turn, never the
|
||||
# unanswered text before it; kept across replay passes (an empty turn absorbs too).
|
||||
if prev_content:
|
||||
prev[MERGED_TURN_PREFIX] = prev_content + "\n\n" if new_content else prev_content
|
||||
prev[MERGED_TURN_PREFIX] = prev_content
|
||||
# Merged content invalidates the api_content sidecar; drop it so replay cannot use stale bytes.
|
||||
drop_stale_api_content(prev)
|
||||
# Pop the persist marker only when the durable row actually changed: a merge that
|
||||
|
||||
@@ -80,11 +80,12 @@ def _override_replaces_content(msg: Dict, content: Any, override: Any) -> bool:
|
||||
|
||||
|
||||
def _content_with_turn_override(msg: Dict, content: Any, override: Any) -> Any:
|
||||
"""Replace only the absorbed current turn, leaving unanswered history intact."""
|
||||
"""Replace only the absorbed current turn, leaving unanswered history intact. The join matches
|
||||
``_merge_consecutive_users``; a row that no longer holds the prefix takes the plain override."""
|
||||
prefix = msg.get(MERGED_TURN_PREFIX)
|
||||
if isinstance(content, str) and isinstance(override, str) and isinstance(prefix, str):
|
||||
if content.startswith(prefix):
|
||||
return prefix + override
|
||||
if content == prefix or content.startswith(prefix + "\n\n"):
|
||||
return prefix + "\n\n" + override if override else prefix
|
||||
return override
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user