1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Whether this process is on its way down (#1462).
//!
//! A turn that ends carrying `AgentError::Cancelled` can mean two opposite
//! things, and the recovery ticket must be handled differently for each:
//!
//! * **The user stopped it** — Esc twice, `/stop`, `/discard`, a stop word.
//! They abandoned the work, so the tracking row is deleted and the turn is
//! never replayed.
//! * **The app is quitting under it** — Ctrl+C twice cancels the in-flight
//! token before setting `should_quit` (`tui/app/state.rs`). The user asked
//! for the process to end, not for the turn to be thrown away, so the row
//! must survive for the next boot to resume.
//!
//! `CancellationToken` carries no reason, so the shutdown paths raise this
//! flag before cancelling and the tool loop reads it when deciding whether to
//! delete the row. Process-global on purpose: it describes the process, and
//! the reader is several layers below the TUI that sets it.
//!
//! Not needed for `/restart`, `/exit`, `/quit` or `TuiEvent::Quit`: those end
//! the process without cancelling, so the row already survives. They set the
//! flag anyway, so the meaning stays "this process is going down" rather than
//! "one particular key combination was pressed".
use ;
static SHUTTING_DOWN: AtomicBool = new;
/// Mark the process as shutting down. Called before any shutdown path
/// cancels an in-flight turn.
pub
/// True once a shutdown has begun.
pub
/// Should this turn's recovery row survive?
///
/// Generic over the success type so the decision can be exercised directly
/// without building an `AgentResponse`. Only a cancellation that coincides
/// with a shutdown keeps the row: a user-initiated stop still deletes it, and
/// a turn that merely *finished* during a shutdown deletes it too, or the next
/// boot would replay work that was already answered.
pub
/// Test-only reset so cases cannot leak the flag into each other.
pub