cosca 0.7.0

Unified cross-platform subprocess management: spawning, stdio, process trees, stable identity, and elevation.
Documentation
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
//! The macOS fd-marker's EOF edge: the event that fires when the last holder of the marker's
//! write end exits.
//!
//! Every member of the tree inherits the write end (`fdmarker`); the supervisor keeps the read
//! end. The kernel closes descriptors on process exit unconditionally, so the edge needs no
//! cooperation from the tree, no bookkeeping from the supervisor, and — unlike ppid
//! enumeration — it covers members reparented to launchd.
//!
//! Two limits, both structural rather than incidental:
//!
//! - **Exited, not reaped.** A descriptor closes before the zombie is collected, so the edge
//!   says every member has *exited*; it says nothing about statuses. A caller wanting a
//!   status still waits on the root.
//! - **A member that `close()`s the descriptor leaves the set.** The edge is exactly as
//!   trustworthy as the marker's membership: it can fire while such a member still runs.
//!   That is the same trust model as the marker itself — naive-child containment.
//!
//! Every knote here is armed with `NOTE_LOWAT`, a high low-water mark, and `EV_CLEAR` (arm once
//! per genuinely new edge, not once per `kevent` call while the condition merely holds).
//! `EV_EOF` is always the sole verdict, unconditional of buffered bytes — but the low-water
//! mark itself is clamped by the kernel to the pipe's actual buffer capacity (measured ~64 KiB
//! on this host), so it suppresses wakeups for ordinary writes (which is all the crate should
//! ever produce — nothing in the crate writes to the marker) without being an absolute
//! guarantee against a member that sustains output at or above that ceiling.
//!
//! That residual case is handled differently depending on whether the wait is bounded:
//!
//! - **Bounded** (a caller-supplied deadline): the excess is drained in bounded rounds, an
//!   accommodation for a misbehaving-but-eventually-cooperative writer, paid for by the
//!   caller's own deadline — CPU-proportional to the writer's throughput for the wait's
//!   duration, same as the drain itself. No round starts once the deadline has passed. The one
//!   non-blocking check at expiry looks for EOF only and drains nothing. The in-flight round
//!   may finish arbitrarily later (principle 13).
//! - **Unbounded** (no deadline at all): nothing is drained. The effective low-water clamp
//!   equals the pipe's full capacity, so the very edge that makes the knote ready is also the
//!   instant the writer's own `write()` call blocks in the kernel — the original design
//!   assumption this module's misuse contract already documents (see `fdmarker`'s module doc:
//!   a member that writes to its inherited marker descriptor "blocks once the kernel pipe
//!   buffer fills"). Not draining lets that self-limiting behavior stand: with `EV_CLEAR` set
//!   and no new bytes possible while the writer stays blocked, the wait genuinely blocks in the
//!   kernel — poll-free, not CPU-proportional — until the writer's descriptor closes (forcibly
//!   or otherwise) or, for the bounded callers layered on top of this primitive, a deadline is
//!   reached. An unbounded wait cannot honestly offer both zero CPU AND forward progress for a
//!   sustained writer at the same time (continuing to drain IS continuing to do work
//!   proportional to what the writer produces, for as long as the writer keeps producing it) —
//!   this module chooses zero CPU for the unbounded case, since that is also the case with no
//!   deadline to bound the alternative.
//!
//!   The verdict stays TRUE while that writer is blocked, which is why this is a cost and not a
//!   wrong answer: a member parked in `write()` is still alive and still holds a write end, so
//!   the tree really does still have a member and `MembersRemain` is what an honest observer
//!   reports. The blocked member is visible in the process table; the alternative trades that
//!   visibility for a supervisor quietly spending a third of a core (measured 23-37% against a
//!   writer sustaining ~1 GB/s) to carry a member that is already outside the marker's contract.

use std::os::fd::{AsRawFd, BorrowedFd};
use std::time::{Duration, Instant};

