Skip to content

Support signature idempotency for durable tasks in workflows #105

Description

@yedidyakfir

Summary

Add idempotency support for signature creation within workflow durable tasks. Currently, the signature retry cache only works for standalone durable tasks (@hatchet.durable_task()). Workflows containing durable tasks need the same idempotency guarantees — ensuring that on retry, signatures are not duplicated regardless of whether the workflow itself is signed or unsigned.

Current Behavior

  • Standalone durable tasks: Retry cache is automatically set up via handle_task_callback(is_idempotent=True), preventing duplicate signature creation on retries
  • Workflow durable tasks: No retry cache setup — if a durable task inside a workflow retries, asign(), achain(), aswarm() will create duplicate signatures
  • Signed workflows: Treated as TaskSignature via asign(), but inner durable tasks don't inherit idempotency

Desired Behavior

  1. Durable tasks inside workflows should automatically get retry cache support, just like standalone durable tasks
  2. Signed workflows should propagate idempotency context to their inner tasks
  3. Unsigned workflows with durable tasks should also support retry cache for signature creation within those tasks
  4. Signature creation order must remain deterministic across retries (existing constraint from docs/documentation/idempotency.md)

Use Cases

  • A workflow with a durable task that calls asign() retries after failure → should return the cached signature, not create a new one
  • A signed workflow dispatched via asign(workflow) contains durable tasks that themselves create signatures → all inner signatures should be idempotent on retry
  • An unsigned workflow registered via @mageflow.workflow() has durable tasks → those tasks' signatures should be cached

Technical Considerations

  • Retry cache is keyed by workflow_id (Hatchet's task run ID) — need to determine the correct key scope for workflow-level tasks
  • _inject_workflow_hooks() in HatchetMageflow already injects completion hooks — may need to also inject retry cache setup for durable tasks within workflows
  • handle_task_callback() controls is_idempotent flag — workflow task decoration needs to pass this through
  • Must handle both task() and durable_task() within workflow context

Related

Tasks

  • Extend retry cache setup to durable tasks within workflows
  • Ensure signed workflows propagate idempotency context to inner durable tasks
  • Ensure unsigned workflows with durable tasks support signature retry cache
  • Add unit tests for workflow durable task retry cache behavior
  • Add integration tests verifying no duplicate signatures on workflow task retry

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions