fix(web): keep fetch-time output dirty and clamp replay travel per move (#814)

Review follow-up. The early re-pull sampled the live-output generation after
its fetch, but nothing gates live output while the capture downloads, so
output newer than the capture was overwritten and the session marked clean.
Sample before the fetch.

Travel made during the replay was one signed sum clamped once, so scrolling
to the bottom and back up cancelled out. Record moves in order and clamp
after each, as live scrolling does.
This commit is contained in:
Hadrien Kerlero committed 2026-11-22 02:43:30 +01:00
1 parent e91c62885a
commit fd31315582
3 files changed
+37 -14

No files matched your search

+12 -5
View File
@@ -806,7 +806,7 @@ class CodemanApp {
this._fullHistoryRepullInFlight = false;
this._liveOutputSinceFullPull = new Set(); // Set<sessionId>
this._liveOutputGen = new Map(); // Map<sessionId, number>
this._earlyReplayTravel = null;
this._earlyReplayTravel = null; // number[] while an early (#814) replay runs
// Sessions whose last re-pull came back THINNER than the live buffer (a
// repaint-mode CLI pane, where tmux keeps no history of its own). The pull is
// refused for those and retried far more slowly — see _maybeRefetchFullHistory.
@@ -9658,6 +9658,10 @@ class CodemanApp {
// replaying its own capture, and the reset below would land in the middle
// of that write. The select generation moves on every switch, so it can.
const selectGen = this._selectGeneration;
// Sampled BEFORE the fetch: this path does not gate live output while the
// capture downloads, so output flushed after tmux captured would otherwise
// be overwritten by the replay and still count as covered by it (#814).
const liveOutputGen = this._liveOutputGen?.get(sessionId) || 0;
try {
const requestStartedAt = performance.now();
const capture = await this._fetchTerminalCapture(
@@ -9754,8 +9758,9 @@ class CodemanApp {
const rowsBefore = this.terminal.buffer.active.length;
const replayStartedAt = performance.now();
const rowsFromBottom = this.terminal.buffer.active.baseY - this.terminal.buffer.active.viewportY;
const liveOutputGen = this._liveOutputGen?.get(sessionId) || 0;
if (anchor === 'bottom') this._earlyReplayTravel = 0;
// Ordered, not summed: each move clamps at the buffer edge as it would
// have live, so a reversal after hitting the bottom is not cancelled out.
if (anchor === 'bottom') this._earlyReplayTravel = [];
this._resetTerminalForReplay();
const {
parsedAt,
@@ -9787,8 +9792,10 @@ class CodemanApp {
if (anchor === 'bottom') {
// Recover the tmux repaint gap above the live screen without a jump (#814).
const baseY = this.terminal.buffer.active.baseY;
const distance = rowsFromBottom - this._earlyReplayTravel;
this.terminal.scrollToLine(Math.max(0, Math.min(baseY, baseY - distance)));
const clamp = (row) => Math.max(0, Math.min(baseY, row));
let row = clamp(baseY - rowsFromBottom);
for (const move of this._earlyReplayTravel) row = clamp(row + move);
this.terminal.scrollToLine(row);
this._earlyReplayTravel = null;
} else {
const delta = parsedBufferLength - rowsBefore;
+2 -2
View File
@@ -4068,8 +4068,8 @@ Object.assign(CodemanApp.prototype, {
* what the pull left rather than flashing the state it is about to replace.
*/
_maybeLoadMoreHistoryOnScroll(lines) {
if (typeof this._earlyReplayTravel === 'number') {
this._earlyReplayTravel += lines;
if (Array.isArray(this._earlyReplayTravel)) {
this._earlyReplayTravel.push(lines);
return;
}
if (lines > 0) {