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.
This commit is contained in:
Hadrien Kerlero committed 2026-11-23 00:31:49 +01:00
1 parent 7794f74282
commit 4848886330
2 files changed
+22 -3

No files matched your search

+2 -1
View File
@@ -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
+20 -2
View File
@@ -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', () => {