fix(runtime): cancel de background task immédiat et fiable depuis le workstate (#199, QA verte)
Transforme l'annulation d'une background task en contrat immédiat, observable et non-best-effort: - domain/background_task: états Cancelling/Cancelled/CancelFailed et transitions idempotentes; un kill PTY qui échoue est surfacé en CancelFailed plutôt qu'en succès silencieux. - infrastructure/runner + store: cancel effectif de la task ciblée, reconcile marque Cancelling même sans live handle, et départage CancelFailed des tâches pending au boot. - application/background + workstate + orchestrator/wake: chemin de cancel initié depuis le workstate, projection synchronisée de l'état (pas d'attente d'un cycle ambigu). - frontend: projection workstate de l'état cancelled/cancelling/cancelFailed (cancellingRow/cancelFailedRow/cancelButtons), normalization et services. Tests QA verts: background_task_cancel, background_task_runner cancel_wins_even_if_output_is_still_available, background_task_store reconcile_marks_cancelling_without_live_handle_cancel_failed_and_pending, workstate.test.tsx.
This commit is contained in:
@ -108,7 +108,8 @@ impl FsBackgroundTaskStore {
|
||||
/// Reconciles persisted tasks against live runtime handles at boot.
|
||||
///
|
||||
/// B2 rule: `Running`/`Waiting` tasks missing from `live_task_ids` are marked
|
||||
/// `Failed` with a synthetic restart-loss failure and become delivery-pending.
|
||||
/// `Failed`; `Cancelling` tasks missing from `live_task_ids` are marked
|
||||
/// `CancelFailed`. Both become delivery-pending.
|
||||
/// Already-terminal undelivered tasks are reported as delivery-pending. `Queued`
|
||||
/// tasks are left open.
|
||||
///
|
||||
@ -127,18 +128,13 @@ impl FsBackgroundTaskStore {
|
||||
for (project_id, doc) in &mut state.docs {
|
||||
for task in &mut doc.tasks {
|
||||
match task.state {
|
||||
BackgroundTaskState::Running | BackgroundTaskState::Waiting
|
||||
BackgroundTaskState::Running
|
||||
| BackgroundTaskState::Waiting
|
||||
| BackgroundTaskState::Cancelling
|
||||
if !live.contains(&task.id) =>
|
||||
{
|
||||
let finished_at_ms = now_ms.max(task.updated_at_ms);
|
||||
let result = BackgroundTaskResult::Failure {
|
||||
finished_at_ms,
|
||||
exit_code: None,
|
||||
error: "background task lost its runtime handle during IdeA restart"
|
||||
.into(),
|
||||
stdout_tail: None,
|
||||
stderr_tail: None,
|
||||
};
|
||||
let result = lost_runtime_result(task.state, finished_at_ms);
|
||||
*task = task.complete(result).map_err(invalid_task)?;
|
||||
report.failed_task_ids.push(task.id);
|
||||
report.delivery_pending_task_ids.push(task.id);
|
||||
@ -158,18 +154,13 @@ impl FsBackgroundTaskStore {
|
||||
for task in &mut doc.tasks {
|
||||
if matches!(
|
||||
task.state,
|
||||
BackgroundTaskState::Running | BackgroundTaskState::Waiting
|
||||
BackgroundTaskState::Running
|
||||
| BackgroundTaskState::Waiting
|
||||
| BackgroundTaskState::Cancelling
|
||||
) && !live.contains(&task.id)
|
||||
{
|
||||
let finished_at_ms = now_ms.max(task.updated_at_ms);
|
||||
let result = BackgroundTaskResult::Failure {
|
||||
finished_at_ms,
|
||||
exit_code: None,
|
||||
error: "background task lost its runtime handle during IdeA restart"
|
||||
.into(),
|
||||
stdout_tail: None,
|
||||
stderr_tail: None,
|
||||
};
|
||||
let result = lost_runtime_result(task.state, finished_at_ms);
|
||||
*task = task.complete(result).map_err(invalid_task)?;
|
||||
}
|
||||
}
|
||||
@ -444,3 +435,21 @@ fn io_error(error: std::io::Error) -> BackgroundTaskPortError {
|
||||
fn invalid_task(error: domain::BackgroundTaskError) -> BackgroundTaskPortError {
|
||||
BackgroundTaskPortError::Invalid(error.to_string())
|
||||
}
|
||||
|
||||
fn lost_runtime_result(state: BackgroundTaskState, finished_at_ms: u64) -> BackgroundTaskResult {
|
||||
if state == BackgroundTaskState::Cancelling {
|
||||
BackgroundTaskResult::CancelFailed {
|
||||
finished_at_ms,
|
||||
error: "background task cancellation lost its runtime handle during IdeA restart"
|
||||
.into(),
|
||||
}
|
||||
} else {
|
||||
BackgroundTaskResult::Failure {
|
||||
finished_at_ms,
|
||||
exit_code: None,
|
||||
error: "background task lost its runtime handle during IdeA restart".into(),
|
||||
stdout_tail: None,
|
||||
stderr_tail: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user