use crate::containment::TreeDrain;
use crate::error::Error;
use crate::os_process::macos::kqueue::{Event, Kqueue, Subscription, WaitOutcome};

#[cfg(test)]
#[path = "marker_eof_tests.rs"]
mod marker_eof_tests;

/// The `NOTE_LOWAT` low-water mark every knote in this module is armed with. Clamped by the
/// kernel to the pipe's actual buffer capacity — see the module doc for what this does and
/// does not guarantee.
const LOW_WATER_MARK: usize = 1 << 20; // 1 MiB (requested; effectively min(this, pipe capacity))

/// Make the read end non-blocking (idempotent). The read end belongs solely to the supervisor,
/// so the file-status flag is ours to set.
fn ensure_nonblocking(read_end: BorrowedFd<'_>) -> Result<(), Error> {
    let flags = rustix::fs::fcntl_getfl(read_end).map_err(|e| Error::Io(e.into()))?;
    if flags.contains(rustix::fs::OFlags::NONBLOCK) {
        return Ok(());
    }
    rustix::fs::fcntl_setfl(read_end, flags | rustix::fs::OFlags::NONBLOCK).map_err(|e| Error::Io(e.into()))
}

/// Read and discard up to `n` bytes, tolerating short reads. Bounded by `n` — a count the
/// KERNEL just reported via the triggering kevent's own `data` field, never "keep reading
/// until it stops." Below the low-water clamp this branch never runs at all; at or above it —
/// and only for a caller with an actual deadline, see `interpret_read_event` — this is what
/// keeps a single round bounded — the OUTER loop (`block_until_drained`, over
/// `os_process::macos::kqueue::Kqueue::wait`) is what keeps the total wait bounded by the caller's
/// deadline despite repeated rounds.
fn drain_pending(read_end: BorrowedFd<'_>, original_n: usize) -> Result<(), Error> {
    let mut n = original_n;
    let mut buf = [0u8; 4096];
    let result = loop {
        if n == 0 {
            break Ok(());
        }
        let want = n.min(buf.len());
        match nix::unistd::read(read_end, &mut buf[..want]) {
            Ok(0) => break Ok(()), // EOF raced ahead of us; nothing left to drain
            Ok(got) => n -= got,   // still nonzero next iteration if `got < want`
            Err(nix::errno::Errno::EINTR) => continue,
            Err(nix::errno::Errno::EAGAIN) => break Ok(()), // a concurrent reader won the race
            Err(e) => break Err(Error::Io(e.into())),
        }
    };
    // Recorded even on a partial drain (EOF/EAGAIN cut it short): `original_n - n` bytes were
    // consumed.
    #[cfg(test)]
    drain_test_hooks::record_drained((original_n - n) as u64);
    result
}

/// Test-only: a cumulative bytes-drained counter for proving a round drained nothing. Confined
/// to macOS builds only by virtue of this whole module being macOS-only — no separate
/// `cfg_attr` needed, unlike `wait::test_clock`'s helpers, which live in a cross-platform
/// module.
#[cfg(test)]
pub(crate) mod drain_test_hooks {
    use std::cell::Cell;

    thread_local! {
        static DRAINED_BYTES: Cell<u64> = const { Cell::new(0) };
    }

    /// Cumulative bytes drained on THIS thread so far — monotonically increasing, so comparing
    /// a baseline to the total after a wait concludes proves "nothing was drained since",
    /// immune to a writer refilling the pipe and masking a `FIONREAD`-only comparison.
    pub(crate) fn drained_bytes() -> u64 {
        DRAINED_BYTES.with(Cell::get)
    }

    pub(crate) fn record_drained(n: u64) {
        DRAINED_BYTES.with(|c| c.set(c.get() + n));
    }
}

