Skip to content

Stop console-pty tests from hanging in CI: run the sight-pty helper tests in their own process, away from a Bun 1.3 double close - #380

Merged
jbearak merged 1 commit into
mainfrom
fix-console-pty-flakes
Nov 5, 2026
Merged

jbearak merged 1 commit into
mainfrom
fix-console-pty-flakes

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

console-pty.test.ts kept failing CI at random. Usually the first test hit the 5 s timeout with a blank screen; once await proc.exited threw EBADF instead. Reruns passed. The tests weren't slow: in 105 recent CI jobs the first test took 559–669 ms whenever it passed, and every failure stopped at exactly 5,000 ms.

The cause is a Bun 1.3.x bug. When a child is spawned with an extra stdio pipe (fd 3, the sight-pty control channel), Bun closes that pipe's fd when the child exits, then closes the same number again when the stream is garbage-collected. The second close hits whatever has reused the number. helper-pty.test.ts runs just before console-pty.test.ts in CI's single test process, so the victim was usually console-pty's terminal, and once an epoll fd (the EBADF). Closing the streams explicitly in the tests doesn't prevent it. Bun 1.4.0 fixed it. CI pins 1.3.13.

So CI now runs helper-pty.test.ts in its own bun test step, and the main run skips it with --path-ignore-patterns. Comments in ci.yml and the test file record the bug. No timeouts changed, and nothing catches EBADF.

How I found it, in a Linux container with Bun 1.3.13:

  • console-pty only stalls when the sight-pty helper tests run first in the same process: 11/60 together, 0/40 alone. No single helper test reproduces it, because the late closes build up across the group.
  • During a stall, the test process had lost its terminal's master fd even though the test never closed it.
  • A Bun-only script with this spawn shape closed a reused fd in 149 of 150 runs on 1.3.13, the same on 1.3.14, and 0/20 on each of 1.4.0 through 1.4.4. I found no matching Bun issue.

Proof: in that container, the two-file command that failed 5/45 without the change failed 0/60 with it, with no EBADF. Line endings, typecheck, lint and actionlint pass.

Follow-up, not in this PR: run alone, helper-pty.test.ts can still trip itself (2/50 in the container, none in 78 CI logs). Moving CI and release builds to Bun 1.4 or later would fix the bug itself.

Reviewed with sol-loop: 1 round with gpt-6.1-sol. Sol verdict: approved.

Created with Claude Opus 5.5 in Claude Code (T3 Code); reviewed by gpt-6.1-sol in Codex.

Summary by CodeRabbit

  • Tests
    • Updated CI to run the PTY integration test separately from the general test suite.
    • Documented a Bun 1.3.x issue that can affect PTY test output and process handling, and noted its fix in Bun 1.4.0.

…ble close can't hang console-pty

On Bun 1.3.x, a child spawned with an extra stdio pipe (fd 3, sight-pty's
control channel) has that pipe's fd closed when the child exits and again
when the stream is garbage-collected. The second close hits whatever has
reused the number. In CI's single test process that was usually
console-pty.test.ts's Bun.Terminal, which went blank until the 5 s
timeout, or an epoll fd (EBADF in `await proc.exited`). Bun 1.4.0 fixed
it. CI now runs helper-pty.test.ts in a separate `bun test` step.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The CI workflow excludes the PTY helper test from the general test run and executes it separately. Comments in the workflow and test file describe a Bun 1.3.x file-descriptor issue and note that it is fixed in Bun 1.4.0.

Changes: PTY test CI execution

Layer / File(s) Summary
Isolate PTY test execution in CI
.github/workflows/ci.yml, tests/integration/console/helper-pty.test.ts
The general test run excludes the PTY helper test, which runs separately. Comments describe the reported Bun 1.3.x file-descriptor issue and its stated fix in Bun 1.4.0.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

  • jbearak/sight#341: Adds the PTY helper test and implementation that this change isolates in CI.
  • jbearak/sight#343: Changes PTY runtime and child-process shutdown behavior in the same test area.
Merge Risk: Minimal · up to 05239

The CI isolation change has no established merge-blocking risk.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the helper PTY tests now run in a separate process to stop console-pty tests from hanging in CI. It also names the Bun 1.3 double-close cause. The title is long, but i…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Title check

Explanation

The title names the main change: the helper PTY tests now run in a separate process to stop console-pty tests from hanging in CI. It also names the Bun 1.3 double-close cause. The title is long, but it matches the changeset and the PR objectives.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 65dc5751-a093-4336-83ec-8992da59fc99
Commits

Reviewing files that changed from the base of the PR and between 18802b6 and 05239c2.

Files selected for processing: 2

  • .github/workflows/ci.yml
  • tests/integration/console/helper-pty.test.ts

Included review availability: This review used your included allowance. 3 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.

@jbearak
jbearak merged commit 99b8570 into main Nov 5, 2026
16 checks passed
@jbearak
jbearak deleted the fix-console-pty-flakes branch November 5, 2026 11:04
jbearak added a commit that referenced this pull request Nov 19, 2026
…e pinned Bun

release-build.yml ran bun test ./tests in one process, which on Bun
1.3.13 can hang or throw EBADF unless helper-pty.test.ts runs on its
own (#380). Both workflows now run bun run test:ci, a package.json
script that does that split, and a test checks they still match.

Co-authored-by: Claude Opus 5.5 <[email protected]>
jbearak added a commit that referenced this pull request Nov 19, 2026
…e pinned Bun

release-build.yml ran bun test ./tests in one process, which on Bun
1.3.13 can hang or throw EBADF unless helper-pty.test.ts runs on its
own (#380). Both workflows now run bun run test:ci, a package.json
script that does that split, and a test checks they still match.

Co-authored-by: Claude Opus 5.5 <[email protected]>
jbearak added a commit that referenced this pull request Nov 19, 2026
…e build's tests the way CI does (#420)

* Send only the cursor's statement under #delimit ;, not a neighbour on its first or last line

With display on one line and 1; clear; on the next, Send Statement on
display also ran clear;, and the same held for }; clear; after a block
and for code before a statement on its first line. The detector now
reads each ; statement's character range and sends the statements that
start on the cursor's line (or the one through it), cutting the lines
they share. When the last line holds the next statement, the cursor
stays there. Send Upward and Downward Lines end and start at the same
cuts.

Co-authored-by: Claude Opus 5.5 <[email protected]>

* Run the release build's tests the way CI does, so it can't hang on the pinned Bun

release-build.yml ran bun test ./tests in one process, which on Bun
1.3.13 can hang or throw EBADF unless helper-pty.test.ts runs on its
own (#380). Both workflows now run bun run test:ci, a package.json
script that does that split, and a test checks they still match.

Co-authored-by: Claude Opus 5.5 <[email protected]>

* Read a document for sending once per edit, not on every send

Each send lexed and parsed the whole document, which took about 130 ms
on a 50,000-line file even to send a selection. The reading is now
kept per document until its version changes.

Co-authored-by: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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