Workflow pin is never re-pinned when a requeue changes the task's workflow, so approving a waiting_human task always re-parks it #1707

Closed
opened 2026-10-27 13:41:28 +00:00 by sam · 0 comments
Owner

Summary

Approving a task that is waiting_human requeues it under implement but leaves its workflow pin untouched. pinWorkflowDefinition returns early whenever workflow_definition_yaml is non-empty and only checks that YAML against its own digest — never against task.Workflow. A requeue therefore hands the daemon a task whose stored definition id disagrees with its workflow column, and the pin is never repaired.

The mismatch then fails the worker's identity check in CompilePinnedWorkflow:

pinned workflow definition does not match task identity

Observed live: a task that had parked under feasibility (its stored pin was the feasibility definition) was approved. Requeue set status=queued, workflow=implement and cleared park_reason, but workflow_definition_yaml still held id: feasibility, so wf.Name (feasibility) != req.Task.Workflow (implement) parked the task again. Approving a second time reproduces it identically — the task is unrecoverable through the operator surface.

Impact

  • An approval cannot succeed. Any task approved out of waiting_human whose stored pin names a different workflow re-parks immediately, every time. The operator's only working action on that task is to decline it.
  • Silent at the write. The requeue audit row records requeued implement and the dashboard shows the task leave waiting_human, so the failure looks like a worker fault rather than stale state.
  • Not repairable from the UI. Retry/approve both route through the same requeue, so neither clears the pin.

Defect — the pin invariant is assumed, never enforced

internal/daemon/daemon.go, pinWorkflowDefinition:

if task.WorkflowDefinitionYAML != "" {
    if workflow.DigestDefinition(task.WorkflowDefinitionYAML) != task.WorkflowDefinitionDigest {
        return fmt.Errorf("stored workflow definition digest mismatch")
    }
    return nil
}

The guard is self-referential: it proves the stored YAML matches its own recorded digest, which is a property of the write, not of the task. It never asks whether the stored definition is the one task.Workflow names, which is exactly the invariant CompilePinnedWorkflow later enforces:

if wf.Name != req.Task.Workflow || workflow.DigestDefinition(req.WorkflowDefinition) != req.Task.WorkflowDefinitionDigest {
    return workflow.Workflow{}, fmt.Errorf("pinned workflow definition does not match task identity")
}

So the producer (daemon pin) accepts a state the consumer (worker compile) rejects. Per the repo's own rule — fix invalid state at the producer — the guard belongs here.

The comment on resolveWorkflowID shows the requeue path is a deliberate, supported case ("a decision already made about this specific task"), which makes the missing re-pin a defect rather than an unreachable state.

Reproduction

  1. Task runs feasibility, reaches deliver, parks as waiting_human with workflow_definition_yaml = "id: feasibility\n...".
  2. Operator approves: POST /api/tasks/{id}/action {"action":"approve"} → Service.apply → Store.Requeue(ctx, id, "waiting_human", "implement").
  3. UpdateTaskOnRequeue sets status/workflow/park_reason and not the workflow_definition_* columns.
  4. Next dispatch calls pinWorkflowDefinition, which returns early on the non-empty stale YAML.
  5. Worker's CompilePinnedWorkflow fails the identity check; the task parks transient.

Expected

pinWorkflowDefinition re-pins whenever the stored definition's id disagrees with task.Workflow: clear the pin and resolve it from the active collection for the named workflow, instead of trusting a pin that names a different workflow. A pin that is present, digest-valid and id-consistent should stay a no-op.

