Repository navigation
fix(terminal): keep post-spawn reconcile alive through locks - #6684
Conversation
📝 WalkthroughWalkthroughThe 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f06deae9-5828-4d30-a487-839db8738d82
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.ts
| globalThis.requestAnimationFrame = vi.fn((callback: FrameRequestCallback) => { | ||
| frameCallbacks.push(callback) | ||
| return frameCallbacks.length | ||
| }) | ||
| const runNextFrame = (): void => { | ||
| const callback = frameCallbacks.shift() | ||
| if (!callback) { | ||
| throw new Error('expected a queued animation frame') | ||
| } | ||
| callback(0) | ||
| } | ||
|
|
||
| const { connectPanePty } = await import('./pty-connection') | ||
| const { setDriverForPty } = await import('@/lib/pane-manager/mobile-driver-state') | ||
|
|
||
| const ptyId = 'pty-post-spawn-transient-lock' | ||
| setDriverForPty(ptyId, { kind: 'mobile', clientId: 'phone-1' }) | ||
| try { | ||
| const transport = createMockTransport(ptyId) | ||
| transportFactoryQueue.push(transport) | ||
| mockStoreState = { | ||
| ...mockStoreState, | ||
| tabsByWorktree: { 'wt-1': [{ id: 'tab-1', ptyId: null }] }, | ||
| ptyIdsByTabId: { 'tab-1': [] } | ||
| } | ||
| const pane = createPane(1) | ||
| pane.terminal.cols = 80 | ||
| pane.terminal.rows = 24 | ||
|
|
||
| connectPanePty(pane as never, createManager(1) as never, createDeps() as never) | ||
| runNextFrame() | ||
| await flushAsyncTicks() | ||
|
|
||
| pane.terminal.cols = 120 | ||
| pane.terminal.rows = 40 | ||
| runNextFrame() | ||
| expect(transport.resize).not.toHaveBeenCalled() | ||
|
|
||
| setDriverForPty(ptyId, { kind: 'idle' }) | ||
| runNextFrame() | ||
|
|
||
| expect(transport.resize).toHaveBeenCalledWith(120, 40) | ||
| } finally { | ||
| setDriverForPty(ptyId, { kind: 'idle' }) | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Restore the rAF mock and dispose the binding.
This test leaves globalThis.requestAnimationFrame replaced and a reconcile loop still queued after the assertion. Restore the global and dispose the pane binding in finally to avoid cross-test pollution.
Proposed fix
it('continues post-spawn size reconcile after a transient mobile presence lock', async () => {
const frameCallbacks: FrameRequestCallback[] = []
+ const originalRequestAnimationFrame = globalThis.requestAnimationFrame
globalThis.requestAnimationFrame = vi.fn((callback: FrameRequestCallback) => {
frameCallbacks.push(callback)
return frameCallbacks.length
})
@@
const { connectPanePty } = await import('./pty-connection')
const { setDriverForPty } = await import('`@/lib/pane-manager/mobile-driver-state`')
const ptyId = 'pty-post-spawn-transient-lock'
+ let binding: { dispose(): void } | null = null
setDriverForPty(ptyId, { kind: 'mobile', clientId: 'phone-1' })
try {
@@
- connectPanePty(pane as never, createManager(1) as never, createDeps() as never)
+ binding = connectPanePty(pane as never, createManager(1) as never, createDeps() as never)
@@
} finally {
+ binding?.dispose()
setDriverForPty(ptyId, { kind: 'idle' })
+ globalThis.requestAnimationFrame = originalRequestAnimationFrame
}
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| globalThis.requestAnimationFrame = vi.fn((callback: FrameRequestCallback) => { | |
| frameCallbacks.push(callback) | |
| return frameCallbacks.length | |
| }) | |
| const runNextFrame = (): void => { | |
| const callback = frameCallbacks.shift() | |
| if (!callback) { | |
| throw new Error('expected a queued animation frame') | |
| } | |
| callback(0) | |
| } | |
| const { connectPanePty } = await import('./pty-connection') | |
| const { setDriverForPty } = await import('@/lib/pane-manager/mobile-driver-state') | |
| const ptyId = 'pty-post-spawn-transient-lock' | |
| setDriverForPty(ptyId, { kind: 'mobile', clientId: 'phone-1' }) | |
| try { | |
| const transport = createMockTransport(ptyId) | |
| transportFactoryQueue.push(transport) | |
| mockStoreState = { | |
| ...mockStoreState, | |
| tabsByWorktree: { 'wt-1': [{ id: 'tab-1', ptyId: null }] }, | |
| ptyIdsByTabId: { 'tab-1': [] } | |
| } | |
| const pane = createPane(1) | |
| pane.terminal.cols = 80 | |
| pane.terminal.rows = 24 | |
| connectPanePty(pane as never, createManager(1) as never, createDeps() as never) | |
| runNextFrame() | |
| await flushAsyncTicks() | |
| pane.terminal.cols = 120 | |
| pane.terminal.rows = 40 | |
| runNextFrame() | |
| expect(transport.resize).not.toHaveBeenCalled() | |
| setDriverForPty(ptyId, { kind: 'idle' }) | |
| runNextFrame() | |
| expect(transport.resize).toHaveBeenCalledWith(120, 40) | |
| } finally { | |
| setDriverForPty(ptyId, { kind: 'idle' }) | |
| } | |
| const frameCallbacks: FrameRequestCallback[] = [] | |
| const originalRequestAnimationFrame = globalThis.requestAnimationFrame | |
| globalThis.requestAnimationFrame = vi.fn((callback: FrameRequestCallback) => { | |
| frameCallbacks.push(callback) | |
| return frameCallbacks.length | |
| }) | |
| const runNextFrame = (): void => { | |
| const callback = frameCallbacks.shift() | |
| if (!callback) { | |
| throw new Error('expected a queued animation frame') | |
| } | |
| callback(0) | |
| } | |
| const { connectPanePty } = await import('./pty-connection') | |
| const { setDriverForPty } = await import('`@/lib/pane-manager/mobile-driver-state`') | |
| const ptyId = 'pty-post-spawn-transient-lock' | |
| let binding: { dispose(): void } | null = null | |
| setDriverForPty(ptyId, { kind: 'mobile', clientId: 'phone-1' }) | |
| try { | |
| const transport = createMockTransport(ptyId) | |
| transportFactoryQueue.push(transport) | |
| mockStoreState = { | |
| ...mockStoreState, | |
| tabsByWorktree: { 'wt-1': [{ id: 'tab-1', ptyId: null }] }, | |
| ptyIdsByTabId: { 'tab-1': [] } | |
| } | |
| const pane = createPane(1) | |
| pane.terminal.cols = 80 | |
| pane.terminal.rows = 24 | |
| binding = connectPanePty(pane as never, createManager(1) as never, createDeps() as never) | |
| runNextFrame() | |
| await flushAsyncTicks() | |
| pane.terminal.cols = 120 | |
| pane.terminal.rows = 40 | |
| runNextFrame() | |
| expect(transport.resize).not.toHaveBeenCalled() | |
| setDriverForPty(ptyId, { kind: 'idle' }) | |
| runNextFrame() | |
| expect(transport.resize).toHaveBeenCalledWith(120, 40) | |
| } finally { | |
| binding?.dispose() | |
| setDriverForPty(ptyId, { kind: 'idle' }) | |
| globalThis.requestAnimationFrame = originalRequestAnimationFrame | |
| } |
| // Mobile legitimately parks the PTY at phone dims; a transient guard | ||
| // should only skip this frame, not cancel the reconcile window. | ||
| if (!getFitOverrideForPty(ptyId) && !isPtyLocked(ptyId)) { | ||
| safeFit(pane) | ||
| const cols = pane.terminal.cols | ||
| const rows = pane.terminal.rows | ||
| if (cols > 0 && rows > 0 && (cols !== lastSentCols || rows !== lastSentRows)) { | ||
| // Initial spawn-time sync is authoritative, so it bypasses the | ||
| // visibility gate that onResize honors (but not the mobile guards above). | ||
| transport.resize(cols, rows) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Invalidate the sent-size baseline after a mobile skip.
If mobile parks the PTY at phone dimensions and the desktop size after unlock equals the original spawn size, lastSentCols/Rows still match and no restore resize is sent. Track that a guarded frame was skipped and force the first unblocked valid frame to reassert desktop dimensions.
Proposed fix
let frame = 0
let lastSentCols = spawnCols
let lastSentRows = spawnRows
+ let skippedMobileGuardFrame = false
const tick = (): void => {
if (disposed || transport.getPtyId() !== ptyId) {
return
}
// Mobile legitimately parks the PTY at phone dims; a transient guard
// should only skip this frame, not cancel the reconcile window.
- if (!getFitOverrideForPty(ptyId) && !isPtyLocked(ptyId)) {
+ const mobileGuardActive = Boolean(getFitOverrideForPty(ptyId) || isPtyLocked(ptyId))
+ if (mobileGuardActive) {
+ skippedMobileGuardFrame = true
+ } else {
safeFit(pane)
const cols = pane.terminal.cols
const rows = pane.terminal.rows
- if (cols > 0 && rows > 0 && (cols !== lastSentCols || rows !== lastSentRows)) {
+ if (
+ cols > 0 &&
+ rows > 0 &&
+ (skippedMobileGuardFrame || cols !== lastSentCols || rows !== lastSentRows)
+ ) {
// Initial spawn-time sync is authoritative, so it bypasses the
// visibility gate that onResize honors (but not the mobile guards above).
transport.resize(cols, rows)
+ skippedMobileGuardFrame = false
lastSentCols = cols
lastSentRows = rows
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Mobile legitimately parks the PTY at phone dims; a transient guard | |
| // should only skip this frame, not cancel the reconcile window. | |
| if (!getFitOverrideForPty(ptyId) && !isPtyLocked(ptyId)) { | |
| safeFit(pane) | |
| const cols = pane.terminal.cols | |
| const rows = pane.terminal.rows | |
| if (cols > 0 && rows > 0 && (cols !== lastSentCols || rows !== lastSentRows)) { | |
| // Initial spawn-time sync is authoritative, so it bypasses the | |
| // visibility gate that onResize honors (but not the mobile guards above). | |
| transport.resize(cols, rows) | |
| let frame = 0 | |
| let lastSentCols = spawnCols | |
| let lastSentRows = spawnRows | |
| let skippedMobileGuardFrame = false | |
| const tick = (): void => { | |
| if (disposed || transport.getPtyId() !== ptyId) { | |
| return | |
| } | |
| // Mobile legitimately parks the PTY at phone dims; a transient guard | |
| // should only skip this frame, not cancel the reconcile window. | |
| const mobileGuardActive = Boolean(getFitOverrideForPty(ptyId) || isPtyLocked(ptyId)) | |
| if (mobileGuardActive) { | |
| skippedMobileGuardFrame = true | |
| } else { | |
| safeFit(pane) | |
| const cols = pane.terminal.cols | |
| const rows = pane.terminal.rows | |
| if ( | |
| cols > 0 && | |
| rows > 0 && | |
| (skippedMobileGuardFrame || cols !== lastSentCols || rows !== lastSentRows) | |
| ) { | |
| // Initial spawn-time sync is authoritative, so it bypasses the | |
| // visibility gate that onResize honors (but not the mobile guards above). | |
| transport.resize(cols, rows) | |
| skippedMobileGuardFrame = false | |
| lastSentCols = cols | |
| lastSentRows = rows |
Summary
Follow-up to #6649.
Tests