Skip to content

Commit c4be532

Browse files
committed
fix(session): clean up in-memory terminal runtime bindings on close
close_session only cleared live_sessions and DB session_bindings, but left session_runtime_bindings and terminal_runtime_bindings HashMaps populated along with terminal_runtimes entries. After page refresh, collect_workspace_session_runtime_bindings would still find these stale bindings, causing closed sessions to reappear. Now calls unbind_session_runtime_by_session to remove from both binding maps, and remove_terminal_runtime_registration to clean up the runtime registry, ensuring a clean teardown on session close.
1 parent 637c6a1 commit c4be532

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

apps/server/src/services/session_runtime.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ pub(crate) fn unbind_session_runtime_by_terminal(
108108
Ok(session_key)
109109
}
110110

111+
pub(crate) fn unbind_session_runtime_by_session(
112+
workspace_id: &str,
113+
session_id: &str,
114+
state: State<'_, AppState>,
115+
) -> Result<(), String> {
116+
let key = session_runtime_key(workspace_id, session_id);
117+
let terminal_id = state
118+
.session_runtime_bindings
119+
.lock()
120+
.map_err(|e| e.to_string())?
121+
.remove(&key);
122+
if let Some(tid) = terminal_id {
123+
state
124+
.terminal_runtime_bindings
125+
.lock()
126+
.map_err(|e| e.to_string())?
127+
.remove(&tid);
128+
}
129+
Ok(())
130+
}
131+
111132
pub(crate) fn session_runtime_binding_for_terminal(
112133
terminal_id: u64,
113134
state: State<'_, AppState>,

apps/server/src/services/workspace.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,19 @@ pub(crate) fn close_session<S: ToString>(
563563
let _ = stop_agent_runtime_without_status_update(&workspace_id, &session_id, state);
564564
let _ = forget_live_session(state, &workspace_id, &session_id);
565565
let _ = crate::services::supervisor::disable_supervisor_mode(&workspace_id, &session_id, state);
566-
remove_workspace_session_binding(state, &workspace_id, &session_id).map(|_| ())
566+
remove_workspace_session_binding(state, &workspace_id, &session_id).map(|_| ())?;
567+
let _ = crate::services::session_runtime::unbind_session_runtime_by_session(
568+
&workspace_id,
569+
&session_id,
570+
state,
571+
);
572+
let _ =
573+
crate::services::session_runtime::remove_terminal_runtime_registration(
574+
&workspace_id,
575+
&session_id,
576+
state,
577+
);
578+
Ok(())
567579
}
568580

569581
pub(crate) fn list_session_history(

0 commit comments

Comments
 (0)