@@ -447,6 +447,7 @@ class SubprocessCoordinator(BaseCoordinator):
447447 # resolve roots without knowing the subclass field name.
448448 _configured_roots : list [pathlib .Path ] = attrs .field (init = False , factory = list )
449449 _active_bundle_info : BundleInfo | None = attrs .field (init = False , default = None )
450+ _active_scan_roots : tuple [pathlib .Path , ...] | None = attrs .field (init = False , default = None )
450451
451452 @property
452453 def _explicit_artifact_roots (self ) -> tuple [str , Sequence [pathlib .Path ]]:
@@ -526,14 +527,18 @@ def _init_root_source(
526527 raise FileNotFoundError (f"Dag bundle { target .name !r} resolved to { path } , which does not exist." )
527528 return [path ], bundle
528529
529- def _build_execute_task_command (
530- self , * , what : TaskInstance , roots : list [pathlib .Path ]
531- ) -> tuple [list [str ], str | None ]:
530+ def _get_scan_roots (self ) -> tuple [pathlib .Path , ...]:
531+ """Return the artifact roots resolved for the active task."""
532+ if self ._active_scan_roots is None :
533+ raise RuntimeError ("_get_scan_roots requires an active task; call it during execute_task." )
534+ return self ._active_scan_roots
535+
536+ def _build_execute_task_command (self , * , what : TaskInstance ) -> tuple [list [str ], str | None ]:
532537 """
533538 Build the subprocess command and resolve its supervisor wire-schema version for *what*.
534539
535- *roots* are the directories to scan for artifacts, already resolved by
536- :meth:`_init_root_source` from the coordinator's configured source .
540+ Subclasses can retrieve the directories to scan for artifacts with
541+ :meth:`_get_scan_roots` .
537542 Returns a ``(command, subprocess_schema_version)`` pair. *command* MUST
538543 NOT include the ``--comm`` / ``--logs`` flags — those are appended by
539544 :class:`_PopenActivitySubprocess` once the listening sockets have been
@@ -558,6 +563,15 @@ def _set_current_bundle(self, bundle_info: BundleInfo):
558563 finally :
559564 self ._active_bundle_info = None
560565
566+ @contextlib .contextmanager
567+ def _set_scan_roots (self , roots : Sequence [pathlib .Path ]):
568+ """Expose *roots* to the command builder for the duration of the task."""
569+ self ._active_scan_roots = tuple (roots )
570+ try :
571+ yield
572+ finally :
573+ self ._active_scan_roots = None
574+
561575 def execute_task (
562576 self ,
563577 * ,
@@ -584,7 +598,8 @@ def execute_task(
584598 bundle_version = resolved_bundle .version ,
585599 )
586600 )
587- command , subprocess_schema_version = self ._build_execute_task_command (what = what , roots = roots )
601+ stack .enter_context (self ._set_scan_roots (roots ))
602+ command , subprocess_schema_version = self ._build_execute_task_command (what = what )
588603 process = _PopenActivitySubprocess .start (
589604 what = what ,
590605 dag_rel_path = dag_rel_path ,
0 commit comments