Skip to content

Conversation

@pedropombeiro
Copy link

@pedropombeiro pedropombeiro commented Feb 9, 2026

Summary

When Neovim exits, the opencode --port process stays orphaned in memory instead of being terminated.

Root Cause

During VimLeavePre, snacks.terminal has already cleaned up its internal state, which invalidates the Neovim job. This means:

  • jobstop(job_id) returns true but doesn't actually terminate the process
  • jobpid(job_id) returns nil - Neovim no longer knows which PID the job maps to

Solution

Capture the PID (not just job ID) when the terminal opens, and use shell kill to terminate it directly during VimLeavePre. This bypasses Neovim's job tracking entirely.

Changes

  • snacks provider: Track _pid at toggle/start time using jobpid(terminal_job_id)
  • snacks provider: Use vim.fn.system('kill -TERM ' .. pid) in stop() for reliable termination
  • plugin/provider.lua: Change autocmd from VimLeave to VimLeavePre for earlier cleanup

Testing

  1. Start opencode via :Opencode
  2. Exit Neovim (:qa)
  3. Verify no orphaned processes: ps aux | grep "opencode --port" should return nothing

@nickjvandyke
Copy link
Owner

Thanks for taking a crack at this!

Is it possible to stop the job and all its children too? The child process (opencode) seems to stick around for me. Not sure if this is specific to fish.

image

@pedropombeiro pedropombeiro force-pushed the fix/terminate-job-on-stop branch from 9a5837e to d41da26 Compare February 9, 2026 23:02
@pedropombeiro pedropombeiro reopened this Feb 9, 2026
@pedropombeiro pedropombeiro force-pushed the fix/terminate-job-on-stop branch from d41da26 to f56624a Compare February 9, 2026 23:34
@pedropombeiro
Copy link
Author

Thanks for taking a crack at this!

Is it possible to stop the job and all its children too? The child process (opencode) seems to stick around for me. Not sure if this is specific to fish.

Can you try again with the latest version?

@pedropombeiro pedropombeiro force-pushed the fix/terminate-job-on-stop branch from f56624a to 733c590 Compare February 9, 2026 23:40
Track the terminal's PID at toggle/start time and use shell 'kill'
to terminate it during VimLeavePre. This is more reliable than
jobstop() because snacks.terminal cleanup can invalidate the job
before our stop() is called.
@pedropombeiro pedropombeiro force-pushed the fix/terminate-job-on-stop branch from 733c590 to ca9251c Compare February 9, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants