The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): skip live-only rows when aligning the legacy display prefix
Tekniumf4b951863445
diff --git a/tests/tui_gateway/test_history_identity.py b/tests/tui_gateway/test_history_identity.pyindex c593703a6f0..a3834b2a91d 100644--- a/tests/tui_gateway/test_history_identity.py+++ b/tests/tui_gateway/test_history_identity.py@@ -15,3 +15,14 @@ def test_legacy_projection_uses_ordered_prefix_not_last_equal_answer():first = [{'role': 'user', 'content': 'continue'}, {'role': 'assistant', 'content': 'OK'}]second = [{'role': 'user', 'content': 'continue'}, {'role': 'assistant', 'content': 'OK'}]assert _reconcile_display_with_live(first, first + second) == first + second+++def test_live_only_row_before_the_boundary_keeps_the_unflushed_tail():+ # A row the DB never stores verbatim (injected note, expanded @file user text) must be+ # skipped, not used to exhaust the persisted prefix and drop the unflushed turn.+ persisted = [{'role': 'user', 'content': 'continue'}, {'role': 'assistant', 'content': 'OK'}]+ tail = [{'role': 'user', 'content': 'new'}, {'role': 'assistant', 'content': 'unflushed'}]+ injected = [persisted[0], {'role': 'system', 'content': 'note'}, persisted[1], *tail]+ assert _reconcile_display_with_live(persisted, injected) == persisted + tail+ expanded = [{'role': 'user', 'content': 'continue\n[expanded @file body]'}, persisted[1], *tail]+ assert _reconcile_display_with_live(persisted, expanded) == persisted + taildiff --git a/tui_gateway/session_registry.py b/tui_gateway/session_registry.pyindex 9f99bdf1da7..547f337ba9a 100644--- a/tui_gateway/session_registry.py+++ b/tui_gateway/session_registry.py@@ -707,11 +707,9 @@ def _legacy_display_anchor(display: list[dict], memory: list[dict]) -> int:if not isinstance(msg, dict):continuevalue = (msg.get('role'), _coerce_message_text(msg.get('content')))- while cursor < len(prefix) and prefix[cursor] != value:- cursor += 1 # Verification candidates may be absent from the model projection.- if cursor == len(prefix):- return -1- cursor += 1+ if value not in prefix[cursor:]:+ continue # live-only row (persist override, injected note): never exhausts the display prefix+ cursor = prefix.index(value, cursor) + 1 # verification candidates may be absent from the model projectionif cursor == len(prefix):return indexreturn -1