From f33ac82ca1c00c2f75c2628cadb7827d96b57d96 Mon Sep 17 00:00:00 2001 From: happy5318 Date: Sat, 19 Sep 2026 13:35:13 +0800 Subject: [PATCH] fix(session): guard truncation flags before read in settle strategy (CI) test_issue6867 extracts _restoreSettledSession into a bare harness where the module-level _messagesTruncated/_oldestIdx lets are absent; a bare read threw ReferenceError and the whole recovery path died before it could restore. Use typeof guards like the surrounding paging restores. The semantics are unchanged in the real page (both are always declared). --- static/messages.js | 2 +- tests/test_session_default_window.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/static/messages.js b/static/messages.js index 8295794d..220ab1a6 100644 --- a/static/messages.js +++ b/static/messages.js @@ -7092,7 +7092,7 @@ function attachLiveStream(activeSid, streamId, uploaded=[], options={}){ // identical turns make BOTH comparisons succeed, preferring the prefix // splices at the wrong offset and silently drops/duplicates rows // (#7628). Never prefer prefix when truncation is active. - const _truncatedRecovery=!!_messagesTruncated||!!(_oldestIdx>0); + const _truncatedRecovery=(typeof _messagesTruncated!=='undefined'&&!!_messagesTruncated)||(typeof _oldestIdx!=='undefined'&&!!(_oldestIdx>0)); const _preserveCurrentTranscript=preserveVisibleOnShorterTerminalSnapshot&&(_truncatedRecovery?_stagedMatchesCurrentSuffix:_stagedMatchesCurrentPrefix); const _resolvedMessages=_preserveCurrentTranscript ? [..._stagedMessages,..._currentVisibleMessages.slice(_truncatedRecovery?_stagedSuffixStart+_stagedMessages.length:_stagedMessages.length)] diff --git a/tests/test_session_default_window.py b/tests/test_session_default_window.py index b10e63bb..3676d061 100644 --- a/tests/test_session_default_window.py +++ b/tests/test_session_default_window.py @@ -158,7 +158,7 @@ def test_settle_truncation_signal_decides_match_strategy(): BOTH comparisons succeed; the prefix branch then splices at the wrong offset and silently drops/duplicates rows) (#7628).""" restore = _restore_settled_session_body() - assert "_truncatedRecovery=!!_messagesTruncated||!!(_oldestIdx>0)" in restore + assert "_truncatedRecovery=(typeof _messagesTruncated!=='undefined'&&!!_messagesTruncated)||(typeof _oldestIdx!=='undefined'&&!!(_oldestIdx>0))" in restore # The splice offset must follow the SAME truncation decision as the match # strategy — no fallthrough to prefix when both match. assert "_truncatedRecovery?_stagedSuffixStart+_stagedMessages.length:_stagedMessages.length" in restore