From ec88a52be2d271db1e8af74d8b9165f6ffd086d2 Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Apr 2026 00:53:12 +0000 Subject: [PATCH] fix: handle agent completed/cancelled statuses in job executor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The linux_patch_api agent returns "completed" as its terminal success status, but the worker only recognized "succeeded". This caused the worker to log "unexpected agent status — ignoring" every 60 seconds and never mark patch jobs as finished. Changes: - job_executor.rs: match "completed" alongside "succeeded" as terminal success status, mapping both to patch_job_hosts.status = succeeded - job_executor.rs: match "cancelled" as a terminal failure status, routing to handle_host_failure with appropriate error message - pm-agent-client types.rs: updated AgentJobStatus doc comment to list all valid agent statuses: queued, running, succeeded, completed, failed, cancelled --- crates/pm-agent-client/src/types.rs | 2 +- crates/pm-worker/src/job_executor.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/pm-agent-client/src/types.rs b/crates/pm-agent-client/src/types.rs index bce071e..efb3c76 100644 --- a/crates/pm-agent-client/src/types.rs +++ b/crates/pm-agent-client/src/types.rs @@ -184,7 +184,7 @@ pub struct ApplyPatchesResponse { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct AgentJobStatus { pub job_id: String, - /// Current status: `"running"`, `"succeeded"`, `"failed"`, or `"cancelled"`. + /// Current status: `"queued"`, `"running"`, `"succeeded"`, `"completed"`, `"failed"`, or `"cancelled"`. pub status: String, pub progress_percent: Option, pub output: Option, diff --git a/crates/pm-worker/src/job_executor.rs b/crates/pm-worker/src/job_executor.rs index a4bab57..192cc93 100644 --- a/crates/pm-worker/src/job_executor.rs +++ b/crates/pm-worker/src/job_executor.rs @@ -552,7 +552,7 @@ async fn poll_single_host(pool: PgPool, config: Arc, row: PatchJobHos }; match status.status.as_str() { - "succeeded" => { + "succeeded" | "completed" => { tracing::info!(pjh_id = %row.id, "poll_single_host: agent job succeeded"); if let Err(e) = sqlx::query( r#" @@ -587,6 +587,13 @@ async fn poll_single_host(pool: PgPool, config: Arc, row: PatchJobHos "poll_single_host: job still in progress" ); }, + "cancelled" => { + tracing::info!(pjh_id = %row.id, "poll_single_host: agent job cancelled"); + let err_msg = status + .error + .unwrap_or_else(|| "Agent job was cancelled".to_string()); + handle_host_failure(pool, row.id, err_msg).await; + }, other => { tracing::warn!( pjh_id = %row.id,