Skip to content

fix: end sessions when the foreground shell exits (#448) - #827

Merged
MisterTea merged 9 commits into
masterfrom
issue-448
Sep 27, 2026
Merged

MisterTea merged 9 commits into
masterfrom
issue-448

Conversation

@MisterTea

@MisterTea MisterTea commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • End the session when the foreground shell exits, even if a background descendant still holds the PTY.
  • On that path, drain already-buffered terminal output and send TERMINAL_EXIT_STATUS with the real OpenSSH-style code. NetBSD's reaping waitpid stores that status before handleSessionEnd() returns.
  • Merged current master so the branch builds against the exit-status and inline SSH-config helpers.

Closes #448.

Test plan

  • ./et-test "[BackgroundProcessTeardown]" — childReaped, exit status 42 after sessionHasEnded(), NetBSD status helper, and a grandchild that is still alive after the session leader exits (exit status 42; no master-EOF probe, which is not portable on Darwin/FreeBSD)
  • ./et-test "sessionHasEnded path sends TERMINAL_EXIT_STATUS" — buffered output plus exit code 37
  • python3 test/system_tests/et_background_process_e2e.py --et build/et --etserver build/etserver --etterminal build/etterminal — remote ready line is exact (not local echo or shell-integration OSC); et exits 0 while a background sleep is still alive
  • PR CI green on 98cfd84cc (37 checks, mergeable)

…wn; ensure teardown does not wait for unrelated descendants
@MisterTea MisterTea changed the title Issue: issue-448 test: sketch background-process teardown coverage for #448 Sep 20, 2026
@MisterTea MisterTea changed the title test: sketch background-process teardown coverage for #448 fix: end sessions when the foreground shell exits (#448) Sep 20, 2026
@codecov

codecov Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.85294% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.85%. Comparing base (ca91fb5) to head (98cfd84).

Files with missing lines Patch % Lines
test/unit_tests/BackgroundProcessTeardownTest.cpp 58.21% 50 Missing and 11 partials ⚠️
test/unit_tests/UserTerminalHandlerTest.cpp 82.02% 8 Missing and 8 partials ⚠️
src/terminal/UserTerminalHandlerUnix.cpp 83.33% 3 Missing and 1 partial ⚠️
src/terminal/PseudoUserTerminalUnix.hpp 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #827      +/-   ##
==========================================
- Coverage   79.86%   79.85%   -0.01%     
==========================================
  Files         151      152       +1     
  Lines       21872    22144     +272     
  Branches    14197    14338     +141     
==========================================
+ Hits        17467    17683     +216     
- Misses       2601     2648      +47     
- Partials     1804     1813       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Delegate Agent and others added 7 commits September 20, 2026 21:23
Co-authored-by: Cursor <cursoragent@cursor.com>
Background descendants can keep the PTY open after the shell is gone.
Drain the last output and report the real status on that path, including
the NetBSD reap, and cover it with tests that do not treat local echo as ready.

Co-authored-by: Cursor <cursoragent@cursor.com>
Darwin EOFs the PTY master when the forkpty session leader exits even if a
descendant still holds the slave, so the unit test no longer requires a
non-EOF probe there. The e2e ready check strips shell-integration OSC/CSI
noise that was glued onto the marker line on Fedora. Prefer clang-format 18
locally so Formatting Check stays green.

Co-authored-by: Cursor <cursoragent@cursor.com>
Detach the grandchild with setsid/O_NOCTTY so Darwin CI does not reclaim it
with the forkpty session, and stop probing the master for EOF — BSD EOFs the
master when the session leader exits even while a descendant holds the slave.

Co-authored-by: Cursor <cursoragent@cursor.com>
macOS msan/novcpkg still tore down the grandchild when the forkpty child
exited mid-setup. Have the holder signal readiness only after setsid and
reopening the slave so the session leader cannot exit early.

Co-authored-by: Cursor <cursoragent@cursor.com>
@MisterTea
MisterTea merged commit 044bcb5 into master Sep 27, 2026
37 checks passed
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.

ET doesn't exit if background process is running

2 participants