Skip to main content

transition_worker_to_failed

Function transition_worker_to_failed 

Source
pub(crate) fn transition_worker_to_failed(
    workspace: &Arc<Workspace>,
    project_key: &ProjectKey,
    session_key: &SessionSlot,
    diagnostic: Option<String>,
)
Expand description

Shared transition: flip a worker’s status to Failed with a human-readable diagnostic, and emit WorkerStatusChanged { StatusChanged }. Called by the Connected-never-arrived paths (subprocess exit, ConnectionFailed event, resume rejected by claude when the fall-through-to-fresh path declines to retry).

Idempotent: when the entry is already Failed with an identical diagnostic, this is a no-op (no mutation, no event emission). A fresh diagnostic for an already-Failed entry DOES re-emit so the UI picks up the new reason text.

Also clears needs_tag because a Failed worker won’t be reached by the opportunistic tag-retry path - leaving the flag set keeps stale state on the entry the next time the worker resumes and transitions back to Running.

The diagnostic should be the first line of claude’s stderr (when available) or the error variant name. Keep it short - the Projects pane renders it as a one-row sub-line below the worker label, truncated to the row’s available width.