Skip to content

non-blocking completions - #18334

Merged
fdncred merged 24 commits into
nushell:mainfrom
philocalyst:non-blocking-completions
Jul 17, 2026
Merged

fdncred merged 24 commits into
nushell:mainfrom
philocalyst:non-blocking-completions

Conversation

@philocalyst

@philocalyst philocalyst commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • in this PR, I made completions non-blocking by default. this means that for very expensive computations (git checkout for example), inputting text is lag-free.
  • it includes tests (including a trait to integrate easily into existing ones)
  • it works on a very simple always-on cache model. this means that entries will always be returned instantly. when new results are discovered, the completions are repainted.
  • the worst case for the model is that no results are returned in the first pass, but this is equivalent to the existing behavior without blocking input.

User-facing changes (Release notes)

  • Drastically improves completion UX, and eliminates any resentment towards completions as I had begun to develop, finding it better to just memorize input to avoid a long terminal freeze.

Additional notes

Screen.Recording.2026-06-03.at.09.32.03.mov

See relevant PR for reedline: nushell/reedline#1093

@philocalyst
philocalyst force-pushed the non-blocking-completions branch from 5b0a01f to 3d10a11 Compare June 3, 2026 12:50
@fdncred
fdncred marked this pull request as draft June 3, 2026 13:06
@fdncred

fdncred commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Converted to draft because I don't want it landed with the ../reedline change. It's also very significant changes. Not really a fan of the unsafe.

@philocalyst

Copy link
Copy Markdown
Contributor Author

Haha! I forgot about that cargo.toml change.

Let me see if I can get better than the unsafe.

@philocalyst
philocalyst force-pushed the non-blocking-completions branch from 3d10a11 to 18d9bd9 Compare June 3, 2026 13:26
@philocalyst

Copy link
Copy Markdown
Contributor Author

Isolated to A SINGLE unsafe block, feel free to ask further questions, it seems unavoidable. My other PR removes unsafe blocks so maybe it evens out??

@fdncred

fdncred commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

The only 2 acceptable changes for reedline in the Cargo.toml is having a versioned reedline like we do during a release and having this patch in our Cargo.toml.

[patch.crates-io]
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }

It's fine to have it the way you have it now, pointing to your reedline repo, for testing, but we'd never land it like this because it's not our reedline, of course. I guess you've done this because there are changes required to reedline? If so, please point out those PRs in the description.

I'm still not sold on the unsafe but I'll let others comment on that.

@philocalyst

philocalyst commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor Author

It's simply for testing. I invite anyone unsure about unsafe to read the comment and the associated page for a confidence boost!

@philocalyst
philocalyst force-pushed the non-blocking-completions branch from 18d9bd9 to 93abe1c Compare June 3, 2026 14:30
@fdncred

fdncred commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Ah, I missed that reedline PR. This looks very cool from the demo video. Thanks!

@philocalyst
philocalyst force-pushed the non-blocking-completions branch 2 times, most recently from ae30616 to 8ac1545 Compare June 3, 2026 17:28
@philocalyst

Copy link
Copy Markdown
Contributor Author

@fdncred Following up here :)

@fdncred

fdncred commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

@philocalyst Your reedline PR needs to be landed first and it looks like you haven't responded to comments there. There's also conflicts here.

Comment thread crates/nu-system/src/foreground.rs Resolved
@fdncred

fdncred commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

It's not real clear to me which parts of this work on Windows and which do not. I don't really like adding unix-only things.

@philocalyst

philocalyst commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@fdncred Managed to make it cross-platform -- windows has a similar flag I'm making use of. I don't have a windows machine to test on, so I got $llm to create a test for it that verifies the case -- but the flag was created as a 1:1 replacement of the unix one, so I'd be surprised if it doesn't work.

Also removed the panic-case with a classic fallback ! Just waiting on the second-pass for my reedline PR. Thank you to @blindFS too! The code is simpler now

@philocalyst

Copy link
Copy Markdown
Contributor Author

Comment thread Cargo.toml Resolved
@philocalyst
philocalyst force-pushed the non-blocking-completions branch from e4c3498 to 278af5d Compare June 16, 2026 18:31
@philocalyst
philocalyst marked this pull request as ready for review June 17, 2026 02:00
@philocalyst
philocalyst force-pushed the non-blocking-completions branch from 5b85219 to 075247d Compare June 17, 2026 03:22
@philocalyst

Copy link
Copy Markdown
Contributor Author

