Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 64 additions & 25 deletions model_gateway/src/worker/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ async fn run_health_loop(
if matches!(
apply_probe_completion(&registry, completion, job_queue.as_ref()).await,
ProbeApplyResult::Applied(Some((_, WorkerStatus::Failed)))
) {
) && config.remove_unhealthy

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit: Keeping Failed workers on the schedule forever also makes the failure logging unbounded. remove_unhealthy defaults to service_discovery (resolve_worker_auto_recovery in config/types.rs:959), i.e. false for the static fleets this PR targets, so a worker that is genuinely gone for good (decommissioned host, retired port) now emits warn!("Health probe failed") here plus the transport-level warn! in http_health_check/grpc_health_check every check_interval_secs (default 60s) for the lifetime of the gateway. Previously the noise stopped once it reached Failed.

Worth demoting the probe-failure log to debug! when launched_status == WorkerStatus::Failed (the state is already reported via /workers and the health metric), so the recovery probe stays cheap and quiet.

{
// Removal is in flight; stop probing. Without removal the
// worker stays scheduled so a restart rejoins.
next_check.remove(&worker_id);
}
}
Expand Down Expand Up @@ -459,15 +462,16 @@ fn queue_due_probes(

let launched_status = worker.status();
let expected_revision = worker.revision();
if launched_status == WorkerStatus::Failed {
if launched_status == WorkerStatus::Failed && config.remove_unhealthy {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟣 Pre-existing: config.remove_unhealthy isn't sufficient to conclude "removal takes it from here" — submit_removal_job short-circuits on mesh-imported workers via should_remove_failed (line 795). So with --remove-unhealthy-workers on, a Failed mesh worker is dropped from next_check here (and at line 351) but no removal job is ever submitted: it stays registered, Failed, and permanently unprobed — exactly the "never rejoins" bug this PR fixes for local workers.

The doc comment on should_remove_failed even assumes probing continues ("the live CRDT key re-imports the worker on the next reconcile, probes fail again"), which can't happen once the worker leaves the schedule.

This predates the PR, but the PR is introducing the gate, so it's the natural place to make it match reality:

Suggested change
if launched_status == WorkerStatus::Failed && config.remove_unhealthy {
if launched_status == WorkerStatus::Failed
&& config.remove_unhealthy
&& should_remove_failed(registry, &worker_id)
{

The same predicate would apply at line 347 and line 659.

// Removal takes it from here. A Failed worker that is not being
// removed keeps its probe slot below, so an engine that comes back
// on the same address is noticed and promoted.
next_check.remove(&worker_id);
if config.remove_unhealthy {
removals.push(RemovalCandidate {
worker_id: worker_id.clone(),
url: worker.base_url().to_string(),
expected_revision,
});
}
removals.push(RemovalCandidate {
worker_id: worker_id.clone(),
url: worker.base_url().to_string(),
expected_revision,
});
continue;
}
if launched_status == WorkerStatus::Draining {
Expand Down Expand Up @@ -609,8 +613,9 @@ fn apply_connect_signal(
match registry.transition_status_if_revision(&worker_id, revision, WorkerStatus::Ready) {
Some((old, new)) => {
debug!(worker_url = %url, ?old, ?new, "Promoted worker on connect signal");
// A Failed worker was dropped from the schedule; a promoted one is
// serving traffic, so it must be probed again — otherwise a later
// A Failed worker may have been dropped from the schedule (removal
// enabled); a promoted one is serving traffic, so it must be probed
// again — otherwise a later
// engine death would leave it Ready with a dead client forever.
Comment on lines +616 to 619

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit: The rewrap left a stub line ("otherwise a later" / "engine death"). Reflow:

Suggested change
// A Failed worker may have been dropped from the schedule (removal
// enabled); a promoted one is serving traffic, so it must be probed
// again — otherwise a later
// engine death would leave it Ready with a dead client forever.
// A Failed worker may have been dropped from the schedule (removal
// enabled); a promoted one is serving traffic, so it must be probed
// again — otherwise a later engine death would leave it Ready with
// a dead client forever.

if let Some(worker) = registry.get(&worker_id) {
schedule_worker_at(
Expand Down Expand Up @@ -651,9 +656,11 @@ fn schedule_descriptor_at(
next_check.remove(&descriptor.worker_id);
return;
}
if descriptor.status == WorkerStatus::Failed {
// Startup reconcile and lagged rebuild must be side-effect-free:
// do not reschedule already-failed workers for probing or removal.
if descriptor.status == WorkerStatus::Failed && config.remove_unhealthy {
// Startup reconcile and lagged rebuild must be side-effect-free, and
// scheduling a Failed worker under removal would queue its removal.
// Without removal the probe is the only effect, and it is how a
// restarted engine rejoins.
next_check.remove(&descriptor.worker_id);
return;
}
Expand Down Expand Up @@ -702,7 +709,10 @@ fn schedule_worker_at(
/// - NotReady → Ready on `success_threshold` consecutive successes
/// - NotReady → Failed on `liveness_failure_threshold` (3 × failure_threshold)
/// - Ready → NotReady on `failure_threshold` consecutive failures
/// - Failed: terminal (handled outside this function — no transitions)
/// - Failed → Ready on `success_threshold` consecutive successes: the engine
/// came back on the same address (a restart), and without
/// `--remove-unhealthy-workers` this is the only way it rejoins
/// - Failed stays Failed on failure; Draining never transitions here
fn compute_next_status(
worker: &Arc<dyn Worker>,
probe_ok: bool,
Expand All @@ -723,7 +733,7 @@ fn compute_next_status(

if matches!(
current_status,
WorkerStatus::Pending | WorkerStatus::NotReady
WorkerStatus::Pending | WorkerStatus::NotReady | WorkerStatus::Failed
) && successes >= success_threshold
{
worker.consecutive_successes_reset();
Expand Down Expand Up @@ -767,9 +777,10 @@ fn compute_next_status(
}
}
WorkerStatus::Failed | WorkerStatus::Draining => {
// Terminal for the health-state machine. Failed is removed
// by `--remove-unhealthy-workers`; Draining is removed by
// the discovery drain timer once in-flight requests settle.
// Nowhere further down to go. Failed is removed by
// `--remove-unhealthy-workers` and otherwise stays probed so
// a restart is noticed; Draining is removed by the discovery
// drain timer once in-flight requests settle.
}
}

Expand Down Expand Up @@ -1644,17 +1655,22 @@ mod tests {
}

#[test]
fn test_state_machine_failed_is_terminal() {
fn test_state_machine_failed_recovers_after_success_threshold() {
let worker = make_worker("http://w:1", 2, 3);
worker.set_status(WorkerStatus::Failed);

// Successful probes don't recover Failed.
assert_eq!(compute_next_status(&worker, true, &cfg(2, 3)), None);
assert_eq!(compute_next_status(&worker, true, &cfg(2, 3)), None);
// Failures keep it Failed.
assert_eq!(compute_next_status(&worker, false, &cfg(2, 3)), None);
assert_eq!(worker.status(), WorkerStatus::Failed);

// Failed probes don't transition Failed anywhere either.
assert_eq!(compute_next_status(&worker, false, &cfg(2, 3)), None);
// The engine came back on the same address: success_threshold
// consecutive successes promote it exactly like NotReady, because a
// static fleet has no other way to rejoin.
assert_eq!(compute_next_status(&worker, true, &cfg(2, 3)), None);
assert_eq!(
compute_next_status(&worker, true, &cfg(2, 3)),
Some(WorkerStatus::Ready)
);
}

#[test]
Expand Down Expand Up @@ -1756,6 +1772,29 @@ mod tests {
);
}

#[test]
fn test_reconcile_from_registry_keeps_failed_workers_probed_without_removal() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Nit (test coverage): This test pins the schedule_descriptor_at branch, but the change that actually makes a restarted worker rejoin is in queue_due_probes (line 465) — and that function has its own independent Failed check, exercised by exactly one test (test_removal_candidate_strips_dp_rank_suffix, line 1713) which only runs with remove_unhealthy: true.

So the remove_unhealthy: false path through queue_due_probes is untested: someone could revert line 465 to the unconditional next_check.remove(&worker_id); continue; and the whole suite would still pass while the PD failover regression came straight back. Worth a sibling test that calls queue_due_probes on a Failed worker with remove_unhealthy: false and asserts removals.is_empty(), in_flight.contains(&id), and probes.len() == 1.

// Without --remove-unhealthy-workers a Failed worker is kept on the
// schedule: the probe is how a restart on the same address rejoins.
let registry = Arc::new(WorkerRegistry::new());
let failed_worker = make_worker("http://failed:1", 2, 3);
failed_worker.set_status(WorkerStatus::Failed);
let failed_id = registry.register(failed_worker).unwrap();
let mut next_check = HashMap::new();
reconcile_from_registry(
&registry,
&mut next_check,
&WorkerManagerConfig {
default_check_interval_secs: 5,
remove_unhealthy: false,
},
);
assert!(
next_check.contains_key(&failed_id),
"a failed worker that is not being removed must keep being probed"
);
}

#[test]
fn test_reconcile_from_registry_captures_pending_and_ready_workers() {
// Positive complement to the "skips failed" test: the startup
Expand Down
Loading