/// Create a kqueue with `EVFILT_READ` armed on the marker read end, `NOTE_LOWAT`-gated (see
/// the module doc for what this does and does not guarantee) so ordinary writes never wake
/// it — only `EV_EOF` does.
///
/// One kqueue PER WAITER, deliberately: a knote is keyed on `(kqueue, fd, filter)`, so private
/// kqueues compose (two waiters both see the edge) where two registrations of the same
/// descriptor on one shared queue would take each other's place.
///
/// `unbounded_wait` says whether the caller intends to wait with no deadline — see
/// `refuse_if_write_end_held` for why that matters.
pub(crate) fn arm(read_end: BorrowedFd<'_>, unbounded_wait: bool) -> Result<Kqueue, Error> {
    ensure_nonblocking(read_end)?;
    refuse_if_write_end_held(read_end, unbounded_wait)?;
    let kq = Kqueue::new()?;
    let readable = Subscription::Readable {
        fd: read_end.as_raw_fd(),
        low_water: LOW_WATER_MARK,
    };
    kq.subscribe(readable)?;
    Ok(kq)
}

/// Interpret ONE readable event on the marker read end — the single definition shared by
/// the one-shot drain (`drain_kqueue`) and the blocking wait's loop body
/// (`block_until_drained`), so there is no hand-rolled twin to drift.
///
/// `Ok(Some(AllMembersExited))` = the read end `closed` — final, regardless of buffered bytes, so
/// no read happens in this branch. `Ok(None)` = readable without `EV_EOF`, which with
/// `NOTE_LOWAT` armed only happens once buffered bytes reach the clamp — i.e. the pipe is at
/// capacity, so a writer that keeps writing is, at that exact instant, already blocked in its
/// own `write()`. `suppress_drain` decides what happens next:
///
/// - **`false`** (a bounded wait with deadline funding left): the event's `bytes` are
///   discarded via `drain_pending`, in one round bounded by the count the kernel itself
///   reported — the crate's accommodation for a misbehaving-but-eventually-cooperative writer,
///   paid for by the caller's own deadline.
/// - **`true`**: nothing is read; the event's `bytes` stay buffered. THREE call sites ask for
///   this, unified under one flag by principle 13, but with two different outcomes:
///   - `block_until_drained`, UNBOUNDED (no deadline exists to fund a drain): the wait
///     genuinely blocks in the kernel — the armed knote's `EV_CLEAR` (see `arm`) means no new
///     edge to refire on until the writer's OWN blocked `write()` unblocks (impossible while
///     the pipe stays full) or the descriptor closes (`EV_EOF`). See the module doc for why an
///     indefinite wait cannot honestly offer both zero CPU and forward progress for a sustained
///     writer, and why this crate chooses zero CPU plus the writer's own self-limiting contract
///     (`fdmarker`'s module doc) here.
///   - `block_until_drained`, BOUNDED with the deadline already elapsed when the events arrive:
///     it returns `MembersRemain` on THIS round's inconclusive `Ok(None)`, since there is no
///     deadline left to fund another round.
///   - `probe`, always: a zero-timeout check IS a check at expiry, the same one a bounded wait
///     performs on its own final round — see `probe`'s own doc.
///
/// `suppress_drain` does NOT have to equal whatever `unbounded_wait` the kqueue was armed with
/// (`arm`'s own, separate parameter, which governs `refuse_if_write_end_held`'s policy, not
/// draining) — `probe`'s caller arms bounded (an `Unassessable` write-end scan should still
/// proceed, capped by its own deadline) but always suppresses draining, per the three call
/// sites above.
///
/// `Err` = a read failure.
fn interpret_read_event(
    event: Event,
    read_end: BorrowedFd<'_>,
    suppress_drain: bool,
) -> Result<Option<TreeDrain>, Error> {
    let Event::Readable { bytes, closed, .. } = event else {
        debug_assert!(
            false,
            "the marker kqueue subscribes to the read end only, got {event:?}"
        );
        return Ok(None);
    };
    if closed {
        return Ok(Some(TreeDrain::AllMarkersClosed));
    }
    if !suppress_drain {
        drain_pending(read_end, bytes)?;
    }
    Ok(None) // holders remain (the read end is not closed)
}

/// The three outcomes of one non-blocking read of the events pending on an armed marker kqueue, kept
/// distinct rather than collapsed to `Option<TreeDrain>`: a caller that needs to know whether a
/// REAL, interpreted event occurred (a test proving a watch loop "saw readiness and declined to
/// drain", as opposed to a spurious wakeup with nothing pending at all) cannot tell those two
/// `None`-shaped cases apart otherwise. `drain_kqueue` has two production callers: `probe`, which
/// doesn't need the distinction and folds `Declined` and `Spurious` back together, and
/// `crate::tokio::wait`'s `wait_tree_drained_inner`, which DOES distinguish them — only
/// `Declined` fires its `#[cfg(test)]` seam. `block_until_drained` calls `interpret_events`
/// directly, over `Kqueue::wait`, never `drain_kqueue` itself.
#[derive(Debug)]
pub(crate) enum DrainOutcome {
    /// `EV_EOF` — a terminal verdict.
    Drained(TreeDrain),
    /// A genuine non-EOF event was retrieved and interpreted (at/past the low-water clamp) and
    /// did not resolve the wait; its bytes were discarded when `suppress_drain` is false and
    /// left buffered when true.
    Declined,
    /// Nothing was pending at all; `interpret_read_event` never ran.
    Spurious,
}

impl DrainOutcome {
    fn into_option(self) -> Option<TreeDrain> {
        match self {
            DrainOutcome::Drained(verdict) => Some(verdict),
            DrainOutcome::Declined | DrainOutcome::Spurious => None,
        }
    }
}

/// Interprets `events`, in order, until one is a verdict; the shared body of `drain_kqueue` and
/// `block_until_drained`. `suppress_drain` is `interpret_read_event`'s own parameter of the same
/// name, passed straight through.
fn interpret_events(
    events: Vec<Event>,
    read_end: BorrowedFd<'_>,
    suppress_drain: bool,
) -> Result<Option<TreeDrain>, Error> {
    for event in events {
        if let Some(verdict) = interpret_read_event(event, read_end, suppress_drain)? {
            return Ok(Some(verdict));
        }
    }
    Ok(None)
}

/// Takes every event pending on an armed kqueue through `Kqueue::poll`, without blocking, and
/// interprets them in order until one is a verdict. `suppress_drain` is `interpret_read_event`'s
/// own parameter of the same name, passed straight through — see that function's own doc for what
/// it means and why it need not equal `arm`'s `unbounded_wait`.
pub(crate) fn drain_kqueue(kq: &Kqueue, read_end: BorrowedFd<'_>, suppress_drain: bool) -> Result<DrainOutcome, Error> {
    let events = kq.poll()?;
    if events.is_empty() {
        return Ok(DrainOutcome::Spurious);
    }
    Ok(match interpret_events(events, read_end, suppress_drain)? {
        Some(verdict) => DrainOutcome::Drained(verdict),
        None => DrainOutcome::Declined,
    })
}

/// One-shot drain check: exact, not heuristic — arms a private kqueue and reads its
/// zero-timeout verdict off `EV_EOF`, the same signal `block_until_drained` uses (advisory, per
/// this module's `TreeDrain::AllMarkersClosed` — see that type's own doc). `drain_kqueue`
/// returning `DrainOutcome::Declined` or `DrainOutcome::Spurious` (nothing pending, or something
/// pending but not `EV_EOF`) both fold to `MembersRemain` here, correctly, since
/// `AllMarkersClosed` is only ever reported when the kernel itself said `EV_EOF`.
///
/// A zero-timeout check IS a check at expiry (principle 13) — see `interpret_read_event`'s doc
/// for why this always passes `suppress_drain = true` to `drain_kqueue` while still arming
/// bounded (`false` for `arm`'s separate `unbounded_wait`).
///
/// Called from `wait_tree_deadline`'s zero-duration case (`crate::tokio::wait`) — a one-shot
/// check never blocks, so it never risks a caller-invisible hang there. That caller lives
/// behind the crate's `tokio` feature, so this (and its own callee `drain_kqueue`) really is
/// unreachable without it — `#[allow(dead_code)]` reflects that honestly for a `tokio`-disabled
/// build instead of leaving the lib target to fail `cargo clippy --all-targets -D warnings`
/// there.
#[cfg_attr(
    not(feature = "tokio"),
    allow(dead_code, reason = "only caller is wait_tree_deadline behind the tokio feature")
)]
pub(crate) fn probe(read_end: BorrowedFd<'_>) -> Result<TreeDrain, Error> {
    let kq = arm(read_end, false)?;
    Ok(drain_kqueue(&kq, read_end, true)?
        .into_option()
        .unwrap_or(TreeDrain::MembersRemain))
}

/// Block until every marker holder has exited, or until `deadline`.
///
/// `deadline`: `None` = block indefinitely, `Some(at)` = an absolute deadline; a deadline
/// already in the past still performs exactly one non-blocking check before concluding — the
/// sticky, level-triggered `EV_EOF` a genuinely-already-drained tree left pending must be
/// observed, not assumed away by the elapsed deadline alone. No interval is chosen anywhere in
/// this path.
///
/// The per-round deadline-checking and `kevent` mechanics live in
/// `os_process::macos::kqueue::Kqueue::wait` (shared with the proc-exit watch); this function
/// supplies only the marker's own arm and per-event interpretation (`interpret_events`).
///
/// An unbounded wait (`None`) never drains bytes past the low-water clamp on a sustained
/// writer — see the module doc for why, and `interpret_read_event` for where that decision is
/// made. A bounded wait (`Some(_)`, including one already past) keeps draining as long as its
/// deadline has funding left. Whether it has is read AFTER `wait` returns the events, from a
/// fresh `remaining(deadline)`, never from a sample taken before the call, which may have blocked
/// across the deadline: events that arrive with the deadline elapsed stop draining too
/// (principle 13) — same `suppress_drain` flag, just also true for that reason.
pub(crate) fn block_until_drained(read_end: BorrowedFd<'_>, deadline: Option<Instant>) -> Result<TreeDrain, Error> {
    let unbounded_wait = crate::wait::remaining(deadline).is_none();
    let kq = arm(read_end, unbounded_wait)?;
    loop {
        let events = match kq.wait(deadline)? {
            WaitOutcome::Events(events) => events,
            WaitOutcome::DeadlinePassed => return Ok(TreeDrain::MembersRemain),
        };
        let elapsed = crate::wait::remaining(deadline) == Some(Duration::ZERO);
        if let Some(verdict) = interpret_events(events, read_end, unbounded_wait || elapsed)? {
            return Ok(verdict);
        }
        if elapsed {
            return Ok(TreeDrain::MembersRemain);
        }
    }
}

// Detecting a supervisor-retained write-end copy =====
//
// Reuses `fdmarker`'s own `PROC_PIDFDPIPEINFO` FFI surface (already `pub(crate)`) instead of
// declaring a second copy of the same struct layout.

use crate::containment::fdmarker::{fd_pipe_info, pipe_fds_of, FdPipeInfoQuery, PipeQuery};

/// Whether THIS process still holds a copy of the marker's write end.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum WriteEndCheck {
    /// No descriptor in this process refers to the marker's write end.
    Clear,
    /// The supervisor kept a copy — the edge can never fire.
    HeldByUs,
    /// The kernel would not describe our own descriptors, or `read_end` is not a pipe at all —
    /// the check is inconclusive.
    Unassessable,
}

