Description
While fixing #6118 (OAuth-transport MCP servers silently exempted from the lock_tool_list hardening), the adversarial critic and code reviewer independently identified two pre-existing, non-blocking gaps in tool_list_locked cleanup that are now reachable for OAuth server IDs too (previously only reachable via non-OAuth paths, where they already existed unnoticed).
Both are fail-closed and benign (a stale entry only rejects refresh notifications for an id with no live connection — a bounded memory leak across many add/remove cycles of distinct ids, not a security regression), so they were not blocking for #6118 and are filed here as a separate follow-up.
F1: remove_server / shutdown_all_shared never clean tool_list_locked
crates/zeph-mcp/src/manager/server.rs:319-324 (remove_server) and :399-402 (shutdown_all_shared) clear server_tools, server_trust, server_fingerprints, last_refresh, and connected_server_ids — but not tool_list_locked. A server connected under lock_tool_list = true and later removed leaves an orphaned entry in the map.
F2: probe-block cleanup asymmetry in handle_connect_result
The add_server path removes the lock on probe-block (server.rs:210, probe_or_cleanup), but the connect_all/connect_oauth_deferred path's handle_connect_result (crates/zeph-mcp/src/manager/connect.rs:627-630) returns fail() on probe-block without removing the lock — asymmetric with the add_server probe path.
Expected Behavior
tool_list_locked entries are released on server removal, manager shutdown, and probe-block regardless of which connection path (add_server vs. connect_all/OAuth-deferred) established them — centralizing cleanup so all four sites (remove_server, shutdown_all_shared, handle_connect_result probe-block, add_server probe-block) stay in sync.
Actual Behavior
tool_list_locked entries can be orphaned (F1) or left stale after a probe-block on the connect_all/OAuth-deferred path (F2), while the add_server path already cleans up correctly in the equivalent case.
Environment
Logs / Evidence
Description
While fixing #6118 (OAuth-transport MCP servers silently exempted from the
lock_tool_listhardening), the adversarial critic and code reviewer independently identified two pre-existing, non-blocking gaps intool_list_lockedcleanup that are now reachable for OAuth server IDs too (previously only reachable via non-OAuth paths, where they already existed unnoticed).Both are fail-closed and benign (a stale entry only rejects refresh notifications for an id with no live connection — a bounded memory leak across many add/remove cycles of distinct ids, not a security regression), so they were not blocking for #6118 and are filed here as a separate follow-up.
F1:
remove_server/shutdown_all_sharednever cleantool_list_lockedcrates/zeph-mcp/src/manager/server.rs:319-324(remove_server) and:399-402(shutdown_all_shared) clearserver_tools,server_trust,server_fingerprints,last_refresh, andconnected_server_ids— but nottool_list_locked. A server connected underlock_tool_list = trueand later removed leaves an orphaned entry in the map.F2: probe-block cleanup asymmetry in
handle_connect_resultThe add_server path removes the lock on probe-block (
server.rs:210,probe_or_cleanup), but theconnect_all/connect_oauth_deferredpath'shandle_connect_result(crates/zeph-mcp/src/manager/connect.rs:627-630) returnsfail()on probe-block without removing the lock — asymmetric with the add_server probe path.Expected Behavior
tool_list_lockedentries are released on server removal, manager shutdown, and probe-block regardless of which connection path (add_server vs. connect_all/OAuth-deferred) established them — centralizing cleanup so all four sites (remove_server,shutdown_all_shared,handle_connect_resultprobe-block, add_server probe-block) stay in sync.Actual Behavior
tool_list_lockedentries can be orphaned (F1) or left stale after a probe-block on the connect_all/OAuth-deferred path (F2), while the add_server path already cleans up correctly in the equivalent case.Environment
Logs / Evidence
crates/zeph-mcp/src/manager/server.rs:319-324(remove_server, missingtool_list_lockedcleanup)crates/zeph-mcp/src/manager/server.rs:399-402(shutdown_all_shared, missingtool_list_lockedcleanup)crates/zeph-mcp/src/manager/server.rs:210(probe_or_cleanup, correct cleanup reference)crates/zeph-mcp/src/manager/connect.rs:627-630(handle_connect_resultprobe-block branch, missing cleanup)