Skip to content

Issue #1854: Quit Anyway waits for the tasks to stop behind a modal card - #1855

Merged
emmertex merged 2 commits into
emmertex:stagingfrom
clydecbrown:classic/feat/quit-anyway-drain
Dec 3, 2026
Merged

emmertex merged 2 commits into
emmertex:stagingfrom
clydecbrown:classic/feat/quit-anyway-drain

Conversation

@clydecbrown

Copy link
Copy Markdown
Collaborator

Fixes #1854

Problem

Quit Anyway (the "tasks are still running" prompt) set each task's cancel flag and closed the window at once. Nothing waited for the tasks to stop, so a task slow to honour its cancel could still be writing when the library closed. The prompt had no waiting state, and nothing refused control-channel, CLI or MIDI input, or dropped files, while the app shut down.

Change

  • crates/engine/src/activity.rs: Activity::stopping() lists tasks that were cancelled but are still on the stack; the named constants QUIT_DRAIN (5 s), QUIT_SPINNER_AFTER (0.5 s) and PLUGIN_QUIT_WINDOW (2 s).
  • crates/ui-egui/src/panels/notices.rs: Quit Anyway starts a drain only when a cancelled task is still listed; otherwise it closes at once as before. During the drain the card names what is stopping, shows a spinner after 0.5 s, and the prompt takes every click and key (keyboard::answer_waiting). The drain ends when the tasks have stopped or the 5 s timer runs out; the log names each task still running. A task started during the wait is asked to stop too, and does not raise the tasks question again (unsaved-changes and backup questions still come first).
  • crates/ui-egui/src/lib.rs: control requests get "the app is shutting down", and MIDI and file drops are ignored, while the drain runs; a second close request is refused without restarting the wait. A watchdog thread ends the process if the frame loop cannot (a minimised or occluded window draws no frames): at the timer it wakes the UI, a grace period later it logs what is left and exits. The drain clock is egui's, because Instant::now panics on wasm; the thread is compiled out on wasm.
  • crates/ui-egui/src/headless.rs: the test harness can send a host close request and records CancelClose.
  • Strings Waiting for {names} to stop… in all 17 -formats.json catalogs; docs/background-tasks.md; release notes.

Not in this PR: PLUGIN_QUIT_WINDOW is defined and ordered against the app timer by a test, but nothing applies it, because the app has no plug-in shutdown to govern yet (AC-6 cancelled). The watchdog's exit skips the usual save on exit (settings, window, the due backup, closing the library); it is the last resort for a UI that draws no frames. A Dock or system quit still bypasses the quit prompt altogether. No test sends a pointer click through the card or a MIDI message during the wait.

Acceptance criteria

  • AC-1: with no running task, Quit Anyway closes the window at once, as now. — quit_anyway_with_nothing_left_running_closes_at_once
  • AC-2: with a running task, Quit Anyway enters the draining state; input, CLI and control requests get a "shutting down" refusal. — the_wait_shows_a_spinner_after_half_a_second_and_refuses_input, the_wait_ignores_dropped_files_and_holds_the_native_menu_back (seen failing with the control gate off and with the drop gate off; MIDI is gated too but not tested)
  • AC-3: a wait longer than 0.5 s shows a spinner, naming what is still stopping. — the_spinner_joins_the_card_at_half_a_second (seen failing with the threshold always off and always on)
  • AC-4: the quit prompt takes all pointer and keyboard input and nothing beneath it reacts. — the prompt counts as a modal; Esc and the native menu are tested; no test clicks through the card
  • AC-5: during the drain the window redraws and answers the OS, and a second OS quit does not restart the wait. — the_window_answers_the_os_during_the_wait (seen failing with the refusal in may_close removed)
  • AC-6: each plug-in's shutdown window is shorter than the app's timer. (cancelled: the constants exist and a test orders them, but there is no plug-in shutdown for the window to govern yet)
  • AC-7: when the app's timer ends the drain, the process exits and the log names each cancelled task still running. — crates/ui-egui/tests/quit_drain_log.rs (seen failing with the log line removed); the exit is the_watchdog_really_ends_the_process
  • AC-8: a test per state (no task; a task that stops in time; a task that does not stop before the timer). — quit_anyway_with_nothing_left_running_closes_at_once, quit_anyway_waits_for_a_task_that_stops_in_time, quit_anyway_ends_when_the_timer_runs_out_and_the_log_names_the_task
  • AC-9: after Quit Anyway, Esc does nothing. — the Esc check in the_wait_shows_a_spinner_after_half_a_second_and_refuses_input (seen failing with the modal flag removed)
  • AC-10: a watchdog thread ends a drain the frame loop cannot, and a drain that finishes normally stops it. — the_watchdog_ends_the_process_when_the_frame_loop_cannot, the_watchdog_wakes_the_ui_at_the_timer_before_it_ends_anything, a_drain_that_ends_normally_stops_the_watchdog, the_watchdog_really_ends_the_process (a child process, the real process::exit)
  • AC-11: a task started during the wait is asked to stop when the drain ends and does not raise the tasks question again. — a_task_started_during_the_wait_does_not_raise_the_tasks_question_again (seen failing without the answered flag and without the cancel_all())
  • AC-12: the watchdog stands down as soon as the frame loop ends the drain. — a_drain_the_frame_loop_has_ended_stops_the_watchdog_while_it_still_saves (seen failing without the finish() call)

