Repository navigation
Fix flaky terminal column-desync E2E tests under CI load - #7501
brennanb2025 wants to merge 2 commits into
Conversation
The two shortest-wait cases (:129 visible resize, :169 pty:getSize applied size) asserted an exact match after a fixed 400-500ms wait. The PTY re-sync after a resize is async (renderer fit -> pty:resize -> daemon -> ioctl); under CI load it lands later than the fixed wait, so the exact check sampled mid-flight and flaked. Poll until the sizes agree (bounded 15s). A genuinely dropped resize that never re-syncs still fails, matching the sibling re-sync tests in this file that already tolerate async timing with longer waits. Co-authored-by: Orca <help@stably.ai>
The Linux dispatch converged in ~15s under shard load; 20s gives headroom while still failing a PTY that genuinely never re-syncs. Co-authored-by: Orca <help@stably.ai>
📝 WalkthroughWalkthroughThis PR updates an end-to-end test file for PTY column desynchronization by adding two polling-based helper functions, Changes
Related PRs: None identified. Suggested labels: tests, e2e Suggested reviewers: None identified. Poem 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/e2e/terminal-column-desync-repro.spec.ts (1)
115-157: 📐 Maintainability & Code Quality | 🔵 TrivialConsider
expect.poll()instead of hand-rolled do-while polling.Both helpers reimplement a manual polling loop (
do {...} while (Date.now() < deadline)+page.waitForTimeout(500)) — duplicated across the two functions. Playwright'sexpect.poll()(available in the project's 1.59.1) is built exactly for this: configurabletimeout/intervals, automatic retry, and integrated failure reporting, and would let the two helpers collapse into one shared polling call each, removing the duplication and the manual deadline bookkeeping.♻️ Sketch using `expect.poll`
async function waitForPtyColsToMatchXterm( page: Page, ptyId: string, label: string, timeoutMs = COLUMN_RESYNC_TIMEOUT_MS ): Promise<void> { - const deadline = Date.now() + timeoutMs - let snapshot: ColumnSnapshot = { xtermCols: -1, ptyCols: -1 } - do { - snapshot = await readColumnSnapshot(page, ptyId) - if (snapshot.ptyCols === snapshot.xtermCols) { - return - } - await page.waitForTimeout(500) - } while (Date.now() < deadline) - throw new Error( - `${label}: PTY cols (${snapshot.ptyCols}) never re-synced to xterm cols (${snapshot.xtermCols}) ` + - `within ${timeoutMs}ms; a stale PTY width that never re-syncs is the column-desync bug` - ) + let last: ColumnSnapshot = { xtermCols: -1, ptyCols: -1 } + await expect + .poll( + async () => { + last = await readColumnSnapshot(page, ptyId) + return last.ptyCols === last.xtermCols + }, + { + timeout: timeoutMs, + intervals: [500], + message: () => + `${label}: PTY cols (${last.ptyCols}) never re-synced to xterm cols (${last.xtermCols}) ` + + `within ${timeoutMs}ms; a stale PTY width that never re-syncs is the column-desync bug` + } + ) + .toBe(true) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8b79234d-1359-4460-9fde-2fa47821496b
📒 Files selected for processing (1)
tests/e2e/terminal-column-desync-repro.spec.ts
| // Why: the PTY re-sync after a resize is async (renderer fit → pty:resize → | ||
| // daemon → ioctl); a fixed wait then exact check samples mid-flight and flakes | ||
| // under CI load. Poll until the sizes agree — a genuinely dropped resize that | ||
| // never re-syncs still fails (the real column-desync bug), a slow-but-correct | ||
| // propagation no longer does. | ||
| const COLUMN_RESYNC_TIMEOUT_MS = 20_000 | ||
|
|
||
| async function waitForPtyColsToMatchXterm( | ||
| page: Page, | ||
| ptyId: string, | ||
| label: string, | ||
| timeoutMs = COLUMN_RESYNC_TIMEOUT_MS | ||
| ): Promise<void> { | ||
| const deadline = Date.now() + timeoutMs | ||
| let snapshot: ColumnSnapshot = { xtermCols: -1, ptyCols: -1 } | ||
| do { | ||
| snapshot = await readColumnSnapshot(page, ptyId) | ||
| if (snapshot.ptyCols === snapshot.xtermCols) { | ||
| return | ||
| } | ||
| await page.waitForTimeout(500) | ||
| } while (Date.now() < deadline) | ||
| throw new Error( | ||
| `${label}: PTY cols (${snapshot.ptyCols}) never re-synced to xterm cols (${snapshot.xtermCols}) ` + | ||
| `within ${timeoutMs}ms; a stale PTY width that never re-syncs is the column-desync bug` | ||
| ) | ||
| } | ||
|
|
||
| async function waitForReportedColsToMatchPty( | ||
| page: Page, | ||
| ptyId: string, | ||
| timeoutMs = COLUMN_RESYNC_TIMEOUT_MS | ||
| ): Promise<void> { | ||
| const deadline = Date.now() + timeoutMs | ||
| let reportedCols = -1 | ||
| let ptyCols = -1 | ||
| do { | ||
| ptyCols = await readPtyCols(page, ptyId) | ||
| reportedCols = await readReportedPtyCols(page, ptyId) | ||
| if (reportedCols === ptyCols) { | ||
| return | ||
| } | ||
| await page.waitForTimeout(500) | ||
| } while (Date.now() < deadline) | ||
| throw new Error( | ||
| `pty:getSize reported ${reportedCols} but the PTY's process.stdout.columns is ${ptyCols} and ` + | ||
| `never re-synced within ${timeoutMs}ms; getSize must reflect the APPLIED size so the ` + | ||
| `drift-check can detect a dropped resize` | ||
| ) | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect waitForPtyColumnsAtMost to see its actual retry/backoff behavior
rg -n -B2 -A25 'function waitForPtyColumnsAtMost' tests/e2e/terminal-column-desync-repro.spec.ts
rg -n 'READ_ANY_COLS' tests/e2e/terminal-column-desync-repro.spec.tsRepository: stablyai/orca
Length of output: 256
Bound the PTY probe to the 20s wrapper A single poll can still block for up to 30s inside readPtyCols(), so the 20s timeout here is not a real ceiling and the thrown error can understate the wall-clock cost. Tighten the inner budget or switch this check to expect.poll().
|
Closing as redundant. |
What changes
Makes the two flakiest cases in
terminal-column-desync-repro.spec.tsreliable under CI load by polling for the PTY↔xterm re-sync instead of asserting an exact match after a fixed 400–500ms wait. Test-only: no product code changes.:129(visible resize) and:169(pty:getSizeapplied size) now poll until the columns agree, bounded at 20s.What this does NOT do / why it's not a product change
This is not a product bug fix. Investigation (below) concluded the failure was a fragile test, not a defect — so nothing in the terminal/PTY code changes, and the poll still fails if a PTY genuinely never re-syncs (it does not paper over the real column-desync bug this suite guards).
Background — was it a real bug or a bad test?
terminal-column-desync:169was failing on ~3 of 4 loaded scheduled Linux runs (garbled-TUI repro suite), but passing on lighter runs and locally. Investigation:pty:getSizereturn node-pty'sproc.colsinstead of the emulator dims. ButSession.resizeadvances the emulator and subprocess atomically, and node-pty caches the requested size inproc.cols— the CI trace showsgetSize=72vs real kernel117, so returningproc.colswould still report 72. A staff-level design review (three converging reviewers) caught this before any code was written.:189/:228/:325/:398) deliberately drop resizes and assert the PTY re-syncs, using longer waits (500–900ms) and reload-loops — and they pass on CI. Only:169/:129failed, and they're the two with the shortest fixed waits and the simplest scenario — they sampled before the async re-sync completed under load. The PTY does re-sync (the whole file passes); the assertion just fired too early.The fix aligns
:169/:129with how the rest of the file already tolerates the async re-sync.Design-review outcome
Review correctly blocked the initial product-fix plan as a likely no-op and drove the pivot to the evidence-based test-hardening. Diagnosis was then confirmed empirically (below).
Headline behavior status
Implemented — the two flaky tests are hardened; a genuinely stuck PTY still fails. No product behavior changes.
Validation
terminal-column-desynctests passed under real shard load, including the previously-flaky:169/:129, which converged in ~15s (the old 500ms wait was far too short under load). The 20s poll budget gives headroom over the observed ~15s. (The overall run stays red only on the separately-deferred Batch-3 perf/app-instability groups.)Perf
Test-only. The poll returns on first convergence and is bounded at 20s (paid only while a resize is still propagating). No product hot path; net suite time neutral (replaces a flaky failure+retry with a bounded settle).
Risks / non-goals
getSize/emulator asymmetry (a real but separate code smell — daemon reports emulator dims, local reportsproc.cols); noted as a possible follow-up, but it is not what reddens these tests and a correct product fix there needs the true kernel winsize (TIOCGWINSZ), which node-pty doesn't expose.