fix: cancel active process on contest switch

Problem: switching contests while a run, interactive session, or stress
test was in progress left orphaned callbacks and terminal jobs alive.
Running `:CP run` twice also allowed the first run's stale output to
overwrite the buffer after the second run completed.

Solution: replace the `io_view_running` bool in `views.lua` with a
generation counter (`_run_gen`); each `run_io_view` call increments it
and captures a local `gen`, and async callbacks bail out early when `gen
~= _run_gen`. Add `cancel_io_view`, `cancel_interactive` to `views.lua`
and `cancel` to `stress.lua` for forceful teardown without layout
restore. Call these in `setup_contest` whenever `is_new_contest` is true.
This commit is contained in:
Barrett Ruth 2026-03-05 17:37:13 -05:00
parent b3014e9c86
commit 9f23076420
3 changed files with 57 additions and 18 deletions

View file

@ -179,6 +179,19 @@ function M.setup_contest(platform, contest_id, problem_id, language)
local is_new_contest = old_platform ~= platform or old_contest_id ~= contest_id
if is_new_contest then
local views = require('cp.ui.views')
views.cancel_io_view()
local active = state.get_active_panel()
if active == 'interactive' then
views.cancel_interactive()
elseif active == 'stress' then
require('cp.stress').cancel()
elseif active == 'run' then
views.disable()
end
end
cache.load()
local function proceed(contest_data)