From eb31b4ed1e3cc8ffd5b3d01abdfbf6640ed5dfc1 Mon Sep 17 00:00:00 2001 From: Dennis Soong Date: Fri, 15 May 2026 17:31:37 +0800 Subject: [PATCH] test: tighten compression snapshot preservation coverage --- CHANGELOG.md | 2 +- api/streaming.py | 5 ++++- tests/test_issue2223_compression_no_rename.py | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26114939..630700a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Fixed -- **PR #2285** by @dso2ng (refs #2230) — Context-compression preservation now marks old pre-compression session files with `pre_compression_snapshot: true` and hides those preserved snapshots from the active sidebar list while keeping the JSON files available for lineage traversal. This keeps long-running conversations from accumulating duplicate active sidebar rows after repeated compressions without reusing the manual archive flag for an internal snapshot lifecycle state. +- **PR #2285** by @dso2ng (refs #2230) - Context-compression preservation now marks old pre-compression session files with `pre_compression_snapshot: true` and hides those preserved snapshots from the active sidebar list while keeping the JSON files available for lineage traversal. This keeps long-running conversations from accumulating duplicate active sidebar rows after repeated compressions without reusing the manual archive flag for an internal snapshot lifecycle state. ## [v0.51.64] — 2026-05-14 — Release AN (stage-357 — 3-PR small batch — docker_init k8s whoami fallback + PWA manifest session routes (closes #2226) + aux title test coverage) diff --git a/api/streaming.py b/api/streaming.py index 8f3a130f..3f497fc0 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -1605,12 +1605,15 @@ def _preserve_pre_compression_snapshot(s, old_sid: str) -> None: existing_msgs = len(existing.get('messages') or []) existing_snapshot = bool(existing.get('pre_compression_snapshot')) except (json.JSONDecodeError, ValueError): + # Treat corrupt/malformed old JSON as missing history and rewrite it + # from the in-memory pre-compression messages below. That is safer + # than leaving an unreadable recovery snapshot behind. existing_msgs = -1 existing_snapshot = False if len(s.messages) <= existing_msgs and existing_snapshot: return if len(s.messages) > existing_msgs: - # In-memory messages are newer than the file — save the full old + # In-memory messages are newer than the file; save the full old # snapshot from the current session object while preserving its # pre-existing parent_session_id lineage. saved_sid = s.session_id diff --git a/tests/test_issue2223_compression_no_rename.py b/tests/test_issue2223_compression_no_rename.py index 9b109d23..6fd5c30e 100644 --- a/tests/test_issue2223_compression_no_rename.py +++ b/tests/test_issue2223_compression_no_rename.py @@ -117,6 +117,10 @@ class TestNoRenameDuringCompression: assert old_payload["pre_compression_snapshot"] is True assert old_payload["parent_session_id"] == "fork_parent" assert len(old_payload["messages"]) == 2 + index = json.loads((session_dir / "_index.json").read_text(encoding="utf-8")) + index_by_id = {entry["session_id"]: entry for entry in index} + assert index_by_id["old_sid"]["pre_compression_snapshot"] is True + assert "new_sid" not in index_by_id assert continuation.session_id == "new_sid" assert continuation.parent_session_id == "fork_parent" assert not continuation.pre_compression_snapshot