So it does seem to fail because of reedline :(

Should I uncomment?
# reedline = { git = "https://github.com/nushell/reedline", branch = "main" }

@philocalyst
philocalyst force-pushed the non-blocking-completions branch from 075247d to 8bc1ee4 Compare June 19, 2026 17:59
@fdncred

fdncred commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

it is uncommented in the latest main branch. seems like you need to rebase on main.

@philocalyst
philocalyst force-pushed the non-blocking-completions branch from 8bc1ee4 to 4ef901e Compare June 21, 2026 03:49
@philocalyst

Copy link
Copy Markdown
Contributor Author

Should be better than ever! Spent two hours chasing down a bug with completions that was already fixed upstream lmao, sorry for the delay :)

did some general simplifications with the final diff in hand, mainly
around error handling and how we route data through
@philocalyst
philocalyst force-pushed the non-blocking-completions branch from 3686cf3 to 842bb6b Compare July 16, 2026 00:27
@fdncred
fdncred merged commit 1ba3edb into nushell:main Jul 17, 2026
14 checks passed
@github-actions github-actions Bot added this to the v0.115.0 milestone Jul 17, 2026
@fdncred

fdncred commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Thanks! Looking forward to having this.

@fdncred

fdncred commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

There is a little something weird happening with this PR. @philocalyst Why does it complete to some intermediate list and then when I hit the down arrow look like regular nushell completions?
non-blocking

@fdncred

fdncred commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Also, if you're using carapace it pops up an entirely new window or two. We may need to revert.
non-blocking-2

@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Jul 20, 2026
@blindFS

blindFS commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Hi @philocalyst, I wonder if there's a way to fallback to the blocking completer somehow. Because I want to draw some fzf menus during the external completer call, it causes a lot of reedline troubles, like shown in the screen recording of #18771

@NotTheDr01ds

Copy link
Copy Markdown
Contributor

While I greatly appreciate your attempts to improve completions, I'm hitting multiple issues with this commit in place:

  1. Easily reproducible - Probably the same thing that @fdncred is seeing. Completions no longer auto-complete when the commandline only matches a single completion as they did before the PR. You either have to hit Tab a second time, Enter, or I guess like Darren said, the down-arrow.

  2. But much, much worse, completions get garbled, and I cannot reproduce the exact conditions under which this happens. Right now, I have a shell open where:

cd ~/sr<tab>
# completes to
cd ~/src/c
# then
cd ~/src/ntd-<tab>
# completes to 
cd ~/src/c/ntd
# If I hit tab multiple times on the cd ~/src/c
cd ~/src/c<tab>/c<tab>/c...
# => cd ~/src/c/c/c/c/c

All of these are invalid completions/directories.

If I restart the shell, the problem goes away for a few commandlines, it seems, then comes back. Again, can't reproduce the trigger condition.

Unfortunately it's so bad I'm going to have to build to before this commit for my daily use until fixed or reverted. It's just impossible to navigate the filesystem.

And I'm seeing this with others as well, such as $env.config.ho<tab> resulting in something like $env.confhooks (not the exact result, but can't reproduce exactly at the moment).

@fdncred

fdncred commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Yup @NotTheDr01ds we know it's bad. @philocalyst is currently working on it.

@NotTheDr01ds

Copy link
Copy Markdown
Contributor

Don't mean to harp on it if it's already known, but I didn't see any report of the second issue, so wasn't sure. Good to hear it's known.

@Juhan280

Copy link
Copy Markdown
Contributor

Don't mean to harp on it if it's already known, but I didn't see any report of the second issue, so wasn't sure. Good to hear it's known.

It was mentioned in discord, but now there is a separate issue for it

@NotTheDr01ds

Copy link
Copy Markdown
Contributor

@Juhan280 Can you point me to that issue? I'm not seeing anything that lines up with the problems I'm seeing, at least not from the title.

@Juhan280

Juhan280 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

@Juhan280 Can you point me to that issue? I'm not seeing anything that lines up with the problems I'm seeing, at least not from the title.

#18737

fdncred added a commit that referenced this pull request Aug 2, 2026
Requires nushell/reedline#1136
Related PR (Builds ontop of):
#18660

## Description

