MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / run_session_loop

Function run_session_loop

crates/openshell-server/src/supervisor_session.rs:713–760  ·  view source on GitHub ↗
(
    state: &Arc<ServerState>,
    sandbox_id: &str,
    session_id: &str,
    tx: &mpsc::Sender<GatewayMessage>,
    inbound: &mut tonic::Streaming<SupervisorMessage>,
    mut shutdown_rx: oneshot::

Source from the content-addressed store, hash-verified

711}
712
713async fn run_session_loop(
714 state: &Arc<ServerState>,
715 sandbox_id: &str,
716 session_id: &str,
717 tx: &mpsc::Sender<GatewayMessage>,
718 inbound: &mut tonic::Streaming<SupervisorMessage>,
719 mut shutdown_rx: oneshot::Receiver<()>,
720) {
721 let heartbeat_interval = Duration::from_secs(u64::from(HEARTBEAT_INTERVAL_SECS));
722 let mut heartbeat_timer = tokio::time::interval(heartbeat_interval);
723 // Skip the first immediate tick.
724 heartbeat_timer.tick().await;
725
726 loop {
727 tokio::select! {
728 _ = &mut shutdown_rx => {
729 info!(sandbox_id = %sandbox_id, session_id = %session_id, "supervisor session: superseded by reconnect, shutting down");
730 break;
731 }
732 msg = inbound.message() => {
733 match msg {
734 Ok(Some(msg)) => {
735 handle_supervisor_message(state, sandbox_id, session_id, msg);
736 }
737 Ok(None) => {
738 info!(sandbox_id = %sandbox_id, session_id = %session_id, "supervisor session: stream closed by supervisor");
739 break;
740 }
741 Err(e) => {
742 warn!(sandbox_id = %sandbox_id, session_id = %session_id, error = %e, "supervisor session: stream error");
743 break;
744 }
745 }
746 }
747 _ = heartbeat_timer.tick() => {
748 let hb = GatewayMessage {
749 payload: Some(gateway_message::Payload::Heartbeat(
750 openshell_core::proto::GatewayHeartbeat {},
751 )),
752 };
753 if tx.send(hb).await.is_err() {
754 info!(sandbox_id = %sandbox_id, session_id = %session_id, "supervisor session: outbound channel closed");
755 break;
756 }
757 }
758 }
759 }
760}
761
762fn handle_supervisor_message(
763 state: &Arc<ServerState>,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected