neotest icon indicating copy to clipboard operation
neotest copied to clipboard

[Question] Subprocess with `--clean` flag

Open KostkaBrukowa opened this issue 1 year ago • 7 comments

Hey! I've been seeing small issue with session in nvim. Whenever I was opening neotest summary window, the session wasn't saved (it worked normally when neotest summary wasn't opened at all). I've done some digging into the code and here: https://github.com/nvim-neotest/neotest/blob/master/lua/neotest/lib/subprocess.lua#L41 I've stumbled upon this line, when you open new headless nvim instance and I found out, that if I add flag --clean:

  local cmd = { vim.loop.exepath(), "--embed", "--headless", "-n", "--clean" }

my problem disappears (the headless instance might have been overriding my session) and the neotest summary window also loads a bit faster. I was wondering if there are any possible problems of using --clean flag and why didn't you use it in the first place?

KostkaBrukowa avatar Jul 03 '24 08:07 KostkaBrukowa

I'm a contributor on auto-session and had this same issue reported to me: https://github.com/rmagatti/auto-session/issues/451#issuecomment-3091342442

Are there any thoughts on starting the subprocess --clean? If not the default, then as a configurable option?

I'll also look into not saving a session if vim.env.NVIM is set.

cameronr avatar Jul 19 '25 01:07 cameronr

Can you check the log file to see if there are errors? There'll probably be a Failed to initialize child process Vim:Invoking 'nvim_exec_lua' on channel X message

I think this "fixes" the issue by the subprocess not working which neotest handles gracefully by running everything in the main process. If that's the case, I think just adding an option to disable the subprocess would be best

rcarriga avatar Jul 19 '25 10:07 rcarriga

No errors in the neotest log file:

INFO | 2025-07-19T07:16:07Z-0700 | ...ocal/share/nvim/lazy/neotest/lua/neotest/config/init.lua:469 | Configuration complete
INFO | 2025-07-19T07:16:09Z-0700 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:33 | Starting child process
INFO | 2025-07-19T07:16:09Z-0700 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:36 | Parent address: localhost:65213
INFO | 2025-07-19T07:16:09Z-0700 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:42 | Starting child process with command: /opt/homebrew/Cellar/neovim/0.11.3/bin/nvim --embed --headless -n
INFO | 2025-07-19T07:16:09Z-0700 | ...ocal/share/nvim/lazy/neotest/lua/neotest/config/init.lua:469 | Configuration complete
INFO | 2025-07-19T07:16:09Z-0700 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:86 | CHILD | Connected to parent instance
INFO | 2025-07-19T07:16:09Z-0700 | ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:378 | Initialising client
INFO | 2025-07-19T07:16:09Z-0700 | ...are/nvim/lazy/neotest/lua/neotest/client/events/init.lua:48 | Emitting starting event
INFO | 2025-07-19T07:16:09Z-0700 | ...al/share/nvim/lazy/neotest/lua/neotest/adapters/init.lua:18 | Found 0 adapters for directory /Users/cam/tmp/a
INFO | 2025-07-19T07:16:09Z-0700 | ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:507 | Initialisation finished in 0 seconds
INFO | 2025-07-19T07:16:09Z-0700 | ...are/nvim/lazy/neotest/lua/neotest/client/events/init.lua:48 | Emitting started event
INFO | 2025-07-19T07:16:10Z-0700 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:20 | Closing child channel
INFO | 2025-07-19T07:16:10Z-0700 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:46 | Child process exited

I also added some test code to add the pid to the filename and verified that two different processes were trying to write a session for the same cwd.

Not auto-saving when vim.env.NVIM is set fixes the issue but I wonder if there are circumstances where we might still want to do that (remote nvim?)

cameronr avatar Jul 19 '25 14:07 cameronr

Please try with the latest commit, it should work now 😄

rcarriga avatar Jul 20 '25 10:07 rcarriga

All of my testing was done with https://github.com/nvim-neotest/neotest/commit/3c81345c28cd639fcc02843ed3653be462f47024 and that looks like the latest change on master?

cameronr avatar Jul 21 '25 01:07 cameronr

Apologies, my push failed and I was in a rush 🤦 Try now

rcarriga avatar Aug 08 '25 06:08 rcarriga

Confirmed that it's working now with ce17830. Thanks for the follow up!

cameronr avatar Aug 09 '25 04:08 cameronr