From 48488863306473c4d4752a180b37e124ab0cf65a Mon Sep 17 00:00:00 2001 From: Hadrien Kerlero <199662351+HadrienKerlero@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:31:49 +0100 Subject: [PATCH] fix(web): sample the live-output generation before selectSession fetches (#814) - selectSession now samples _liveOutputGen before its fresh fetch, as the refresh and manual-pull paths do, so output that arrives during the download keeps the session marked for Reload history. - Test: live output during the fresh fetch keeps the mark after a mux-full-history replay. --- src/web/public/app.js | 3 ++- test/shell-scroll-history-pull.test.ts | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/web/public/app.js b/src/web/public/app.js index c5859d4e..db589667 100644 --- a/src/web/public/app.js +++ b/src/web/public/app.js @@ -10557,6 +10557,8 @@ class CodemanApp { !session?.remote && !session?.docker && !session?.adopt && this._paneHistoryLines?.get(sessionId) === 0; const useFullHistory = !shellSession && (paneKeepsNoHistory || !this._fullHistoryLoaded.has(sessionId)); if (useFullHistory) this._fullHistoryLoaded.add(sessionId); + // Sample before fetching, as other replays do, so output during download keeps the session marked. + const liveOutputGen = this._liveOutputGen?.get(sessionId) || 0; const fetchStartedAt = performance.now(); const tailUrl = `/api/sessions/${sessionId}/terminal?tail=${TERMINAL_TAIL_SIZE}`; let capture; @@ -10620,7 +10622,6 @@ class CodemanApp { _crashDiag.log(`REWRITE: ${(data.terminalBuffer.length/1024).toFixed(0)}KB`); this._setTerminalLoadState(sessionId, selectGen, 'replaying'); const replayStartedAt = performance.now(); - const liveOutputGen = this._liveOutputGen?.get(sessionId) || 0; this._resetTerminalForReplay(); // Truncation is reported OUT OF BAND (#258). This used to write a grey // "... earlier output truncated ..." line into the diff --git a/test/shell-scroll-history-pull.test.ts b/test/shell-scroll-history-pull.test.ts index 775813a3..2a3b2c75 100644 --- a/test/shell-scroll-history-pull.test.ts +++ b/test/shell-scroll-history-pull.test.ts @@ -1548,7 +1548,7 @@ describe('manual history banner action', () => { }); describe('selectSession only clears live-output marks for actual full mux captures', () => { - it.each(['mux-full-history', 'history'])('checks the response source: %s', async (source) => { + function makeSelectApp(source = 'mux-full-history') { const errors = vi.fn(); const select = loadAppMethod('selectSession', { console: { log: vi.fn(), error: errors }, @@ -1576,7 +1576,7 @@ describe('selectSession only clears live-output marks for actual full mux captur 'scrollToLastNonEmptyLine', ].map((name) => [name, vi.fn()]) ); - Object.assign(app, methods, { + const selection = Object.assign(app, methods, { activeSessionId: 's2', _fullHistoryLoaded: new Set(), _liveOutputSinceFullPull: new Set(['s1']), @@ -1586,11 +1586,29 @@ describe('selectSession only clears live-output marks for actual full mux captur sendResize: async () => false, }); Object.assign(app.terminal, { scrollToBottom: vi.fn() }); + return { app: selection, select, errors }; + } + + it.each(['mux-full-history', 'history'])('checks the response source: %s', async (source) => { + const { app, select, errors } = makeSelectApp(source); await select.call(app, 's1'); expect(errors).not.toHaveBeenCalled(); expect(app.chunkedTerminalWrite).toHaveBeenCalledOnce(); expect(Reflect.get(app, '_liveOutputSinceFullPull').has('s1')).toBe(source !== 'mux-full-history'); }); + + it('keeps the mark when live output arrives during the fresh fetch', async () => { + const { app, select, errors } = makeSelectApp(); + const fetchCapture = app._fetchTerminalCapture.getMockImplementation()!; + app._fetchTerminalCapture.mockImplementationOnce(async (url) => { + app._liveOutputGen.set('s1', (app._liveOutputGen.get('s1') || 0) + 1); + return fetchCapture(url); + }); + await select.call(app, 's1'); + expect(errors).not.toHaveBeenCalled(); + expect(app.chunkedTerminalWrite).toHaveBeenCalledOnce(); + expect(app._liveOutputSinceFullPull.has('s1')).toBe(true); + }); }); describe('drop-recovery refresh clears the live-output mark only for a mux capture', () => {