Skip to content

fix(worker): dedupe discovered workflows by defining module#20

Draft
HHK1 wants to merge 1 commit into
mainfrom
fix/dedupe-workflow-discovery
Draft

fix(worker): dedupe discovered workflows by defining module#20
HHK1 wants to merge 1 commit into
mainfrom
fix/dedupe-workflow-discovery

Conversation

@HHK1

@HHK1 HHK1 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Problem

discover_workflows() uses inspect.getmembers(module, inspect.isclass) which returns every class accessible in the module's namespace — including classes imported from sibling modules.

When one workflow imports another to call it via execute_workflow (a common parent/child pattern), the child workflow class is picked up by the scanner in both the module that defines it and the module that imports it. Both registrations are passed to run_worker, and Temporal rejects the duplicate at worker startup:

ValueError: More than one workflow named mna-flash-dd-managed
RuntimeError: Failed validating workflow mna-eval

Repro

# workflows/child.py
@workflow.define(name="child")
class ChildWorkflow: ...

# workflows/parent.py
from workflows.child import ChildWorkflow  # re-exported into parent's namespace

@workflow.define(name="parent")
class ParentWorkflow:
    @workflow.entrypoint
    async def run(self, params): 
        return await execute_workflow(ChildWorkflow, ...)

Worker startup fails because ChildWorkflow is discovered twice.

Fix

  • Filter on obj.__module__ == modname so only classes defined in the scanned module count.
  • Keep a seen set as a belt-and-braces guard against any other duplicate paths.

Test

Manually verified on a project that hit the original error — worker now starts cleanly with two workflows where one imports the other.


Generated by Mistral Vibe.

Workflow classes imported from a sibling module (e.g. a parent
workflow importing a child to call via execute_workflow) were
picked up by inspect.getmembers in every module that re-exported
them, registering the same class twice and tripping Temporal's
'More than one workflow named X' check at worker startup.

Filter by obj.__module__ == modname so only classes defined in
the scanned module count, and track seen classes as a safety net.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
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