How it was checked

  • cargo xtask ci --quick, cargo xtask sil and cargo test -p for the touched crates pass on this branch, up to
    date with staging (merged in, not rebased)
    • The gate passed on this content (fmt, ci --quick, parity, layers, assets, deny, wasm, android); the branch is behind staging by 7 commits on other files and merges cleanly.
  • A test that fails without this change: the tests above, each seen failing with its behaviour removed (the feature's tests call API this change adds)
  • User-visible change: ran the app and looked at the result

Merging

  • Overlap: none found.
  • Existing edits and libraries: unchanged.
  • Shared numbers taken: none.
  • Where it came from: own design.
  • New dependencies, unsafe, build scripts, network access, spawned processes, deleted files, CI or xtask gate changes: a new background thread (the watchdog) and one test that re-runs the test binary as a child process; no dependencies, unsafe, build scripts or network access (see Runs on CI).

Manual: none, the quit prompt has no manual page.

Runs on CI

In the diff, only the touched crates' own tests run on the runners. Two things to know: the watchdog thread (native only, ends the process after the timer plus a grace period) and the_watchdog_really_ends_the_process, which starts the test binary itself (Command::new on current_exe, filtered to that one test) and checks that it ends within seconds; the child's only effect is to exit. No workflow, build-script, packaging or dependency changes, no network, and no files written outside a temp folder.

Checklist

  • No new panic path in non-test code: no unwrap / expect / panic!, no indexing or unchecked arithmetic on a
    number from a file, a person or an agent (get, checked_mul, NaN and char boundaries handled)
  • New text on screen goes through tr() and has its key in crates/ui-egui/locales/*.json; a new shortcut is
    free in docs/library-shortcuts.md
  • New code has a caller: no command, module or setting that nothing reaches yet
  • Ready to merge (otherwise open it as a draft)

🤖 Generated with Claude Code

clydecbrown and others added 2 commits December 2, 2026 16:51
… card

Quit Anyway used to set each task's cancel flag and close the window at once,
so a task slow to stop could still be writing when the library closed.

When a cancelled task is still listed, the prompt now turns into a wait: a
modal card names what is stopping, shows a spinner after 0.5 s, and refuses
control, MIDI, file-drop and keyboard input until the tasks have ended or the
app's 5 s timer runs out (the log names what was still running). The window
keeps answering the OS, and a second quit request does not restart the wait.
A watchdog thread ends the process if the frame loop cannot (a minimised
window draws no frames). A task started during the wait is asked to stop too
and does not raise the tasks question again.

Manual: none, no user-visible change beyond the quit prompt, which has no manual page.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@emmertex
emmertex enabled auto-merge December 3, 2026 01:02

@emmertex emmertex left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — careful design (drain gated on stopping(), watchdog stands down via finish() before the saves, wasm-safe clock), behaviour-level tests for each state, all 17 locales filled, release notes present. Updated the branch with staging and enabled auto-merge.

Non-blocking nits:

  • Manual: docs/manual-site/src/content/docs/platforms/performance.mdx:42 already says "Quitting asks first while a stoppable task is running." — a follow-up sentence there about Quit Anyway waiting up to 5 s (spinner after 0.5 s) would keep the manual in step.
  • LCC_QUIT_WATCHDOG_CHILD (test only) could use the CHROMAFORGE_ prefix for consistency with the env-var convention.

@emmertex
emmertex merged commit fe24c0e into emmertex:staging Dec 3, 2026
3 checks passed
@clydecbrown
clydecbrown deleted the classic/feat/quit-anyway-drain branch December 3, 2026 01:19
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.

Quit Anyway drains cleanly: input is blocked, a spinner shows during a longer wait, and each plug-in gets a shorter time than the app

2 participants