Repository navigation
fix: refresh closed MCP connections before turns - #562
GraciousGazelles wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces MCP connection liveness probing and backoff logic to detect and replace closed MCP server connections during a turn. It adds is_closed and has_closed_connections checks across the MCP connection manager, runtime, and session, along with backoff state tracking in McpRefresh to avoid excessive reconnect attempts. The reviewer identified a logical issue in should_probe_liveness_at where the turn ID is updated even when the probe is skipped due to backoff, which prematurely consumes the probe attempt for that turn. A refactoring was suggested to only update the turn ID when a probe is actually allowed to run.
| fn should_probe_liveness_at(&self, turn_id: &str, now: Instant) -> bool { | ||
| let mut state = self | ||
| .liveness_probe | ||
| .lock() | ||
| .unwrap_or_else(std::sync::PoisonError::into_inner); | ||
| if state.last_turn_id.as_deref() == Some(turn_id) { | ||
| return false; | ||
| } | ||
| state.last_turn_id = Some(turn_id.to_string()); | ||
| !state | ||
| .retry_not_before | ||
| .is_some_and(|retry_not_before| now < retry_not_before) | ||
| } |
There was a problem hiding this comment.
Currently, should_probe_liveness_at updates state.last_turn_id even when it returns false due to backoff (now < retry_not_before). This "consumes" the turn's single probe attempt without actually performing any liveness check.
If a turn has multiple steps and the backoff expires mid-turn, subsequent steps will be blocked from probing because last_turn_id was already set.
By only updating last_turn_id when we actually decide to perform a probe (returning true), we allow a later step in the same turn to successfully probe once the backoff window has expired.
fn should_probe_liveness_at(&self, turn_id: &str, now: Instant) -> bool {
let mut state = self
.liveness_probe
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
if state.last_turn_id.as_deref() == Some(turn_id) {
return false;
}
if state
.retry_not_before
.is_some_and(|retry_not_before| now < retry_not_before)
{
return false;
}
state.last_turn_id = Some(turn_id.to_string());
true
}|
Addressed the unresolved liveness review in signed commit |
|
Temporarily reopening this same candidate to request fresh checks for the corrected head; no code is being discarded. |
|
Closed as superseded by #563. |
Current-base replacement for #554.
Refresh initialized MCP connections that have lost their transport before an ordinary turn publishes its provider catalogue. Probes are once per turn and use bounded exponential backoff after repeated closed results. Includes focused liveness and refresh-cleanup coverage.
Supersedes the stale-base PR only after this replacement is validated and merged.