This is a follow-up to #18334 (non-blocking completions, merged) and
#18671 (test-infra sync, merged). Those landed the async worker model
(`CompletionResult` Fresh/Stale/Pending) but left... several issues
unresolved. Sorry to all the folks who put up with that on the nightlies
:(

Overarching changes:
- Across prompts we're using a LRU cache for storing and managing the
caches. This is configurable, and default bounded to 100. For many
completions nothing is loaded onto the LRU cache, only the intensive
operations (git checkout, carapace stuff, etc.). Open to dramatically
reducing this number, but it *sure* feels nice when it works.
- Cache work is a lot more robust, we do narrowing and carry always an
"env" for the completor environment, so we have a *rough* idea of when
to complete for the sources that are mostly pure.
- Added completionengine for the death of hardcoded dispatch with a
routing enum. This allowed me to rewrite the completor trait around the
context and fetched types, wiring a lot more logic directly through it.
- Added completionsite and sitekind models for a catch-all way for
resolving the facts of what is under the cursor, which kills maybe fifty
sites of span math (what caused the super annoying completion
duplication)
- *commandline complete --type` now type-checks its argument (previously
accepted any string and could silently no-op) and clamps the cursor to a
valid boundary instead of indexing out of range.
- complete paths is shared between file and directory completions, which
eliminates a panic risk and more manual span constructions.
- 
- **Flag/span plumbing.** `FlagRef` and `Flag::long_name` are adopted
across `nu-parser`/`nu-engine`/`nu-cmd-lang` so flag identity survives
through parsing and into completion and help-text rendering, which
eliminated a lot of re-derive logic.

## User-facing changes (Release notes)

- Added `$env.config.completions.cache_size` (default: `100`) to control
that cap.
- Completion results now persist across prompts instead of being
discarded on every new prompt,.
- Fixed a potential panic when narrowing file/directory completions on a
path containing multi-byte (non-ASCII) characters.
- `commandline complete --type` now validates its `--type` argument and
no longer panics on an out-of-range cursor.
- `use`, `overlay use`, `export use`, `source-env`, `hide-env`, `attr
complete`, and `which` now go through the same completion dispatch as
other builtins, fixing inconsistent/missing completions in a few of them

## Additional Notes
- Can't promise that this eliminates all bugs, just most of them. The
bigger thing it gives us is a more robust framework to fix bugs, going
forward. Will be responsive to anything related to completions, and am
okay with a longer review period before merge. The big things are
covered now, however, with the added tests in this PR.
-

fixes #11211

---------

Co-authored-by: Darren Schroeder <[email protected]>
kronberger-droid added a commit to kronberger-droid/nushell that referenced this pull request Aug 14, 2026
While the worker computes, reedline keeps reading the terminal, so a
custom completer that drives an interactive picker (`$candidates | fzf`)
paints its UI but never receives a keystroke. Disabling the option makes
the REPL completer settle on the reedline thread: reedline blocks on
input as it did before nushell#18334, and the completer can hand the terminal
to its child.

`complete()` is the only path to the worker spawn, so gating it turns
off every background piece at once. The cache is bypassed too: an
interactive completer is not a pure function, and the pre-nushell#18334
behavior this restores had no completion cache either. The LSP and
`commandline complete` already run inline through `CompletionEngine`
and are untouched.
kronberger-droid added a commit to kronberger-droid/nushell that referenced this pull request Aug 14, 2026
While the worker computes, reedline keeps reading the terminal, so a
custom completer that drives an interactive picker (`$candidates | fzf`)
paints its UI but never receives a keystroke. Disabling the option makes
the REPL completer settle on the reedline thread: reedline blocks on
input as it did before nushell#18334, and the completer can hand the terminal
to its child.

`complete()` is the only path to the worker spawn, so gating it turns
off every background piece at once. The cache is bypassed too: an
interactive completer is not a pure function, and the pre-nushell#18334
behavior this restores had no completion cache either. The LSP and
`commandline complete` already run inline through `CompletionEngine`
and are untouched.
fdncred pushed a commit that referenced this pull request Aug 22, 2026
## Description

While the completion worker computes, reedline keeps reading the
terminal, so a custom completer that drives an interactive picker
(`$candidates | fzf`) paints its UI but never receives a keystroke.
This adds a `background-completions` experimental option
(`Status::OptOut`, so the async path stays the default).
Disabled, the REPL completer settles on the reedline thread: reedline
blocks on input as it did before #18334, and the completer can hand the
terminal to its child.

Scope of the opt-out:

- `complete()` is the only path to the worker spawn, so gating it turns
off every background piece at once; `poll_completion` stays `Idle`.
- The cache is bypassed too: an interactive completer is not a pure
function, and the pre-#18334 behavior this restores had no completion
cache either, so opting out is faithful to the old behavior rather than
a regression against it.
- Suggestions still come from the current engine
(`fetch_completions_at`): the opt-out restores the old interaction
model, not old results.
- The LSP and `commandline complete` already run inline through
`CompletionEngine` and are untouched.

This option exists for configs that need the old blocking semantics
back.

## User-facing changes (Release notes)

Added the `background-completions` experimental option (enabled by
default). Disabling it makes completions block the line editor again,
which lets custom completers drive interactive child processes like fzf:

```nushell
nu --experimental-options '[background-completions=false]'
```

## Additional notes

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

Labels

notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants