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

@ -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)