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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Whether the in-project hygiene sweep runs, and the lane it runs in (#7965).
//!
//! Why a module of its own: the decision used to be fifteen lines inline in
//! `daemon/mod.rs`'s boot sequence — the env gate, the #5784 host-state refusal
//! and the `spawn_blocking` call — which is the shape that made it invisible.
//! `merged_pr_reclaim::spawn_if_enabled` already reads as one line at the call
//! site; this is the same split for the other sweep, and it is where the #7965
//! maintenance lane and the pass timing are applied so neither can be forgotten
//! by a future edit to the boot sequence.
//!
//! What: [`spawn_if_enabled`] reads [`ENV_ENABLED`], refuses a host state that
//! must not be swept, then takes the single background-maintenance permit
//! ([`crate::daemon::services::sweep_status::lane`]) before handing the
//! synchronous pass to the blocking pool. Holding the permit for the pass is what
//! stops this sweep and the worktree reclaim from running their subprocess loops
//! at the same time.
//!
//! Test: `parse_enabled_defaults_on_and_honours_the_off_switch`,
//! `spawn_if_enabled_is_a_noop_when_disabled` in
//! `inproject_hygiene_sweep_tests.rs`.
use Arc;
use ;
use cratesweep_status;
use crateDaemonState;
/// Environment variable that disables the in-project hygiene sweep entirely.
///
/// Why it stays a kill switch: #7965's mitigation on the reporting host was
/// exactly `TRUSTY_MPM_INPROJECT_HYGIENE=0`, and an operator must keep that lever
/// even after the sweep is bounded.
/// What: `0`/`false`/`off`/`no` (trimmed, case-insensitive) disables; anything
/// else, including unset, enables.
/// Test: `parse_enabled_defaults_on_and_honours_the_off_switch`.
pub const ENV_ENABLED: &str = "TRUSTY_MPM_INPROJECT_HYGIENE";
/// Pure parse of [`ENV_ENABLED`] into an on/off decision.
///
/// Why pure: env vars are process-global and ~20 tests in this binary write them,
/// so the policy is tested on a value rather than by mutating the process.
/// Test: `parse_enabled_defaults_on_and_honours_the_off_switch`.
pub
/// Whether the hygiene sweep should run at all.
///
/// Test: the policy is `parse_enabled_defaults_on_and_honours_the_off_switch`.
pub
/// Spawn the startup hygiene sweep unless an operator switched it off (#1709,
/// #7965).
///
/// Why `state` is taken but only its host-state gate used: the refusal is the
/// #5784 one — a daemon whose `$HOME` was reassigned must not fetch and
/// fast-forward the operator's real clones — and keeping the argument makes the
/// call site identical in shape to the reclaim sweep's.
/// What: gate, refuse, then `tokio::spawn` a task that acquires the single
/// maintenance permit and runs the synchronous pass on the blocking pool with a
/// [`sweep_status::HYGIENE`] timing guard. The task is detached: hygiene is
/// best-effort freshness and must never delay the listener coming up.
/// Test: `spawn_if_enabled_is_a_noop_when_disabled`.
pub