Skip to content

fix(pty): let agents run exit hooks before an immediate local-provider close SIGKILLs them - #33367

Merged
nwparker merged 1 commit into
mainfrom
nwparker/agint-teardown-sigkill
Oct 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/agint-teardown-sigkill

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

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 SessionEnd hooks 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) called killWithDescendantSweep without awaitEscalation. With that option missing, the sweep sends SIGTERM to the captured descendants with terminateDescendantSnapshot, which does not wait. It then calls killRoot right away. For an immediate close, killRoot is forceKillPosixPtyProcessGroups, which SIGKILLs every process group on the tty, including Claude's foreground group.

The daemon's TerminalSessionTeardown passes terminateDescendants: terminateShutdownDescendants and awaitEscalation. 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.310 binary):

What changed

  • The local provider's descendant sweep reuses the daemon's terminateShutdownDescendants. Its awaitEscalation: () => operation.immediate makes an immediate close wait for the descendant SIGTERM grace before the root group SIGKILL.
  • One assertion was added to the existing POSIX immediate-shutdown test. It fails without this fix.

Net change: +5/−1 lines of prod code.

Verification

I used an opt-in probe that is not checked in. It drives the real shutdownLocalPty with node-pty and a real claude --settings <file>, where the settings file has a SessionEnd hook that appends to a log. The probe waits 9 s, then closes.

host case main this PR
macOS arm64, Claude 2.1.310 agent-flagged, immediate no SessionEnd (81 ms) SessionEnd (1019 ms)
macOS typed, immediate no SessionEnd (76 ms) SessionEnd (939 ms)
macOS agent, graceful SessionEnd SessionEnd
Linux (Arch), Claude 2.1.309 agent-flagged, immediate no SessionEnd (52 ms) SessionEnd (1287 ms)
Linux typed, immediate no SessionEnd (41 ms) SessionEnd (1331 ms)
Linux agent, graceful SessionEnd SessionEnd

The daemon path, which is the default, was checked with the same kind of probe. It goes through createPtySubprocess (including the macOS /usr/bin/login TCC wrapper), then Session, then TerminalSessionTeardown.killSession. On current main it already fires SessionEnd for 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 by orca terminal close): SessionEnd fired, including for a 3 s hook. With tui: fullscreen, a daemon immediate close 5 s after launch leaves no fullscreenBootPending entry. A direct kill -9 control does leave one. On v1.4.206, which predates #22232, the same daemon probe reproduces both symptoms: no SessionEnd, and a leftover boot record.

Checks: pnpm test src/main/providers, pnpm tc:node, check:code-quality:changed.

Risk

  • An immediate local-provider close with live descendants can now take up to the existing 2.5 s descendant-verify window before the root is killed. This matches the daemon and stays inside the immediate-close reply budget (IMMEDIATE_KILL_REPLY_BUDGET_MS).
  • Windows is unchanged: killWithDescendantSweep returns through its job and taskkill branch before either option is read.
  • Remote and mobile closes reach this code through the execution host. There is no wire change.

Refs #23865, #22039

…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]>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3a16ef9-9edd-41db-9dc9-332e8ec9cc4f
Commits

Reviewing files that changed from the base of the PR and between 0fa161b and 8d54059.

Files selected for processing: 2
  • src/main/providers/local-pty-provider-shutdown.test.ts
  • src/main/providers/local-pty-termination.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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