MCPcopy Create free account
hub / github.com/AI45Lab/Code / register_session

Function register_session

core/src/agent_api/agent_sessions.rs:57–65  ·  view source on GitHub ↗

Register a freshly built session's close handle into the parent agent's registry. Called by `session_builder::build_agent_session` immediately after the handle is constructed. Uses `Weak` so the registry doesn't keep the handle alive; when the caller drops their `AgentSession`, the handle's `Arc` count goes to zero, the handle drops, and the `Weak` in the registry becomes dangling. Dead entries a

(agent: &Agent, handle: &Arc<SessionCloseHandle>)

Source from the content-addressed store, hash-verified

55/// dangling. Dead entries are pruned lazily on the next
56/// [`list_sessions`] / [`close_session`] access.
57pub(super) fn register_session(agent: &Agent, handle: &Arc<SessionCloseHandle>) {
58 let weak = Arc::downgrade(handle);
59 let id = handle.session_id.clone();
60 let mut sessions = agent
61 .sessions
62 .lock()
63 .unwrap_or_else(|poison| poison.into_inner());
64 sessions.insert(id, weak);
65}
66
67fn bail_if_agent_closed(agent: &Agent) -> Result<()> {
68 if agent.closed.load(std::sync::atomic::Ordering::Acquire) {

Callers 1

build_agent_sessionFunction · 0.85

Calls 2

cloneMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected