Skip to content

Hold native env test children until their output is read - #734

Merged
dakra merged 1 commit into
mainfrom
fix/native-env-test-drain-deadline
Oct 12, 2026
Merged

dakra merged 1 commit into
mainfrom
fix/native-env-test-drain-deadline

Conversation

@dakra

@dakra dakra commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Fixes the macOS-only CI flake where ghostel-test-native-process-env-first-entry-wins and ghostel-test-native-process-adds-display-for-graphical-frame fail with "produced no output (exit status 0)" after ~0.6 s.

Root cause

xnu's ptsclose (bsd/kern/tty_dev.c, FIX_VSX_HANG) forces the tty drain timeout to 60 ticks = 0.6 s at hz=100. When the child's last replica close happens, ttywait gives the master reader 0.6 s to consume queued output; past that, ttyflush discards it and the master sees only POLLHUP + EOF. /usr/bin/env prints and exits within a millisecond, so any reader-thread stall past 0.6 s on a loaded runner loses the whole output. Reproduced with a standalone PTY script: parent closes the replica, stalls, reads → the child's exit blocks exactly 0.6 s, then 0 bytes.

Keeping the replica open in the parent is not an option: the session-leader child then hangs forever in exit on macOS. TIOCSDRAINWAIT is overridden by ptsclose.

Change (tests only)

  • ghostel-test--env-command on POSIX runs env; printf GHOSTEL_HELD; read x; the native process helper waits for the marker, writes a newline to the PTY, then waits for exit as before. Windows path unchanged.
  • ghostel-test--env-done-command and the inline PWD-symlink script get the same read x hold; their callers only wait for the marker and teardown kills the child.
  • Dead skip-unless guards removed from the env tests.

Verified: the held command survives a 1 s reader stall in the repro where plain env returns nothing; make -j8 all passes.

On macOS, ptsclose gives the PTY master 0.6 s after the child's last
close to drain queued output and then discards it.  The env tests ran
commands that print and exit within a millisecond, so any reader-thread
stall past that deadline on a loaded CI runner left the terminal empty
with exit status 0.

The POSIX env commands now print their marker and block on read, so a
child cannot exit before the reader has its output.  The native
process helper releases a held command with a newline once the marker
is on screen; the other callers only wait for the marker and let test
teardown kill the child.
@dakra
dakra merged commit c12c6be into main Oct 12, 2026
33 checks passed
@dakra
dakra deleted the fix/native-env-test-drain-deadline branch October 12, 2026 11:36

This branch was previously deployed

1 inactive deployment
github-pages — c12c6be8 Deployed Oct 12, 2026 by dakra via deploy #216
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