SDK: sync and run import the declaring module in a child process

The command line no longer imports a research module, so import-time GPU work
ends with a short-lived child instead of holding a CUDA context for the length
of a followed run. fluksio.sdk.declare starts the child, which writes each
flow's document and shims as JSON; Declared stands in for Flow in sync().
Errors keep their type and message, a child's traceback reaches the user.

Claude-Session: https://claude.ai/code/session_01SSi5AvZ7pFmySK8zy3NPMh
This commit is contained in:
2026-10-28 08:11:14 +01:00
parent 6b8473f207
commit 361ef35d58
8 changed files with 364 additions and 24 deletions
+13 -1
View File
@@ -8,7 +8,7 @@ import pytest
from fastapi.testclient import TestClient
from fluksio.core.config import settings
from fluksio.sdk import FLOWS, MARKER, SyncError
from fluksio.sdk import FLOWS, MARKER, Declared, SyncError
from fluksio.sdk.client import ApiError, Client, sync
EXAMPLES = Path(__file__).parents[4] / "examples"
@@ -74,6 +74,18 @@ def test_sync_stores_a_runnable_flow_with_its_origin(api, flows):
assert "from myresearch.train import fit" in source
def test_a_flow_read_by_another_process_syncs_as_the_flow_does(api, flows):
"""`fluksio sync` imports in a child and uploads what it handed back."""
carried = Declared(flows["train"].declaration())
sync([carried], api, origin=ORIGIN)
stored = api.get_flow("train")["definition"]
assert stored["origin"]["declared_in"] == "myresearch/pipeline.py"
# Nothing differs from what the flow itself would have stored.
assert sync([flows["train"]], api, origin=ORIGIN)[0].unchanged
def test_a_node_carries_the_modules_its_code_reaches(api, flows):
"""The shim names one function; the cache has to key on what it calls."""
sync([flows["train"]], api, origin=ORIGIN)