Skip to content

♻️ Adopt node-graph's GraphTaskHandle for @task.graph decorators#796

Draft
elinscott wants to merge 1 commit into
aiidateam:mainfrom
elinscott:graph-task-handle
Draft

♻️ Adopt node-graph's GraphTaskHandle for @task.graph decorators#796
elinscott wants to merge 1 commit into
aiidateam:mainfrom
elinscott:graph-task-handle

Conversation

@elinscott

Copy link
Copy Markdown
Collaborator

Problem

node-graph #150 made build graph-only by handle type: it removed the method (and its runtime task_type != "GRAPH" guard) from BaseHandle and moved it to a new GraphTaskHandle. node-graph's own decorator now dispatches on the spec type:

handle = GraphTaskHandle(spec) if is_graph_task else TaskHandle(spec)

aiida-workgraph's graph decorator still returns a plain TaskHandle, so when paired with node-graph > 0.6.5 every @task.graph handle loses build/run/run_get_graph/submit:

AttributeError: 'TaskHandle' object has no attribute 'build'

Change

Mirror the upstream pattern:

  • New aiida_workgraph.task.GraphTaskHandle(TaskHandle), returned by the @task.graph decorator.
  • build delegates to node-graph's GraphTaskHandle.build rather than inheriting it, because node-graph's __init__ takes spec only, while ours must also wire get_current_graph and graph_class=WorkGraph. The delegation only needs self._spec / self._graph_class / self.identifier, all present here.
  • run, run_get_graph and submit move from TaskHandle onto GraphTaskHandle. They all materialize a WorkGraph via self.build, which only makes sense for graph specs; on plain task handles they only ever raised. Plain handles now keep node-graph's direct-execute run semantics, matching the behaviour of New syntax for the graph_builder's output #150

Compatibility

#150 is unreleased at the time of writing; the node-graph version pin should be bumped upon the next node-graph release, and this PR should not be merged prior.

node-graph aiidateam#150 made ``build`` graph-only by handle type, removing it
from ``BaseHandle``. The graph decorator still returned a plain
``TaskHandle``, so every ``@task.graph`` handle lost
``build``/``run``/``run_get_graph``/``submit`` when paired with
node-graph > 0.6.5.

Mirror node-graph's own decorator: the graph decorator now returns a
``GraphTaskHandle`` carrying the four graph-materializing methods.
Plain task handles drop them - they only ever raised there, and plain
handles keep node-graph's direct-execute ``run`` semantics.

Requires node-graph with aiidateam#150 (unreleased at time of writing).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@elinscott elinscott marked this pull request as draft July 2, 2026 15:24
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