Skip to content

fix(task-create): handle WorkflowAlreadyStartedError gracefully - #489

Open
alvinkam2001 wants to merge 1 commit into
nextfrom
akam/task-create-idempotency
Open

fix(task-create): handle WorkflowAlreadyStartedError gracefully#489
alvinkam2001 wants to merge 1 commit into
nextfrom
akam/task-create-idempotency

Conversation

@alvinkam2001

@alvinkam2001 alvinkam2001 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes task/create idempotent in the Temporal ACP path. Duplicate submits for the same task ID (e.g. load-balanced agentex-agent replicas racing on the same notification) no longer surface WorkflowAlreadyStartedError, Temporal returns the existing workflow handle instead.

Change

  • TemporalTaskService.submit_task now passes id_conflict_policy=WorkflowIDConflictPolicy.USE_EXISTING.
  • TemporalClient.start_workflow accepts an id_conflict_policy param (defaults to UNSPECIFIED, preserving current behavior for any other caller).

Why

WorkflowIDReusePolicy.ALLOW_DUPLICATE (already set) only governs reuse after a run closes — it doesn't help when a run is currently open. Workflows are mainly just noise as the workflow still runs

Test plan

  • New unit tests in tests/lib/core/services/test_temporal_task_service.py:
    • submit_task passes USE_EXISTING to the client
    • TemporalClient.start_workflow forwards id_conflict_policy when set
    • TemporalClient.start_workflow defaults to UNSPECIFIED (backwards-compat)
  • Existing TemporalTaskService tests still pass
  • Sanity check in staging: fire two task/create calls with the same task ID, confirm both return 200 with the same workflow ID and no error log

Greptile Summary

The PR makes Temporal-backed task/create submissions idempotent while a workflow with the same task ID remains active.

  • Adds configurable workflow ID conflict handling to TemporalClient.start_workflow.
  • Uses USE_EXISTING for task submission while retaining ALLOW_DUPLICATE behavior for closed executions.
  • Adds unit coverage for service-level policy selection, forwarding, and backward-compatible defaults.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable correctness, compatibility, or security issues identified.

The active-workflow conflict behavior is scoped to task submission, the existing closed-run reuse policy remains intact, the Temporal dependency supports the new API, and tests cover policy selection and forwarding.

Important Files Changed

Filename Overview
src/agentex/lib/core/clients/temporal/temporal_client.py Adds a backward-compatible conflict-policy parameter and forwards it to the supported Temporal client API.
src/agentex/lib/core/temporal/services/temporal_task_service.py Selects USE_EXISTING for duplicate active task workflow IDs without changing closed-run reuse behavior.
tests/lib/core/services/test_temporal_task_service.py Verifies service policy selection plus explicit and default conflict-policy forwarding.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[task/create request] --> B[TemporalTaskService.submit_task]
    B --> C[Start workflow with task ID]
    C --> D{Execution with ID active?}
    D -- Yes --> E[USE_EXISTING returns existing handle]
    D -- No, prior run closed --> F[ALLOW_DUPLICATE starts new run]
    D -- No prior run --> G[Start first workflow run]
    E --> H[Return workflow ID]
    F --> H
    G --> H
Loading

Reviews (1): Last reviewed commit: "handle same workflow task/create gracefu..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant