Repository navigation
fix(pty): let agents run exit hooks before an immediate local-provider close SIGKILLs them - #33367
Merged
Merged
Conversation
…r close SIGKILLs them The in-process local PTY provider's immediate close sent SIGTERM to the captured descendants and then, in the same tick, SIGKILLed every process group on the tty. Claude Code never got to run its SessionEnd hooks or withdraw its fullscreen boot record. Wait out the existing descendant SIGTERM grace before the root group kill, as the daemon has since #22232. Co-authored-by: Wooseong Kim <[email protected]>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
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. Comment |
This was referenced Oct 25, 2026
Merged
11 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When Orca closes a terminal right away, it should first ask the programs in it to quit (SIGTERM), give them a moment, and only then force-kill them (SIGKILL). The terminal daemon, which is the normal backend, has worked this way since #22232 (first shipped in v1.4.210). The in-process local PTY provider, used when the daemon is off or degraded, still sent the polite signal and the force-kill in the same tick. Claude Code therefore died before it could run its
SessionEndhooks or clear its fullscreen boot record. This PR makes the local provider wait out the same grace window the daemon already uses.Root cause
shutdownTrackedPty(src/main/providers/local-pty-termination.ts) calledkillWithDescendantSweepwithoutawaitEscalation. With that option missing, the sweep sends SIGTERM to the captured descendants withterminateDescendantSnapshot, which does not wait. It then callskillRootright away. For an immediate close,killRootisforceKillPosixPtyProcessGroups, which SIGKILLs every process group on the tty, including Claude's foreground group.The daemon's
TerminalSessionTeardownpassesterminateDescendants: terminateShutdownDescendantsandawaitEscalation. It SIGTERMs each descendant whose identity it has checked, waits up to the 2 s grace for it to exit, SIGKILLs only the ones still alive, and signals the root after that.Upstream Claude Code (installed
2.1.310binary):SessionEndfrom its SIGTERM/SIGHUP handlers, with a budget ofmax(1500ms, min(maxHookTimeout*1000, 60000))($Me()/aFs=1500,wjr=60000).fullscreenBootPending[pid]in~/.claude.json) is cleared when the process exits through a handler. A record left behind by a pid that is gone counts as a strike on the next launch ([Bug]: Pane teardown force-kills the process tree; Claude Code counts it as a failed fullscreen boot and disables its renderer #22039).What changed
terminateShutdownDescendants. ItsawaitEscalation: () => operation.immediatemakes an immediate close wait for the descendant SIGTERM grace before the root group SIGKILL.Net change: +5/−1 lines of prod code.
Verification
I used an opt-in probe that is not checked in. It drives the real
shutdownLocalPtywith node-pty and a realclaude --settings <file>, where the settings file has aSessionEndhook that appends to a log. The probe waits 9 s, then closes.The daemon path, which is the default, was checked with the same kind of probe. It goes through
createPtySubprocess(including the macOS/usr/bin/loginTCC wrapper), thenSession, thenTerminalSessionTeardown.killSession. On current main it already firesSessionEndfor typed and agent-launched Claude, with both immediate and graceful closes, on macOS and Linux. I also ran it against the installed app (orca terminal create --command claude …followed byorca terminal close):SessionEndfired, including for a 3 s hook. Withtui: fullscreen, a daemon immediate close 5 s after launch leaves nofullscreenBootPendingentry. A directkill -9control does leave one. On v1.4.206, which predates #22232, the same daemon probe reproduces both symptoms: noSessionEnd, and a leftover boot record.Checks:
pnpm test src/main/providers,pnpm tc:node,check:code-quality:changed.Risk
IMMEDIATE_KILL_REPLY_BUDGET_MS).killWithDescendantSweepreturns through its job and taskkill branch before either option is read.Refs #23865, #22039