Skip to content

Let Ctrl+C in sight console stop a command Stata runs through shell - #448

Merged
jbearak merged 3 commits into
mainfrom
t3/console-pty-process-group
Nov 23, 2026
Merged

jbearak merged 3 commits into
mainfrom
t3/console-pty-process-group

Conversation

@jbearak

@jbearak jbearak commented Nov 23, 2026

Copy link
Copy Markdown
Owner

In the command-line sight console, Ctrl+C didn't stop a command Stata was running through shell or !. shell sleep 60 kept going until the sleep finished. #447 fixed this in the VS Code Stata pane; this is the same fix for the Bun PTY.

Ctrl+C sent SIGINT to Stata's pid only, and Stata waits for whatever its shell started. A terminal's ^C goes to the whole foreground process group. The helper's group-signal fix can't be reused here:

  • Bun starts Stata in sight console's own process group, so there's no separate group to signal.
  • Bun's detached: true would give Stata its own session, but it also makes the PTY Stata's controlling terminal. That brings job control with it: after shell, Stata can be stopped with SIGTTIN (see the sight-pty.c header).

So Ctrl+C now takes one ps -A -o pid=,ppid= snapshot, then sends SIGINT to Stata and to every process descended from it. Stata is signalled first, so its interrupt is already pending when the command it's waiting for ends. Hang-up, kill and resize are unchanged.

Known gaps:

  • A process whose parent has already exited isn't reached, because it no longer descends from Stata.
  • ps is looked up on the inherited PATH.

Proof:

  • Ran the real CLI with StataMP 18 on macOS, driven through a PTY that sends a Ctrl+C keypress.
    • Before the fix: shell sleep 60 and !sleep 60 were still stuck after 8 s.
    • After the fix: each returns to the prompt in about 350 ms, and no sleep is left behind.
    • sleep 20000, a Mata loop and while 1 {} still print --Break--.
  • The new test, tests/integration/console/bun-pty.test.ts, fails without the fix and passed 100 runs in a row with it.
  • Line endings, typecheck, lint, and bun test ./tests pass (10521 tests, 0 failures).

Reviewed with sol-loop: 2 rounds with gpt-6.2-sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code (T3 Code).

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 65 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

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: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 8f6e8557-f1f4-47b2-b035-ed125ba0beba
Commits

Reviewing files that changed from the base of the PR and between 86ad9f1 and ac96152.

Files selected for processing: 2

  • src/console/pty.ts
  • tests/integration/console/bun-pty.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak merged commit f2725bf into main Nov 23, 2026
17 checks passed
@jbearak
jbearak deleted the t3/console-pty-process-group branch November 23, 2026 01:31
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