Skip to content

Parent workflow deadlocks when child run is deadline-expired during claimWorkflowRun #714

Description

@kunaldevxxx

Background

When a child workflow run exceeds its deadlineAt, workers expire it to failed status inside claimWorkflowRun. The parent workflow parks itself waiting on the child via step.runWorkflow, which calls sleepWorkflowRun and releases the worker slot. The parent should be woken promptly when the child reaches a terminal state.

Problem

The deadline-expiry path in postgres/backend.ts:484 and sqlite/backend.ts:414 marks child runs as failed but never calls wakeParentWorkflowRun. The parent's availableAt is never updated to NOW(). The parent remains parked until its own availableAt — which is set to the runWorkflow timeout (default: 1 year from workflow start).

Steps to Reproduce

  1. Define a child workflow and a parent that calls step.runWorkflow(child, input, { timeout: "1h" }).
  2. Create the child run with deadlineAt: new Date(Date.now() + 1000) (1s).
  3. Wait 2s for the deadline to pass.
  4. Trigger a claimWorkflowRun tick.
  5. Observe: child is failed; parent availableAt remains 1 hour in the future.

Expected Behavior

When a child run is expired, the parent's availableAt is set to NOW() so it is picked up on the next poll cycle.

Proposed Solution

Postgres: Extend the expired CTE to also RETURNING "id", "parent_step_attempt_namespace_id", "parent_step_attempt_id". After the main claim UPDATE, run the same wake-parent UPDATE used by completeWorkflowRun against the expired IDs.

SQLite: After the expiry UPDATE, query the expired run IDs with RETURNING "id", "parent_step_attempt_id" and loop wakeParentWorkflowRun for each.

Acceptance Criteria

Integration test: parent wakes within one poll cycle after child deadline expires.
Both Postgres and SQLite backends pass the test.
No regression in existing child-workflow tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions