{"record":{"id":"271d90e64f1f447c","repo":"hashicorp/terraform","slug":"task-stage-s-s","errorCode":null,"errorMessage":"Task Stage '%s': %s.","messagePattern":"Task Stage '(.+?)': (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote/backend_taskStages.go","lineNumber":45,"sourceCode":"\t\toptions := tfe.TaskStageReadOptions{\n\t\t\tInclude: []tfe.TaskStageIncludeOpt{tfe.TaskStageTaskResults, tfe.PolicyEvaluationsTaskResults},\n\t\t}\n\t\tstage, err := b.client.TaskStages.Read(ctx.StopContext, stageID, &options)\n\t\tif err != nil {\n\t\t\treturn false, generalError(\"Failed to retrieve task stage\", err)\n\t\t}\n\n\t\tswitch stage.Status {\n\t\tcase tfe.TaskStagePending:\n\t\t\t// Waiting for it to start\n\t\t\treturn true, nil\n\t\tcase tfe.TaskStageRunning:\n\t\t\t// not a terminal status so we continue to poll\n\t\t\treturn true, nil\n\t\tcase tfe.TaskStagePassed:\n\t\t\treturn false, nil\n\t\tcase tfe.TaskStageCanceled, tfe.TaskStageErrored, tfe.TaskStageFailed:\n\t\t\treturn false, fmt.Errorf(\"Task Stage '%s': %s.\", stage.ID, stage.Status)\n\t\tcase tfe.TaskStageAwaitingOverride:\n\t\t\treturn false, fmt.Errorf(\"Task Stage '%s' awaiting override.\", stage.ID)\n\t\tcase tfe.TaskStageUnreachable:\n\t\t\treturn false, nil\n\t\tdefault:\n\t\t\treturn false, fmt.Errorf(\"Task stage '%s' has invalid status: %s\", stage.ID, stage.Status)\n\t\t}\n\t})\n}\n","sourceCodeStart":27,"sourceCodeEnd":55,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote/backend_taskStages.go#L27-L55","documentation":"Emitted by waitTaskStage (backend_taskStages.go:44-45) when a polled TaskStage reaches a terminal failure status — Canceled, Errored, or Failed. Task stages represent run tasks (Sentinel policy evaluations, custom run tasks) attached to a run stage; this error reports the stage ID and the failing status so the caller knows the run was blocked by a task that did not pass.","triggerScenarios":"A run task attached to the plan/apply stage fails: a Sentinel policy set enforces a hard failure, a custom task returns an error, or the task execution is canceled (e.g. by an admin or a timeout). The polling loop in waitTaskStage observes the status and returns this error.","commonSituations":"Sentinel policy enforcement rejecting the plan (e.g. forbid specific resource types/regions); a custom run-task endpoint returning an error; task runner infrastructure issue causing Errored status; admin canceled the task stage.","solutions":["Open the run in the TFC/TFE UI and inspect the task results to see the exact policy/task failure reason.","Fix the configuration so it satisfies the policy (e.g. approved region, required tags), then re-run.","If the policy is configured as advisory/overridable and the failure is Canceled/Errored (not Failed), check task-runner health and retry.","Coordinate with the workspace admin to adjust policy enforcement only if the rejection is unintended."],"exampleFix":"// before: plan blocked by policy\nError: Task Stage 'taskstage-xxx': failed.\n\n// after: review policy results in UI, fix config to comply, re-run\n$ terraform plan   # config now satisfies Sentinel policy","handlingStrategy":"try-catch","validationCode":"// Preflight: list task stages/run tasks on the workspace to anticipate failures.\nws, _ := r.client.Workspaces.Read(ctx, r.organization, r.workspace.Name)\nif len(ws.TaskStagesIDs()) > 0 { /* warn that run tasks are active */ }","typeGuard":null,"tryCatchPattern":"// Differentiate terminal task failure from override-pending for the operator.\nswitch stage.Status {\ncase tfe.TaskStageCanceled, tfe.TaskStageErrored, tfe.TaskStageFailed:\n    return fmt.Errorf(\"Task Stage '%s': %s.\", stage.ID, stage.Status)\ncase tfe.TaskStageAwaitingOverride:\n    return fmt.Errorf(\"Task Stage '%s' awaiting override.\", stage.ID)\n}","preventionTips":["Review run-task/Sentinel policy results in the TFC UI before re-running.","Fix the config to satisfy enforced policies rather than disabling them.","For overridable policies, ensure the right team has override permission.","Monitor task-runner health if you see Errored statuses on healthy configs."],"tags":["task-stage","run-task","sentinel","policy","terraform-cloud"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}