Skip to content

Handle to background job is dropped if $env.PROMPT closure is exited prematurely #18989

Closed

Description

@mkatychev

Bug report form

  • I have done a basic search of the issue tracker to find any existing issues that are similar.
  • I have checked that my version is at least the latest stable release available via my installation method.

Describe the bug

Image
$ ff

Job 102 is re-frozen
q^C^[Error: nu::shell::error

  × Operation interrupted
   ╭─[/Users/mkatychev/.config/nu/prompt.nu:6:16]
 5 │ ]: int -> oneof<string, nothing> {
 6 │     let icon = match $in {
   ·                ──┬──
   ·                  ╰── This operation was interrupted
 7 │         1 => $one
   ╰────

~/Documents/rust/nushell-ci>

How to reproduce

  1. Have $env.PROMPT defined as a closure that is rather expensive, in this case calling gstat on a big repo in a big repo such as https://github.com/nushell/nushell/
  1. Start an CPU intensive task in another shell or session (like a release build of nushell with all features!).
  2. have background jobs frozen in a nu session and change directories rapidly to make a lot of $env.PROMPT calls
  3. ^C before $env.PROMPT_COMMAND has finished

Expected behavior

I expect errors to happen during CPU scheduling but not to have said errors result in dropping all references to background jobs

Configuration

key value
version 0.115.1
major 0
minor 115
patch 1
branch
commit_hash 798c55d
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.95.0 (59807616e 2026-04-14)
rust_channel 1.95.0-aarch64-apple-darwin
cargo_version cargo 1.95.0 (f2d3ce0bd 2026-03-21)
build_time 2026-08-23 08:21:47 +00:00
build_rust_channel release
allocator standard
features default, helix, lsp, mcp, network, plugin, rustls-tls, sqlite, static-link-openssl, trash-support
installed_plugins gstat 0.115.1, query 0.115.1
experimental_options example=false, dc-glob=true, reorder-cell-paths=true, pipefail=true, enforce-runtime-annotations=true, native-clip=true, cell-path-types=true, background-completions=true

Activity

  1. added
    status:needs-triage
    on Sep 8, 2026
  2. mkatychev commented on Sep 8, 2026

    @mkatychev
    ContributorAuthor

    Same issue with background jobs triggered by standard library (while nushell was being compiled with --release):

    $ rg 'dist'
    
    ...
    
    Error: nu::shell::error
    
      × Operation interrupted
        ╭─[/Users/mkatychev/.config/nu/prompt.nu:42:17]
     41 │     let bg = if "nvim" in $jobs.description? { $"(ansi darkolivegreen3b)(ansi reset)" } | default ""
     42 │     let j_end = match ($jobs | length) {
        ·                 ──┬──
        ·                   ╰── This operation was interrupted
     43 │         0 => ""
        ╰────
    
    $ rg '\bdist\b'
    Error: nu::shell::error
    
      × Operation interrupted
        ╭─[std/dirs/mod.nu:22:20]
     21 │         from_string: {|| split row (char esep)}
     22 │         to_string: {|| str join (char esep)}
        ·                    ────────────┬────────────
        ·                                ╰── This operation was interrupted
     23 │     }
        ╰────
    
    Error: nu::shell::error
    
      × Operation interrupted
        ╭─[std/dirs/mod.nu:26:20]
     25 │         from_string: {|| into int}
     26 │         to_string: {|| into string}
        ·                    ────────┬───────
        ·                            ╰── This operation was interrupted
     27 │     }
        ╰────
  3. akasakariko commented on Oct 5, 2026

    @akasakariko
    Contributor

    I'd like to work on this

  4. mkatychev commented on Oct 23, 2026

    @mkatychev
    ContributorAuthor

    Just had this happen on latest nushell (after #19163 was merged):

    > x
    ^CError: nu::shell::error
    
      × Operation interrupted
        ╭─[/Users/mkatychev/.config/nu/prompt.nu:41:17]
     40 │     let bg = if "nvim" in $jobs.description? { $"(ansi darkolivegreen3b)(ansi reset)" } | default ""
     41 │     let j_end = match ($jobs | length) {
        ·                 ──┬──
        ·                   ╰── This operation was interrupted
     42 │         0 => ""
        ╰────
    
    $ jobs
    ╭────────────╮
    │ empty list │
    ╰────────────╯
  5. akasakariko commented on Oct 24, 2026

    @akasakariko
    Contributor

    I'll continue to follow up on this

  6. mkatychev commented on Oct 24, 2026

    @mkatychev
    ContributorAuthor

    Thank you for all the effort you've put into this!

    Is there any setting I can turn on for a logdump next time this happens?

  7. kronberger-droid commented on Nov 16, 2026

    @kronberger-droid
    Contributor

    I couldn't reproduce this on 0.117 on Linux: with a slow PROMPT_COMMAND, Ctrl+C while the prompt renders left a frozen job in job list every time, also after job unfreeze and refreezing.
    #19337 changed this area after your last try, does it still happen for you on 0.117?

    AI:X EXECUTE

  8. mkatychev commented on Nov 19, 2026

    @mkatychev
    ContributorAuthor

    I can't reproduce this on latest main either though it mainly happens during load heavy instances so triggering it reliably is a bit tricky, I can repon if I find this issue once more

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions