Skip to content

fix: stop xterm reflow retaining and overwriting trimmed rows - #21112

Open
OrcaWin wants to merge 3 commits into
np-oom-scan-terminal-cell-retentionfrom
np-oom-scan-xterm-reflow-retention
Open

OrcaWin wants to merge 3 commits into
np-oom-scan-terminal-cell-retentionfrom
np-oom-scan-xterm-reflow-retention

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior

Stop xterm reflow from retaining rows under negative array indexes and overwriting the retained circular-buffer tail. Preserve the existing scrollback capacity and correctly retained terminal contents.

Validation

Real emitted desktop/headless CJS/ESM controls cover cursor, wrapping, markers and retained row contents. The current-main lockfile integration preserves the reviewed source and generated patch bytes.

Merge decision

Requires #20992, which requires #20981 and has a separately disclosed parser-performance cost. This correction adds no smaller history limit, but the stack is not an independent easy merge. Refreshed CI is required.

Audit evidence, Audit evidence, Audit evidence

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Reflow destination guard. Adds && i >= 0 to the _reflowSmaller insertion loop (Buffer.ts) in the maintained @xterm/xterm and @xterm/headless source patches, so this.lines.set(i--, …) can no longer write below logical row 0 (which CircularList._getCyclicIndex maps onto negative array properties and, for a rotated ring, valid rows).
  • Bundle/mobile regeneration. Desktop and mobile CJS/ESM bundle patches and maps carry the guard; MOBILE_SOURCES now includes Buffer.ts, and both lockfiles' patch_hash entries move with it.
  • Regression coverage. New config/scripts/xterm-reflow-retention.test.mjs exercises installed headless and renderer builds across CJS and ESM at ring starts 0 and 37; a new mobile WebView test covers the 20-column floor.
  • Bounded audit proof. docs/audits/xterm-reflow-retention/ records a 192 MiB-capped reproduction, 28 parity cases, and 8 WeakRef lifecycle cases, with tested source hashes pinned in validation.json.

Verification performed

  • Confirmed exactly one Buffer.ts stanza and one i >= 0 hunk in each of the headless, desktop, and mobile source patches, and the guard present in the generated bundles.
  • Lock consistency holds: every patch_hash (@xterm/headless, @xterm/xterm, mobile, and the untouched addon-webgl entry) equals sha256 of its committed patch file, so a frozen install should resolve.
  • Removed the guard from the installed bundles and re-ran the new test: all eight cases fail with the wrong retained tail, so the assertion is not theatre (restored afterward).
  • validation.json's productSourceHashes["pnpm-lock.yaml"] is the tested lock (12ecbfeb…); the committed lock is the projected one (25529fae…), matching publicationProjection.projectedLockSha256 and differing only by the base branch's unrelated addon-webgl entry, as publicationProjection.difference states.
  • docs/reference/xterm-patch-regeneration.md is updated for the added source stanza and file counts; no stale source-list references remain.

The author's explicit non-claims (no retroactive cleanup of properties in live buffers, no reduction of temporary reflow allocation, no incident attribution) are accurate and appropriately scoped.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

The second commit (f893dc4a75) is test-only: it updates expectations the first commit's guard invalidated. Product scope is unchanged.

  • Payload hash expectation. mobile/src/terminal/terminal-webview-payload-hash.test.ts moves to 952197df… / 731264 (was 241cb377… / 731258); the +6 length delta matches the minified &&i>=0 guard now in the generated engine.
  • Reflow/search regression expectation. src/renderer/src/components/terminal-search-long-wrapped-line.test.ts no longer asserts the buggy state (_array keys toContain('-1'), inherited from the base branch); it now asserts zero negative keys plus the full retained line 0..19 tail.

Verification performed

  • Re-ran the changed renderer file end-to-end: all 17 tests pass, including stops rewinding at row 0 when a reflow trims a wrapped line head.
  • Re-ran config/scripts/xterm-reflow-retention.test.mjs: 8/8 pass against the installed headless and renderer bundles (CJS + ESM, ring starts 0 and 37).
  • The flipped negative-key assertion is not theatre: the base branch asserted toContain('-1') against the same pre-guard state, so it fails without the fix.
  • CI on f893dc4a: test shards 1–8, typecheck, static analysis, and package all success.
  • I could not independently regenerate the mobile payload (mobile node_modules is absent on the runner), so the new hash/length is verified only by CI and by the arithmetic consistency above.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Resolve mobile lock metadata with the pnpm 12 hash format while retaining all patch hashes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant