fix: preserve transcript generations in sidebar projection

Rocky-Actor: Hermes Rocky
Rocky-Mode: interactive
This commit is contained in:
Rocky committed 2026-09-24 18:01:04 +03:00
1 parent a4a87a97a3
commit df35836b75
3 files changed
+53 -1

No files matched your search

+2
View File
@@ -53,6 +53,8 @@ _SIDEBAR_SESSION_RESPONSE_FIELDS = {
"model", "model",
"model_provider", "model_provider",
"message_count", "message_count",
"transcript_generation",
"transcript_generation_baseline",
"user_message_count", "user_message_count",
"created_at", "created_at",
"updated_at", "updated_at",
@@ -171,7 +171,9 @@ writes.
- **Viewed counts are generation-scoped.** Session mutation routes increment the - **Viewed counts are generation-scoped.** Session mutation routes increment the
persisted `transcript_generation` whenever edit, regenerate, retry, undo, clear, persisted `transcript_generation` whenever edit, regenerate, retry, undo, clear,
or truncate reduces the visible transcript, and record the retained count as or truncate reduces the visible transcript, and record the retained count as
`transcript_generation_baseline`. A newer generation replaces an older one even `transcript_generation_baseline`. Both fields survive the bounded `/api/sessions`
projection for visible and sidebar-reference rows, including cached responses.
A newer generation replaces an older one even
when its count is lower; counts are monotonic only within one generation and when its count is lower; counts are monotonic only within one generation and
merge by maximum there. A client first observing a newer generation acknowledges merge by maximum there. A client first observing a newer generation acknowledges
only that retained baseline, so messages added after the shrink remain unread only that retained baseline, so messages added after the shrink remain unread
@@ -0,0 +1,48 @@
"""The sessions route must carry shrink metadata through to unread decisions."""
import json
import shutil
import pytest
from tests.test_issue4766_sidebar_source_pushdown import (
_handle_sessions,
_install_common_monkeypatches,
)
from tests.test_issue856_background_completion_unread import _run_unread_behavior
@pytest.mark.skipif(shutil.which("node") is None, reason="node not on PATH")
@pytest.mark.parametrize("retained", [0, 2])
def test_sessions_route_preserves_post_shrink_unread(monkeypatch, retained):
import api.routes as routes
from api.models import Session
from api.session_ops import truncate_session_at_keep
session = Session(session_id="X", messages=[
{"role": "user", "content": str(i)} for i in range(10)
])
truncate_session_at_keep(session, retained)
session.messages.append({"role": "assistant", "content": "new response"})
row = session.compact()
_install_common_monkeypatches(monkeypatch, [row])
routes._session_list_cache_clear()
try:
# Exercise both the initial projection and the cached response.
for _ in range(2):
response = _handle_sessions("http://example.com/api/sessions?sidebar_source=webui")
assert response.status == 200
[projected] = response.json_body()["sessions"]
result = _run_unread_behavior("""
store[SESSION_VIEWED_COUNTS_KEY] = JSON.stringify({
X: {message_count: 10, transcript_generation: 0},
});
const unread = _hasUnreadForSession(""" + json.dumps(projected) + """);
console.log(JSON.stringify({unread, viewed: JSON.parse(store[SESSION_VIEWED_COUNTS_KEY]).X}));
""")
assert result == {
"unread": True,
"viewed": {"message_count": retained, "transcript_generation": 1},
}
assert "messages" not in projected
finally:
routes._session_list_cache_clear()