Skip to content

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

Closed
alvinkam2001 wants to merge 3 commits into
mainfrom
akam/task-create-idempotency
Closed

fix(task-create): handle WorkflowAlreadyStartedError gracefully#488
alvinkam2001 wants to merge 3 commits into
mainfrom
akam/task-create-idempotency

Conversation

@alvinkam2001

@alvinkam2001 alvinkam2001 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes duplicate Temporal task starts return the existing workflow and adds default OpenTelemetry context propagation across Temporal clients and workers.

  • Adds workflow-ID conflict-policy plumbing and uses USE_EXISTING for task submission.
  • Installs a configurable Temporal tracing interceptor on client and worker boundaries.
  • Adds unit coverage for conflict-policy forwarding and tracing-interceptor configuration.

Confidence Score: 4/5

The PR should not merge until duplicate task IDs with changed inputs are rejected or reconciled instead of being reported as successful while silently retaining the old workflow inputs.

USE_EXISTING handles exact retries, but it also converts conflicting submissions with updated agent, params, or timeout values into apparent successes even though Temporal does not apply those new workflow-start arguments.

Files Needing Attention: src/agentex/lib/core/temporal/services/temporal_task_service.py

Important Files Changed

Filename Overview
src/agentex/lib/core/temporal/services/temporal_task_service.py Makes task submission idempotent through USE_EXISTING, but silently discards changed inputs when a duplicate ID refers to an active workflow.
src/agentex/lib/core/clients/temporal/temporal_client.py Adds conflict-policy plumbing from the wrapper to Temporal's workflow-start API.
src/agentex/lib/core/tracing/temporal.py Adds opt-out, failure-tolerant construction of Temporal's OpenTelemetry interceptor.
src/agentex/lib/core/clients/temporal/utils.py Enables trace-context injection on SDK Temporal clients.
src/agentex/lib/core/temporal/workers/worker.py Enables tracing on the worker's client and places the tracing worker interceptor before business interceptors.
tests/lib/core/services/test_temporal_task_service.py Covers conflict-policy forwarding but only tests exact-retry behavior, not duplicate IDs with differing payloads.
tests/lib/core/tracing/test_temporal_interceptor.py Covers default enablement, supported opt-out values, and unavailable-contrib fallback.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant ACP as TemporalACP
    participant Service as TemporalTaskService
    participant Temporal
    Caller->>ACP: task/create(task ID, params)
    ACP->>Service: submit_task(agent, task, params)
    Service->>Temporal: start_workflow(id, inputs, USE_EXISTING)
    alt No active workflow
        Temporal-->>Service: New workflow handle
    else Active workflow with same ID
        Temporal-->>Service: Existing workflow handle
        Note over Service,Temporal: New inputs are not delivered
    end
    Service-->>ACP: Task ID
Loading

Fix All in Cursor Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
### Issue 1
src/agentex/lib/core/temporal/services/temporal_task_service.py:59
**Conflicting task inputs are discarded**

When a second `task/create` request resolves to an active task ID but supplies changed agent, params, or timeout values, `USE_EXISTING` reports success without delivering the new `CreateTaskParams` to the workflow, causing the running task to retain its original inputs despite the task/create contract allowing supplied params to overwrite existing params.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

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

Greptile also left 1 inline comment on this PR.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

This PR is targeting main, but PRs should target the next branch by default.

The main branch is reserved for release-please and Stainless automation. To resolve, pick one of:

  • Re-target the PR to next (recommended). On the PR page, click Edit next to the title and change the base branch to next.
  • Add the target-main label if this is an intentional exception (e.g. an urgent hotfix). The check will re-run and pass.

See CONTRIBUTING.md for the full branch model.

id=task.id,
task_queue=self._env_vars.WORKFLOW_TASK_QUEUE,
execution_timeout=execution_timeout,
id_conflict_policy=WorkflowIDConflictPolicy.USE_EXISTING,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Conflicting task inputs are discarded

When a second task/create request resolves to an active task ID but supplies changed agent, params, or timeout values, USE_EXISTING reports success without delivering the new CreateTaskParams to the workflow, causing the running task to retain its original inputs despite the task/create contract allowing supplied params to overwrite existing params.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agentex/lib/core/temporal/services/temporal_task_service.py
Line: 59

Comment:
**Conflicting task inputs are discarded**

When a second `task/create` request resolves to an active task ID but supplies changed agent, params, or timeout values, `USE_EXISTING` reports success without delivering the new `CreateTaskParams` to the workflow, causing the running task to retain its original inputs despite the task/create contract allowing supplied params to overwrite existing params.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Cursor Fix in Claude Code Fix in Codex

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.

2 participants