Cover with tests for: a requeue whose stored pin names the previous workflow (the case above), and a stored pin that is id-consistent (must remain untouched, so an operator's active definition override still survives).

Refs: internal/domain/taskactions/service.go (approve → Requeue(..., "implement")), internal/infrastructure/postgres/queries/tasks.sql (RequeueTask), internal/app/agentworker/task_execution.go (CompilePinnedWorkflow).


Imported from GitHub #1235 · type bug · priority P1 · created 2026-09-29 · closed 2026-09-29

## Summary Approving a task that is `waiting_human` requeues it under `implement` but **leaves its workflow pin untouched**. `pinWorkflowDefinition` returns early whenever `workflow_definition_yaml` is non-empty and only checks that YAML against its own digest — never against `task.Workflow`. A requeue therefore hands the daemon a task whose stored definition id disagrees with its `workflow` column, and the pin is never repaired. The mismatch then fails the worker's identity check in `CompilePinnedWorkflow`: ``` pinned workflow definition does not match task identity ``` Observed live: a task that had parked under `feasibility` (its stored pin was the `feasibility` definition) was approved. `Requeue` set `status=queued, workflow=implement` and cleared `park_reason`, but `workflow_definition_yaml` still held `id: feasibility`, so `wf.Name` (`feasibility`) `!= req.Task.Workflow` (`implement`) parked the task again. Approving a second time reproduces it identically — the task is unrecoverable through the operator surface. ## Impact - **An approval cannot succeed.** Any task approved out of `waiting_human` whose stored pin names a different workflow re-parks immediately, every time. The operator's only working action on that task is to decline it. - **Silent at the write.** The requeue audit row records `requeued implement` and the dashboard shows the task leave `waiting_human`, so the failure looks like a worker fault rather than stale state. - **Not repairable from the UI.** Retry/approve both route through the same requeue, so neither clears the pin. ## Defect — the pin invariant is assumed, never enforced `internal/daemon/daemon.go`, `pinWorkflowDefinition`: ```go if task.WorkflowDefinitionYAML != "" { if workflow.DigestDefinition(task.WorkflowDefinitionYAML) != task.WorkflowDefinitionDigest { return fmt.Errorf("stored workflow definition digest mismatch") } return nil } ``` The guard is self-referential: it proves the stored YAML matches its own recorded digest, which is a property of the write, not of the task. It never asks whether the stored definition is the one `task.Workflow` names, which is exactly the invariant `CompilePinnedWorkflow` later enforces: ```go if wf.Name != req.Task.Workflow || workflow.DigestDefinition(req.WorkflowDefinition) != req.Task.WorkflowDefinitionDigest { return workflow.Workflow{}, fmt.Errorf("pinned workflow definition does not match task identity") } ``` So the producer (daemon pin) accepts a state the consumer (worker compile) rejects. Per the repo's own rule — fix invalid state at the producer — the guard belongs here. The comment on `resolveWorkflowID` shows the requeue path is a deliberate, supported case ("a decision already made about this specific task"), which makes the missing re-pin a defect rather than an unreachable state. ## Reproduction 1. Task runs `feasibility`, reaches `deliver`, parks as `waiting_human` with `workflow_definition_yaml = "id: feasibility\n..."`. 2. Operator approves: `POST /api/tasks/{id}/action {"action":"approve"}` → `Service.apply` → `Store.Requeue(ctx, id, "waiting_human", "implement")`. 3. `UpdateTaskOnRequeue` sets `status`/`workflow`/`park_reason` and **not** the `workflow_definition_*` columns. 4. Next dispatch calls `pinWorkflowDefinition`, which returns early on the non-empty stale YAML. 5. Worker's `CompilePinnedWorkflow` fails the identity check; the task parks `transient`. ## Expected `pinWorkflowDefinition` re-pins whenever the stored definition's id disagrees with `task.Workflow`: clear the pin and resolve it from the active collection for the named workflow, instead of trusting a pin that names a different workflow. A pin that is present, digest-valid **and** id-consistent should stay a no-op. Cover with tests for: a requeue whose stored pin names the previous workflow (the case above), and a stored pin that is id-consistent (must remain untouched, so an operator's active definition override still survives). Refs: `internal/domain/taskactions/service.go` (approve → `Requeue(..., "implement")`), `internal/infrastructure/postgres/queries/tasks.sql` (`RequeueTask`), `internal/app/agentworker/task_execution.go` (`CompilePinnedWorkflow`). --- _Imported from GitHub #1235 · type bug · priority P1 · created 2026-09-29 · closed 2026-09-29_
sam added the highbug labels 2026-10-27 13:41:28 +00:00
sam self-assigned this 2026-10-27 13:41:28 +00:00
sam closed this issue 2026-10-27 13:41:28 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1707