agentmux_launcher\host_pipe/
connection.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3//
4// CPD-2 — host_pipe connection state.
5//
6// Today the launcher's IPC server (`agentmux-launcher::ipc::server`)
7// owns the accept loop for the launcher pipe; the host's writer
8// half is handed to `HostPipe::set_writer` once the connecting
9// client registers as `ClientKind::Host`. There is no dedicated
10// accept loop in this module — the existing one in `ipc::server`
11// already covers both inbound (host → launcher Commands) and
12// outbound (launcher → host Events / Commands via `HostPipe`) on
13// the same pipe instance.
14//
15// This file is reserved for future expansion (connection-state
16// telemetry, reconnect-attempt counter for `--diag` surfacing, etc.)
17// per the SPEC §3.5 module layout. CPD-3+ may grow it; CPD-2 keeps
18// the surface minimal.
19
20#![allow(dead_code)]
21
22use std::time::Instant;
23
24/// Connection-state telemetry. Stashed inside `HostPipe`'s inner
25/// mutex (alongside the writer + pending buffer). Kept distinct so
26/// future `--diag host_pipe` surfaces have a clean snapshot point
27/// without reaching into private fields.
28#[derive(Debug, Clone, Copy, Default)]
29pub struct ConnectionTelemetry {
30    /// Total times a writer has been installed (set_writer calls).
31    /// Increments on every reconnect.
32    pub connect_count: u64,
33    /// Total times the writer has been cleared (disconnect signals).
34    pub disconnect_count: u64,
35    /// Total frames written successfully.
36    pub frames_written: u64,
37    /// Total frames buffered while disconnected.
38    pub frames_buffered: u64,
39    /// Total frames dropped (overflow + 30s timeout combined).
40    pub frames_dropped: u64,
41    /// Most recent `host_disconnected_at`, if any. Convenience copy
42    /// for telemetry surfaces; the authoritative value is on
43    /// `HostPipeInner`.
44    pub last_disconnect_at: Option<Instant>,
45}