impl Handler {
/// Keeps `stream_keyboard` explicit because it sits on relay RPC orchestration, where hardware failures must surface without stopping the server.
    /// Inputs are the typed parameters; output is the return value or side effect.
    async fn stream_keyboard_rpc(
        &self,
        req: Request<tonic::Streaming<KeyboardReport>>,
    ) -> Result<Response<ReceiverStream<Result<KeyboardReport, Status>>>, Status> {
        let rpc_id = runtime_support::next_stream_id();
        info!(rpc_id, "⌨️ stream_keyboard opened");
        let (tx, rx) = tokio::sync::mpsc::channel(32);
        let kb = self.kb.clone();
        let ms = self.ms.clone();
        let kb_path = hid_endpoint(0);
        let ms_path = hid_endpoint(1);
        let gadget = self.gadget.clone();
        let did_cycle = self.did_cycle.clone();
        let session_lease = self.capture_power.acquire_session().await;
        let report_delay = live_keyboard_report_delay();

        tokio::spawn(async move {
            let _session_lease = session_lease;
            let mut s = req.into_inner();
            while let Some(pkt) = s.next().await.transpose()? {
                if let Err(e) = runtime_support::write_hid_report(&kb, &kb_path, &pkt.data).await {
                    if e.raw_os_error() == Some(libc::EAGAIN) {
                        debug!(rpc_id, "⌨️  write would block (dropped)");
                    } else {
                        warn!(rpc_id, "⌨️  write failed: {e} (dropped)");
                        runtime_support::recover_hid_if_needed(
                            &e,
                            gadget.clone(),
                            kb.clone(),
                            ms.clone(),
                            kb_path.clone(),
                            ms_path.clone(),
                            did_cycle.clone(),
                        )
                        .await;
                    }
                }
                tx.send(Ok(pkt)).await.ok();
                if !report_delay.is_zero() {
                    tokio::time::sleep(report_delay).await;
                }
            }
            info!(rpc_id, "⌨️ stream_keyboard closed");
            Ok::<(), Status>(())
        });

        Ok(Response::new(ReceiverStream::new(rx)))
    }

    /// Keeps `stream_mouse` explicit because it sits on relay RPC orchestration, where hardware failures must surface without stopping the server.
    /// Inputs are the typed parameters; output is the return value or side effect.
    async fn stream_mouse_rpc(
        &self,
        req: Request<tonic::Streaming<MouseReport>>,
    ) -> Result<Response<ReceiverStream<Result<MouseReport, Status>>>, Status> {
        let rpc_id = runtime_support::next_stream_id();
        info!(rpc_id, "🖱️ stream_mouse opened");
        let (tx, rx) = tokio::sync::mpsc::channel(1024);
        let ms = self.ms.clone();
        let kb = self.kb.clone();
        let kb_path = hid_endpoint(0);
        let ms_path = hid_endpoint(1);
        let gadget = self.gadget.clone();
        let did_cycle = self.did_cycle.clone();
        let session_lease = self.capture_power.acquire_session().await;

        tokio::spawn(async move {
            let _session_lease = session_lease;
            let mut s = req.into_inner();
            while let Some(pkt) = s.next().await.transpose()? {
                if let Err(e) = runtime_support::write_hid_report(&ms, &ms_path, &pkt.data).await {
                    if e.raw_os_error() == Some(libc::EAGAIN) {
                        debug!(rpc_id, "🖱️  write would block (dropped)");
                    } else {
                        warn!(rpc_id, "🖱️  write failed: {e} (dropped)");
                        runtime_support::recover_hid_if_needed(
                            &e,
                            gadget.clone(),
                            kb.clone(),
                            ms.clone(),
                            kb_path.clone(),
                            ms_path.clone(),
                            did_cycle.clone(),
                        )
                        .await;
                    }
                }
                tx.send(Ok(pkt)).await.ok();
            }
            info!(rpc_id, "🖱️ stream_mouse closed");
            Ok::<(), Status>(())
        });

        Ok(Response::new(ReceiverStream::new(rx)))
    }
}
