Skip to content

test(pty-connection): drain async confirm reads between tests to fix flaky CI - #9260

Merged
brennanb2025 merged 1 commit into
mainfrom
fix/pty-connection-test-timer-leak
Jul 18, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
fix/pty-connection-test-timer-leak

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Problem

The verify job intermittently fails in CI on the connectPanePty suite
(src/renderer/src/components/terminal-pane/pty-connection.test.ts) with a
clearAgentLaunchConfig call-count assertion, e.g.:

AssertionError: expected "vi.fn()" to be called once with arguments: [ Array(1) ]
Number of calls: 5
  2nd call: [ "tab-1:22222222-2222-4222-8222-222222222222" ]   // a DIFFERENT test's pane key
  5th call: [ "tab-1:22222222-2222-4222-8222-222222222222" ]

(This is what failed the verify check on #9254.)

Root cause

Cross-test async leakage. Pane foreground-agent trackers
(createPaneForegroundAgentTracker) kick off confirmForegroundProcess reads
whose continuations settle on the microtask queue, not on fake timers. A
test that ends with one still in flight leaks it into the next test, where it
resolves against that test's freshly-reset store mock and calls
clearAgentLaunchConfig with the prior test's pane key. Because the store
mock's getState() always returns the current test's mockStoreState, the
stale continuation pollutes whichever test happens to be running when it
settles — hence the foreign 2222… (LEAF_2) keys in a test that only uses
1111… (LEAF_1).

Fix

Drain pending microtasks in afterEach (via the existing flushAsyncTicks
helper) before tearing down fake timers, while the test still owns its
store mock. Each test then absorbs its own async fallout instead of leaking it
forward. Behavior-only test-harness change; no product code touched.

Validation

  • Full file stays green: 446/446, repeatedly (incl. under --max-old-space-size=700 GC pressure).
  • No regression; the change only adds a microtask drain to teardown.

Honest caveat on reproducibility

This is a CI-timing flake: I could not reproduce it locally in isolation —
ordered runs pass repeatedly, and the delicate inter-test microtask timing that
triggers it only shows up under the full-suite CI environment. The fix targets
the one mechanism that can produce the exact error signature (a leaked async
continuation calling a store mutator with another test's pane key) and removes
the timing dependence. Nearly all reads in the affected path run under fake
timers, so a real-timer variant of the same leak is not the vector here.

Separately, I noticed running this file with --sequence.shuffle OOMs (runaway
allocation) — a distinct, pre-existing issue unrelated to the ordered CI
failure and out of scope for this PR; noting it for follow-up.

The connectPanePty suite intermittently fails in CI on
`clearAgentLaunchConfig` call-count assertions (e.g. expected exactly
once, received 5 with pane keys belonging to other tests).

Root cause is cross-test async leakage: pane foreground-agent trackers
kick off `confirmForegroundProcess` reads whose continuations settle on
the microtask queue, not on fake timers. A test that ends with one still
in flight leaks it into the next test, where it resolves against that
test's fresh store mock and calls clearAgentLaunchConfig with the prior
test's pane key.

Drain pending microtasks in afterEach (before tearing down fake timers,
while the test still owns its store mock) so each test absorbs its own
async fallout. No behavior change; full suite stays green (446/446).

Note: this is a CI-timing flake not reproducible locally in isolation
(ordered runs pass repeatedly, incl. under GC pressure); the fix targets
the confirmed leak mechanism and removes the timing dependence.
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 84e18ffc-53fd-4889-ab5a-02fe27287296

📥 Commits

Reviewing files that changed from the base of the PR and between d153295 and 8eb05e6.

📒 Files selected for processing (1)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts

📝 Walkthrough

Walkthrough

Updated the PTY connection test suite’s afterEach cleanup to be asynchronous and await flushAsyncTicks(), ensuring pending microtasks complete before test cleanup proceeds.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and fix, but it doesn't follow the required template sections for Summary, Screenshots, Testing, AI Review Report, Security Audit, or Notes. Rewrite it using the repo template and fill in all required sections, especially testing status, cross-platform review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main fix: draining async confirm reads between tests to prevent flaky CI.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit bd72056 into main Jul 18, 2026
3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ai#9260)

The connectPanePty suite intermittently fails in CI on
`clearAgentLaunchConfig` call-count assertions (e.g. expected exactly
once, received 5 with pane keys belonging to other tests).

Root cause is cross-test async leakage: pane foreground-agent trackers
kick off `confirmForegroundProcess` reads whose continuations settle on
the microtask queue, not on fake timers. A test that ends with one still
in flight leaks it into the next test, where it resolves against that
test's fresh store mock and calls clearAgentLaunchConfig with the prior
test's pane key.

Drain pending microtasks in afterEach (before tearing down fake timers,
while the test still owns its store mock) so each test absorbs its own
async fallout. No behavior change; full suite stays green (446/446).

Note: this is a CI-timing flake not reproducible locally in isolation
(ordered runs pass repeatedly, incl. under GC pressure); the fix targets
the confirmed leak mechanism and removes the timing dependence.
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