Skip to content

feat(completions): add a background-completions opt-out - #18764

Merged
fdncred merged 1 commit into
nushell:mainfrom
kronberger-droid:feat/background-completions-opt-out
Aug 22, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
kronberger-droid:feat/background-completions-opt-out

Conversation

@kronberger-droid

@kronberger-droid kronberger-droid commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

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-non-blocking completions #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)

Add background-completions opt-out

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:

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

Additional notes

fixes #18771

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

@blindFS Can you check out if opting out fixes your problem?

@blindFS

blindFS commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@blindFS Can you check out if opting out fixes your problem?

Yes it does fix my problem, thanks!

I really appreciate your help, from joining the discussion with a more contemporary solution to this PR.

@blindFS

blindFS commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

BTW, I think LSP and commandline complete requests shouldn't be run in the background either.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

BTW, I think LSP and commandline complete requests shouldn't be run in the background either.

What lets you think that?

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

@blindFS Can you check out if opting out fixes your problem?

Yes it does fix my problem, thanks!

I really appreciate your help, from joining the discussion with a more contemporary solution to this PR.

Nice, happy to help!
Lets see how the completer work develops, since a few PRs are now up to land.

After we stabilized completions, we can then introduce this option or maybe include more codepaths if we experience more Problems with old configs.

Fine with that?

@blindFS

blindFS commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

BTW, I think LSP and commandline complete requests shouldn't be run in the background either.

What lets you think that?

LSP server runs in a dedicated process nu --lsp and a lsp client typically handles requests in a non-blocking way already.

As for the command of commandline complete, I assume it is blocking anyways.

@Juhan280

Copy link
Copy Markdown
Contributor

Shouldn't new experimental options start out as opt-in first? And then later converted to opt-out?

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Depends on how the completion progresses until release i would suggest.
Right now it will stay op-out for testing.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

BTW, I think LSP and commandline complete requests shouldn't be run in the background either.

What lets you think that?

LSP server runs in a dedicated process nu --lsp and a lsp client typically handles requests in a non-blocking way already.

As for the command of commandline complete, I assume it is blocking anyways.

Do you have a reason to have this feature non-blocking?

I think I agree, only completions will get changed.
But I think blocking for a fzf menu feels appropriate right?

@blindFS

blindFS commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Do you have a reason to have this feature non-blocking?

I don't follow, I mean I was suggesting to make more cases blocking.

I think I agree, only completions will get changed.

But I think blocking for a fzf menu feels appropriate right?

Yep, blocking for fzf feels appropriate, as well as blocking for LSP completion and commandline completes. I mean non-blocking probably works as expected, but the extra overhead brings nothing in those cases.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

All good then we are on the same page. I was jut making sure.

@blindFS

blindFS commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

All good then we are on the same page. I was jut making sure.

Oh, I thought all completion queries are handled in background before this.

@Juhan280

Copy link
Copy Markdown
Contributor

Is this PR intended for v0.115.0 release?

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Well if we merge it, i would first make sure that it really makes the async completions code path impossible. And i would keep it opt-out not opt in. But it depends on how important it still is for @blindFS

@blindFS

blindFS commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Well if we merge it, i would first make sure that it really makes the async completions code path impossible. And i would keep it opt-out not opt in. But it depends on how important it still is for @blindFS

I would like to see it merged, but still I'm not sure whether it runs in the background for nu-lsp and commandline complete.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Thats what i will check out before we merge it.
The idea is to skip the background paths wholesale.

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
kronberger-droid force-pushed the feat/background-completions-opt-out branch from e1cdee6 to d16f93f Compare August 14, 2026 15:30
@kronberger-droid
kronberger-droid marked this pull request as ready for review August 14, 2026 16:15
@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Should be fine to land from my side, the op-out will not spawn any background threads, but obviously the completion backend stays the same.
nu-lsp and commandline are still blocking from my knowledge, so thats nothing to worry about.

cache,
cache_env,
worker: None,
background: true,

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.

I think this makes completion queries of nu-lsp and commandline complete handled in background?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Neither of those go through NuCompleter at all, right?

nu-lsp builds a CompletionEngine in completion.rs and calls fetch_completions_at on it, same for commandline complete in commands/commandline/complete.rs.

The worker only ever gets spawned from ReedlineCompleter::complete, thus the background flag does never influence either of them.

@blindFS blindFS Aug 16, 2026 •

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.

I see, I didn't go through the source code in depth. Purely judging by the name, I thought for_repl covers all the reedline related stuff and with_cache is for the rest.

Now I wonder who else would call this with_cache function?

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.

@kronberger-droid any idea why we still need this with_cache?

@blindFS

blindFS commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Sad story, a new release is already launched...

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

Yeah sorry, piet was already finished with all the preparations when we were still discussing, and I did not want to stall the release on it.

I had not to much time this weekend to push it through before, my bad.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

But I am open helping you with finding an alternative config for the stuff you need.

@blindFS

blindFS commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Yeah sorry, piet was already finished with all the preparations when we were still discussing, and I did not want to stall the release on it.

I had not to much time this weekend to push it through before, my bad.

I'm not aware of the release schedule, otherwise I wouldn't hinder the merge.

Now, as it's released already, let's wait and see whether we still need this or not.

@philocalyst

philocalyst commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Well if we merge it, i would first make sure that it really makes the async completions code path impossible. And i would keep it opt-out not opt in. But it depends on how important it still is for @blindFS

This PR is still in the air, but I'm still confused on the reasoning here, keeping it opt-out erodes the formalization of completion behaviors that we worked on and merged? I thought this was purely a bridge for users migrating their own configurations.

@kronberger-droid

Copy link
Copy Markdown
Contributor Author

You opt-out of the background completion path. So its just an escape hatch.

@fdncred
fdncred merged commit 79690c5 into nushell:main Aug 22, 2026
17 checks passed
@github-actions github-actions Bot added this to the v0.116.0 milestone Aug 22, 2026
@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:other Noted in "Other changes" section labels Aug 22, 2026
@cptpiepmatz cptpiepmatz modified the milestones: v0.116.0, v0.115.1 Aug 22, 2026
@kronberger-droid
kronberger-droid deleted the feat/background-completions-opt-out branch September 14, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:other Noted in "Other changes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive commands like fzf in external completer closure dont work after the non-blocking completion change

6 participants