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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// githttp-fs
//
// Git-based Content Management System
// Copyright: 2026, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)
//! Startup healing of working trees that do not match HEAD.
//!
//! The working tree is a courtesy copy of HEAD kept on disk so a human can
//! `ls` a tenant repository (see `WorkingTree` in `git.rs`). Every ordinary
//! operation keeps it current *as it goes*: a write mirrors the file it
//! commits, a delete removes it, a replicated pack checks its repository out.
//! None of that is retroactive, which leaves exactly one gap — a repository
//! whose files were never written in the first place, or were written and
//! then left to drift:
//!
//! - a node that ran with `server.checkout_files = false` and now runs with it
//! on, including every tenant created while it was off,
//! - a replica whose store was filled before replication checked anything out,
//! and whose tenants will not be touched again until their master commits,
//! - a tenant left half-written by a process killed mid-operation.
//!
//! So this pass runs once per boot and checks every repository out to its
//! HEAD. A checkout converges from *any* prior state, which is what makes one
//! pass enough and makes the pass idempotent: on an already-correct store it
//! writes nothing, and it is reported as having healed nothing.
//!
//! **Startup is the only sane trigger.** Healing on read would mean writing to
//! disk from a read path — which would have to take the tenant write lock that
//! reads in this codebase deliberately never take, so one `GET` could block
//! behind a commit. Healing on write would make whichever request happens to
//! touch a long-disabled tenant first pay for checking out the whole of it
//! while holding that tenant's lock, and would never converge for the tenants
//! nobody writes to — which are precisely the ones an operator goes looking at
//! on disk. A boot pass is off every request path and bounded by the store.
//!
//! **It is opt-in** (`server.checkout_files_autoheal`, default `false`), which
//! is the one place this feature's two keys disagree on a default. Keeping
//! files on disk is what every deployment already did, so `checkout_files`
//! defaults to `true`; this pass never ran before, touches every repository in
//! the store, and *removes* files HEAD no longer names, so it waits to be
//! asked. Its cost is also the only part of the feature that scales with the
//! whole store rather than with one operation: roughly a `stat` per file per
//! boot even when nothing needs repairing.
//!
//! Leaving it off stops *only* this pass — mirroring as work arrives carries on
//! regardless — so healing a store that ran without `checkout_files` is a
//! deliberate two-step: enable this for one restart, then turn it back off.
use Instant;
use crateGitReplication;
use crateAppState;
use craterun_blocking;
/// Spawns the heal pass, or does nothing when this node is not keeping files
/// on disk (nothing to heal) or has not asked for it (`checkout_files_autoheal`,
/// off unless set).
///
/// Spawned rather than awaited: nothing waits on the working tree, so the
/// listener binds and serves while the pass runs behind it. Every route
/// answers from HEAD's tree, so a tenant whose turn has not come yet is
/// fully readable throughout.
/// Checks every repository this node holds out to its HEAD, one at a time.
///
/// Sequential on purpose: it is disk work nothing is waiting for, and running
/// it in parallel would turn a boot into an I/O storm on exactly the node an
/// operator just restarted. Each repository is mirrored under its own write
/// lock, so the pass can never run against a repository a write or a
/// replicated pack apply is in the middle of, nor against a maintenance pass.
async