fix(web): hold the reader past a 2,000-row gap and drop stale drop recoveries (#814)

- _restoreViewportAnchor searches expected - 4000 + rows .. expected + rows
  (same 4,001 candidates / 4,064 reads): filled rows only move the reader
  up, so gaps up to 4000 - rows land exactly, also at the scrollback cap.
- _resetAllAppState and _cleanupPreviousSession clear
  _pendingDroppedOutputRecovery next to the recovery timer, so a reconnect
  load does not resume a stale recovery and run a second full capture.
- Tests: capped 2,500- and 3,900-row gaps; both real cleanup methods drop
  the pending recovery. Docs: the window and the beyond-window fallback.
This commit is contained in:
Hadrien Kerlero committed 2026-11-22 02:44:24 +01:00
1 parent 6311e59412
commit 193f220f5e
4 files changed
+96 -5

No files matched your search

+4
View File
@@ -5013,6 +5013,9 @@ class CodemanApp {
// Clear pending terminal writes
this._clearTimer('syncWaitTimeout');
this._clearTimer('_clientDropRecoveryTimer');
// A recovery deferred behind a load would otherwise resume once the next
// load (the reconnect's own refresh) finishes, and run a second full capture.
this._pendingDroppedOutputRecovery = null;
this.pendingWrites = [];
this.writeFrameScheduled = false;
// Release the one-chunk-in-flight gate with the rest of the write queue.
@@ -9508,6 +9511,7 @@ class CodemanApp {
this._tabCompletionBaseText = null;
this._clearTimer('_tabCompletionFallback');
this._clearTimer('_clientDropRecoveryTimer');
this._pendingDroppedOutputRecovery = null;
this._terminalRefreshOwner = null;
// Clean up pending terminal writes to prevent old session data from appearing in new session
+9 -2
View File
@@ -4050,8 +4050,15 @@ Object.assign(CodemanApp.prototype, {
// Capped at the distinct-row count so a sparse viewport (one unique row
// among blanks) can still match; the ambiguity check rejects repeats.
const minimumScore = Math.min(frequencies.size, Math.max(2, frequencies.size * 0.6));
const first = Math.max(0, expected - 2000);
const last = Math.min(buffer.baseY, expected + 2000);
// Every row a reload fills in BELOW the reader moves the reader's row one
// up from `expected`; a capture with fewer rows below moves it down by at
// most the one screen the downgrade guard tolerates. So the window leans
// up: 4001 candidates from `expected - 4000 + rows` to `expected + rows`,
// which lands gaps up to `4000 - rows` exactly even at the scrollback cap,
// where the replay trims the top and the old index is no longer a fallback.
const rows = this.terminal.rows || 0;
const first = Math.max(0, expected - 4000 + rows);
const last = Math.min(buffer.baseY, expected + rows);
// Cache the search window once: <= 4064 getLine calls, even when all
// 4001 candidates match repeated TUI furniture in a 50k-row buffer.
const text = Array.from(