Skip to content

Keep Stata console sends from being lost at --more--, while connecting, or behind a long command, and keep polling after a huge burst of output - #416

Merged
jbearak merged 3 commits into
mainfrom
t3/fix-stata-console-queue-bugs
Nov 19, 2026

Conversation

@jbearak

@jbearak jbearak commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

A review before the stable release found four ways the new Stata console (sight console and the Windows Automation pane) loses output or sends. This PR fixes all four.

1. A burst of Windows output stopped polling for good. If one poll read about 200,000 log lines (a large list with set more off), held_lines.push(...lines) threw RangeError: Maximum call stack size exceeded. The poll promise rejected, no further poll was scheduled, and output and queued commands were stuck after that. Now the backend appends without spreading, consumes held lines by index (so a huge poll isn't quadratic), and keeps polling when an iteration throws, saying so once. I swept src/console/ for the same pattern and found one more, the multi-line paste in session.ts.

2. Windows deleted a queued do-file before Stata opened it. Say Stata is running sleep 60000 and you send another statement. The temp file's 30 s cleanup started when the send was handed to the pane, but Stata got the do at about 60 s. Now the pane holds each typed send's file until its console actually gives the line to Stata, then deletes it 30 s later. If the line is dropped (Ctrl+C) or the pane ends first, it deletes the file at once. A cleanup scheduled while the file was held never deletes it, even if it fires after the release.

3. An editor send disappeared at --more--. The pane typed do "file" plus Enter, so d answered the pager and an empty line was submitted. Editor sends now come in through their own entry point, send_line (the console runtime API goes to v3). At --more-- a send waits, with a note under the prompt, and goes out at the next command prompt, one per prompt. Ctrl+C drops waiting sends. Keys you type still answer --more--.

4. A terminal send vanished while a Windows pane was connecting. "Terminal: Do Line or Selection" called sendText on the active terminal, and the pane drops input until its session exists. Now, when the active terminal is a Stata pane, these commands go through the pane's queue, the same way the integrated target does. That also gives them fixes 2 and 3.

Changes outside src/console/, commands.ts and console-pane.ts:

  • stata-terminal-manager.ts: type_send passes the temp file path to the pane, and there is a new send_to_console_pane_terminal export.
  • temp-file.ts: hold_temp_file and release_temp_file. A cleanup scheduled while a file is held skips it.
  • The shared harness in tests/integration/send-to-stata-integrated-terminal.test.ts: the temp-file mock honors holds, the fake console is v3 with send_line, the window mock has activeTerminal, and the send_to_terminal mock records what it sends.

Not changed: on macOS and Linux, the PTY backend writes a line straight to Stata's terminal and reports it as given to Stata right away. A send made behind a long command there still has the old 30 s window.

How I proved it: each fix has a regression test that failed before the fix and passes after:

  • the burst test (1,000,000 lines, since Bun overflows only past about a million; Node overflows at 200k) threw the RangeError at automation-backend.ts:572;
  • a probe of the old pane path at --more-- wrote ["d\r", "\r"];
  • with the old code the integration tests showed no file held and the terminal send going to sendText.

The Windows items were proven against the simulated bridge and fake console runtime, not a live Windows Stata. All four gates passed separately on the rebased head: check:line-endings, typecheck, bun test ./tests (9920 pass, 0 fail) and lint.

Created with Claude Opus 5.5 in Claude Code.

@coderabbitai

coderabbitai Bot commented Nov 19, 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 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 86 included PR review attempts over the past 7 days set your current allowance at 1 review 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: 87529940-f2f0-42f3-96cb-27266a30ce8e
Commits

Reviewing files that changed from the base of the PR and between 49213d6 and 370d8a8.

Files selected for processing: 17

  • client/src/send-to-stata/commands.ts
  • client/src/send-to-stata/console-pane.ts
  • client/src/send-to-stata/stata-terminal-manager.ts
  • client/src/send-to-stata/temp-file.ts
  • docs/send-to-stata.md
  • src/console/automation/automation-backend.ts
  • src/console/backend.ts
  • src/console/editor-console-tty.ts
  • src/console/editor-console.ts
  • src/console/pty-backend.ts
  • src/console/session-host.ts
  • src/console/session.ts
  • tests/integration/client-console-bundle.test.ts
  • tests/integration/send-to-stata-integrated-terminal.test.ts
  • tests/unit/console/automation-backend.test.ts
  • tests/unit/console/session.test.ts
  • tests/unit/send-to-stata/temp-file.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

… editor sends from being lost at --more--, while connecting, or behind a long command

- Automation backend: append a poll's lines without spreading them
  (a burst of ~200k lines overflowed the stack and stopped polling for
  good), consume held lines by index, and keep polling after a poll
  throws, saying so once.
- Editor sends go through a new send_line entry (console API v3): at
  --more-- they wait for the prompt instead of being taken as pager
  keys; typed keys still answer --more--.
- A Stata pane holds each typed send's temp file until its console
  gives the line to Stata, then deletes it after the usual delay; it
  deletes it at once if the line is dropped or the pane ends.
- The active-terminal commands send to a Stata pane through its queue,
  so a send made while the pane connects isn't dropped.
@jbearak
jbearak force-pushed the t3/fix-stata-console-queue-bugs branch from fd9fd75 to f8eee78 Compare November 19, 2026 14:40
@jbearak
jbearak merged commit aa70662 into main Nov 19, 2026
16 checks passed
@jbearak
jbearak deleted the t3/fix-stata-console-queue-bugs branch November 19, 2026 14:53
jbearak added a commit that referenced this pull request Nov 19, 2026
…ritten when formatting, and read abbreviated weights and foreach list types in parse --json (#419)

* Keep embedded strings, option arguments, call parens and blank input rows as written, and read abbreviated weights and foreach list types in parse --json

Formatter (both modes unless noted):
- An inline python:/mata: statement whose string holds a ; before a
  comment marker ("a;\t//b") comes back byte for byte. Only a ; that
  ends the statement (a #delimit ; terminator, or a ; before ///) is
  kept outside the placeholder.
- Under #delimit ;, a /// after the ; that ends a statement no longer
  makes the next statement a continuation line, so one format reaches
  the fixed point and the indentation diagnostic agrees.
- AST mode prints option arguments as written instead of respacing
  them as expressions, which turned using(plugins/my.plugin) into
  using(plugins / my.plugin), format(%9.0g) into format(9.0g), eq(#2)
  into eq(2) and c:\data\x.gph into c : data x.gph.
- AST mode keeps the () of a call with no arguments (display
  runiform()) and a blank data row between input and end.
- Embedded-block placeholders are applied in one pass with line
  offsets computed once (1,000 mata: lines: 11.3 ms to 2.3 ms for
  indentation diagnostics).

sight parse --json:
- Weight words and abbreviations Stata 18 accepts: w..weight,
  fw..fweight, freq..frequency, aw..aweight, cell..cellsize,
  pw..pweight, iw..iweight.
- foreach ... of var/new/num/loc/glo (three letters or more) report the
  full list type.
- else /* c */ if reports else_if: true.
- syntax Level(integer 95) reports default "95"; hover shows it as
  Level(integer 95).
- display runiform() reports runiform() as its argument.

* Parse include using/…, program `name', glued using and price[`weight'] as Stata does, and keep label/note text and program-header comments when formatting (#417)

Fixes parser regressions since v0.15.1, each checked against StataMP 18:

- include/do/run using/setup.do takes the path, not the using keyword
- program `cmdname' defines a program closed by its end
- #delimit ; program // note, then define p; defines p
- `stem'using, `stem'in and `stem'if are one name
- price[`weight'] is a subscript, not a weight clause
- label variable/data/define, char and note ...: text keeps its
  if/in/using words, and AST formatting prints it as written
- a comment in a program header, or a /// note before an inline
  mata:, makes AST formatting leave the file as written instead of
  dropping it
- a run of // comments in a #delimit ; statement parses in linear time

* Keep Stata console sends from being lost at --more--, while connecting, or behind a long command, and keep polling after a huge burst of output (#416)

* Keep the Stata console polling after a huge burst of output, and keep editor sends from being lost at --more--, while connecting, or behind a long command

- Automation backend: append a poll's lines without spreading them
  (a burst of ~200k lines overflowed the stack and stopped polling for
  good), consume held lines by index, and keep polling after a poll
  throws, saying so once.
- Editor sends go through a new send_line entry (console API v3): at
  --more-- they wait for the prompt instead of being taken as pager
  keys; typed keys still answer --more--.
- A Stata pane holds each typed send's temp file until its console
  gives the line to Stata, then deletes it after the usual delay; it
  deletes it at once if the line is dropped or the pane ends.
- The active-terminal commands send to a Stata pane through its queue,
  so a send made while the pane connects isn't dropped.

* Don't let a hand-off's cleanup delete a send's file soon after the pane releases it

* Read input data, prefixed mata: and python: openers, and #delimit ; star comments as Stata does (#414)

* Read input data, prefixed embedded openers, and #delimit ; star comments as Stata does

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bound the program-header check to the input data region

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Test formatting of prefixed mata: lines and #delimit ; input records

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Test a * comment after an abbreviated #d ;

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

* Print no stray ; for an input with no records under #delimit ;

The blank-row check compared line numbers, which under #delimit ; is
true for an empty block because the data starts on the input line.
Caught by input-data-edge-cases.test.ts once main's #414 was merged in.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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