From 07b3f411d7c6f3931c76b83249a6f3760a1d092b Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Fri, 10 Jul 2026 16:52:37 +0000 Subject: [PATCH] fix: preserve same-session load ownership on redundant reload + guard hint cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gate review (Codex) reproduced two SILENT regressions in the generation-token ownership change, both validated against PR head + merge base: 1. sessions.js:1428 — the no-op early-return did NOT fire for a redundant same-session load (currentSid===sid, !_loadingSessionId was false because a keep-stale refresh was in flight). The redundant loadSession() then bumped _loadSessionGeneration and CANCELLED the authoritative in-flight refresh — stale rows remained while message_count advanced, so later polling could not detect them. Restore the pre-existing behavior: also return when the in-flight load is for the SAME sid (!_loadingSessionId || _loadingSessionId===sid). 2. sessions.js:2781 — _ensureMessagesLoaded's finally cleared the transcript-width reload hint unconditionally, so a stale same-session response collapsed a long session to the default tail window. Guard the cleanup with _ownsLoad() so only the owning load clears the hint. Both fixes retain the PR's cross-session, same-session-rejection, and INFLIGHT race behavior (47 tests pass incl. the new isolation suite + the 4 edited files). Co-authored-by: starship-s --- static/sessions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/sessions.js b/static/sessions.js index 22e27cfb..04557bf4 100644 --- a/static/sessions.js +++ b/static/sessions.js @@ -1425,7 +1425,7 @@ async function loadSession(sid){ // #2971: idempotent re-arm before the no-op guard revives a stream a prior // failed loadSession killed; no-ops on real switches. _rearmActiveSessionStream(); - if(currentSid===sid && !forceReload && !_loadingSessionId) return; + if(currentSid===sid && !forceReload && (!_loadingSessionId || _loadingSessionId===sid)) return; // Mark this session as the in-flight load. Subsequent loadSession() calls // will overwrite this; stale awaits use the mismatch to bail out (#1060). const _loadGeneration = ++_loadSessionGeneration; @@ -2778,7 +2778,7 @@ async function _ensureMessagesLoaded(sid, opts) { {timeoutMs:120000} ); } finally { - _clearSameSessionForceReloadHint(sid); + if (_ownsLoad()) _clearSameSessionForceReloadHint(sid); } if (!_ownsLoad()) return; // Guard: api() may have redirected (401) and returned undefined.