fix: cancel active process on contest switch (#316)

## Problem

Switching contests while a run, interactive session, or stress test was
active left orphaned callbacks and terminal jobs alive. Running `:CP
run`
twice also let the first run's stale output overwrite the buffer.

## Solution

Replace the `io_view_running` bool in `views.lua` with a generation
counter so concurrent `run_io_view` calls self-cancel via stale-gen
checks in async callbacks. Add `cancel_io_view`, `cancel_interactive`,
and `stress.cancel` for forceful teardown, and call them in
`setup_contest` whenever `is_new_contest` is true.
This commit is contained in:
Barrett Ruth 2026-03-05 17:42:50 -05:00 committed by GitHub
parent 916c9174a6
commit 7e7e135681
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 18 deletions

View file

@ -232,4 +232,18 @@ function M.toggle(generator_cmd, brute_cmd)
end)
end
function M.cancel()
if state.stress_buf and vim.api.nvim_buf_is_valid(state.stress_buf) then
local job = vim.b[state.stress_buf].terminal_job_id
if job then
vim.fn.jobstop(job)
end
end
if state.saved_stress_session then
vim.fn.delete(state.saved_stress_session)
state.saved_stress_session = nil
end
state.set_active_panel(nil)
end
return M