/// Scan this process's own descriptors for a copy of the marker's write end.
///
/// Exact rather than heuristic: the read end's `pipe_peerhandle` IS the write end's
/// `pipe_handle`, so the comparison names one kernel object. Costs one `PROC_PIDLISTFDS` plus
/// one `proc_pidfdinfo` per pipe descriptor of this process, once per arm.
///
/// **Scope, stated honestly:** this catches a supervisor bug (its OWN retained copy) at the
/// instant of the scan. It is not a general liveness oracle for the write end: a foreign
/// process holding a copy is invisible to a self-scan by construction (mitigated instead by
/// the marker's parent-side descriptor not being inheritable), and a copy created in THIS
/// process after the scan (e.g. a `dup()` racing the caller) is a snapshot gap of the same
/// irreducible-window kind already documented at the `kill(2)` re-verify in
/// `check_or_signal` (`src/containment/unix/group.rs`) — checked-then-acted-on, not held under
/// a lock.
pub(crate) fn write_end_check(read_end: BorrowedFd<'_>) -> WriteEndCheck {
    let me = std::process::id();
    let write_handle = match fd_pipe_info(me, read_end.as_raw_fd()) {
        FdPipeInfoQuery::Found(info) => info.pipe_peerhandle,
        FdPipeInfoQuery::Absent | FdPipeInfoQuery::Denied => return WriteEndCheck::Unassessable,
    };
    let fds = match pipe_fds_of(me) {
        PipeQuery::Found(fds) => fds,
        PipeQuery::Gone | PipeQuery::Denied => return WriteEndCheck::Unassessable,
    };
    let mut any_probe_failed = false;
    for fd in fds {
        if fd == read_end.as_raw_fd() {
            continue; // the read end itself
        }
        match fd_pipe_info(me, fd) {
            FdPipeInfoQuery::Found(info) if info.pipe_handle == write_handle => return WriteEndCheck::HeldByUs,
            FdPipeInfoQuery::Found(_) => {}
            // `pipe_fds_of` just reported this exact fd as a pipe (moments ago), so this is
            // the routine "vanished between the two calls" case, not a probe failure.
            FdPipeInfoQuery::Absent => {}
            // A per-fd probe can fail transiently (the fd closed between listing and query).
            // Folded into Unassessable rather than silently treated as "not a match": the ONE
            // probe that would have found the retained copy is exactly the one that can fail
            // this way, and "exact rather than heuristic" (above) must not quietly degrade to
            // "exact except when it isn't."
            FdPipeInfoQuery::Denied => any_probe_failed = true,
        }
    }
    if any_probe_failed {
        return WriteEndCheck::Unassessable;
    }
    WriteEndCheck::Clear
}

/// Refuse to watch an edge that provably cannot fire. `Unassessable` proceeds UNLESS the
/// caller intends to wait with no deadline: an inconclusive scan combined with a bounded wait
/// is still bounded by the caller's own deadline (no new rounds after it), but combined with
/// an UNBOUNDED wait it is exactly the condition under which this primitive could hang forever
/// with no elevated runtime signal at all — so only that combination is refused.
fn refuse_if_write_end_held(read_end: BorrowedFd<'_>, unbounded_wait: bool) -> Result<(), Error> {
    match write_end_check(read_end) {
        WriteEndCheck::Clear => Ok(()),
        WriteEndCheck::Unassessable if !unbounded_wait => {
            log::debug!("marker EOF: could not confirm this process holds no copy of the marker write end");
            Ok(())
        }
        WriteEndCheck::Unassessable => {
            log::warn!(
                "marker EOF: could not confirm this process holds no copy of the marker write end, \
                 and the caller is waiting with no deadline - refusing rather than risking an \
                 unbounded hang"
            );
            Err(Error::Unassessable {
                detail: "could not confirm this process holds no copy of the containment marker's \
                         write end, and the wait has no deadline"
                    .into(),
                source: None,
            })
        }
        WriteEndCheck::HeldByUs => {
            // No debug_assert here: a deliberately-constructed HeldByUs condition must return
            // Err, not panic, so callers (including tests) can observe it.
            log::error!(
                "marker EOF: this process still holds a copy of the marker write end - the tree-drain \
                 edge can never fire. This is a cosca bug: the write end must be closed after spawn."
            );
            Err(Error::Containment {
                detail: "the supervisor still holds a copy of the containment marker's write end, so the \
                         tree-drain edge can never fire"
                    .into(),
            })
        }
    }
}