Skip to content

Make LazyNodeRegistry.build() thread-safe #96

@xujustinj

Description

@xujustinj

Summary

Workflow.validate() loads inner nodes via asyncio.to_thread(...load_node...) in parallel. With the default NodeRegistry.DEFAULT (a LazyNodeRegistry), the first call to build() is not thread-safe; concurrent load_node() calls can race during registry freezing (e.g., both threads entering build() and deleting _registrations/_removals), causing intermittent AttributeError/KeyError during validation.

Possible fixes

  • (a) Pre-freeze the registry once on the main thread before spawning threads (e.g., eagerly call build() during ValidationContext construction).
  • (b) Add a lock to build() so only the first caller performs the freeze and others wait.
  • (c) Avoid parallel to_thread loading and load nodes sequentially in the event loop thread (likely fast enough for validation).

Notes

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions