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>)
| 55 | /// dangling. Dead entries are pruned lazily on the next |
| 56 | /// [`list_sessions`] / [`close_session`] access. |
| 57 | pub(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 | |
| 67 | fn bail_if_agent_closed(agent: &Agent) -> Result<()> { |
| 68 | if agent.closed.load(std::sync::atomic::Ordering::Acquire) { |
no test coverage detected