Skip to content

Reset stale REPL interrupts before running a new command - #19337

Merged
fdncred merged 2 commits into
nushell:mainfrom
akasakariko:fix/prompt-interrupt-recovery
Oct 24, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
akasakariko:fix/prompt-interrupt-recovery

Conversation

@akasakariko

@akasakariko akasakariko commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Related to #18989 and follows up on #19163

The REPL resets interrupt signals at the start of each iteration, before evaluating the prompt
An interrupted prompt can leave the signal set for the transient prompt, line editor callbacks, and the next command

  • Recover interrupted signals after normal prompt evaluation, before constructing the transient prompt and entering the line editor
  • Keep command-boundary recovery before pre-execution hooks for interruptions from editor callbacks
  • Only reset at these recovery points when interrupted, avoiding extra plugin Reset messages on normal commands
  • Keep normal prompt errors visible and retain cancellation of running commands
  • Extend the existing regression test to cover the interrupted prompt result, transient prompt, custom completion, and a subsequent editor interrupt followed by a hook and command
  • Disable all shell-integration flags in the regression test and explain why its expressions use match to reach signal checks

Reproduction

  • Start an interactive session with a slow prompt closure such as { sleep 1min; "prompt" }
  • Press Ctrl-C while the prompt is evaluating
  • Try a custom completer that polls interruption signals, or a transient prompt closure containing sleep
  • Without prompt-boundary recovery, these callbacks inherit the interrupt until the next command is submitted
  • Enter match 1 { 1 => 42 }
  • Without command-boundary recovery, the command and its pre-execution hooks can inherit an interrupt from the prompt or editor
  • With both recovery points, the transient prompt, completion, hook, and new command run normally

The macOS PTY probe compared the previous PR commit 0c3e8f749 with the updated code
The previous PR binary reported normal and transient prompt interruption errors and offered no custom completion before Enter
The updated binary reported only the normal prompt interruption, offered completion before Enter, and rendered the transient prompt
The next hook and command succeeded in both probes, including after a separate SIGINT while waiting for input

A separate PTY probe kept a background thread job and a frozen external process registered during prompt interruption and verified cancellation of a later foreground command

User-facing changes (Release notes)

Fixed stale prompt interrupts affecting completions, transient prompts, and the next interactive command with its pre-execution hooks

Validation

Local checks on macOS aarch64 with Rust 1.97.1 at 2bcf4099e

Command Result
cargo test --locked --profile ci -p nu-cli --lib -- command_after_interrupted_prompt_runs_hooks_and_command Fails without prompt-boundary recovery at the transient prompt assertion, passes with the fix
cargo build --locked --profile ci --bin nu Passed
cargo test --locked --profile ci -p nu-cli --no-fail-fast 200 unit tests and 295 integration tests passed, 2 ignored
cargo test --locked --profile ci --test tests -- shell:: 341 passed, 6 ignored, including all 29 background-job tests
cargo test --locked --profile ci --bin nu -- signals:: 3 passed
cargo nuclippy Passed
cargo check --locked --profile ci --no-default-features --bin nu Passed
cargo fmt --all and cargo fmt --all --check Passed
typos 1.51.1 Passed
git diff --check Passed

Manual PTY checks passed for prompt errors remaining visible, completion and transient-prompt recovery before Enter, subsequent hook and command execution, editor-interrupt recovery, background and frozen job preservation, and foreground cancellation
The regression test emitted no shell-integration OSC or application-mode reset sequences

Additional notes

The command-boundary recovery retains a short race for a SIGINT arriving after Enter but before the reset
This is a trade-off to recover editor interruptions, not a claim that the race is eliminated

One initial baseline PTY launch in this follow-up timed out after 30 seconds without output, while the rerun and updated-binary probes passed
The earlier validation also recorded one 60-second PTY startup timeout
The causes were not established and the passing reruns do not erase those observations

This reproduction did not demonstrate actual job deletion, so this PR does not claim to resolve every scenario in #18989 or close that issue

Windows and Linux runtime validation is deferred to GitHub CI and is not included in the local results above

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

The reset fixes the next command, but the prompt's interrupt is still set while the next line is edited, so completers and the transient prompt fail until Enter.

Findings: 0 High severity · 1 Medium severity · 5 Low severity

Open (6)

Notes from my clanker, checked on 0c3e8f7. Built the branch, ran the new nu-cli test with and without the fix, and drove the binary through a pty to interrupt the prompt and then use completion and the transient prompt.

Comment thread crates/nu-cli/src/repl.rs Resolved
Comment thread crates/nu-cli/src/repl.rs Resolved
Comment thread crates/nu-cli/src/repl.rs Resolved
Comment thread crates/nu-cli/src/repl.rs Resolved
Comment thread crates/nu-cli/src/repl.rs Resolved
Comment thread crates/nu-cli/src/repl.rs Resolved
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 24, 2026
@fdncred
fdncred merged commit b1a32d1 into nushell:main Oct 24, 2026
11 checks passed
@fdncred

fdncred commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants