Skip to content

fix: cancel deferred configureTmux timer on session destroy (flaky pty-server test)#728

Merged
h0x91b merged 1 commit into
mainfrom
fix/dev3-pty-configure-timer-leak
Jun 25, 2026
Merged

fix: cancel deferred configureTmux timer on session destroy (flaky pty-server test)#728
h0x91b merged 1 commit into
mainfrom
fix/dev3-pty-configure-timer-leak

Conversation

@h0x91b

@h0x91b h0x91b commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Hi, this is Claude (the AI assistant working on this branch) 👋

Summary

Fixes the flaky pty-server test configureTmux via spawnPty › sources tmux config after timeout when socket is provided, which failed intermittently on slow CI runners with expected [ 'tmux', '-L', 'dev3', ... ] to include 'conf-socket'.

Root cause — not a fake-timer race, but a leaked real timer across tests. createSessionspawnPty schedules setTimeout(() => configureTmux(...), 200), but the handle was never stored, so destroySession() could not cancel it. Tests that use real timers tear the session down in afterEach before the 200ms fires; the stale timer then fires during a later test, calling spawn('source-file') with that session's socket (usually the default dev3). vi.clearAllMocks() resets mock.calls per test but not pending OS timers, so the leaked spawn lands in the current test's mock.calls, and .find(c => includes('source-file')) returned the wrong call.

Fix

  • Store the deferred configureTmux timer on the session (configureTimer) and clearTimeout it in destroySession. A torn-down session no longer sources its tmux config 200ms later — a genuine correctness fix that also removes the cross-test leak at the source.
  • Make the affected tests match the source-file call for their own socket instead of the first one found.
  • Add a deterministic regression test: destroy the session before the timeout → no source-file spawn.

Verified the regression test fails without the production fix, then passes with it. bun run lint clean; full suite green (mainview 1636, bun 1548).

The post-spawn configureTmux() runs on a 200ms setTimeout whose handle was
never stored, so destroySession() could not cancel it. A torn-down session
still sourced its tmux config 200ms later, and in the test suite that stale
timer leaked a default-socket source-file spawn into a later test — making
'sources tmux config after timeout when socket is provided' flaky on slow CI
runners (it matched the leaked dev3 socket instead of conf-socket).

Store the timer on the session, clear it in destroySession, and make the
affected tests match the source-file call for their own socket. Adds a
deterministic regression test.
@h0x91b h0x91b enabled auto-merge (squash) June 25, 2026 14:28
@h0x91b h0x91b merged commit 05236d6 into main Jun 25, 2026
4 checks passed
@h0x91b h0x91b deleted the fix/dev3-pty-configure-timer-leak branch June 25, 2026 14:30
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