Artifact sweep keeps digests named in node settings

A Service's weights or a wren node's model held only in a setting were
swept once the run that produced them was deleted.

Claude-Session: https://claude.ai/code/session_01H89mFby73wwhthP9htfcuB
This commit is contained in:
2026-10-24 21:28:35 +02:00
parent ea781c923c
commit 2a09f0b765
5 changed files with 43 additions and 12 deletions
+20 -6
View File
@@ -357,11 +357,20 @@ _REF_DEPTH = 8
_SWEEP_BATCH = 500
def _references_in(value: Any, found: set[str], depth: int = 0) -> None:
"""Every artifact digest inside one stored value."""
def _references_in(
value: Any, found: set[str], depth: int = 0, bare: bool = False
) -> None:
"""Every artifact digest inside one stored value.
With ``bare``, a plain ``sha256:...`` string counts as well, which is how a
node setting such as a Service's ``weights`` names its artifact.
"""
if is_reference(value):
found.add(str(value["digest"]))
return
if bare and isinstance(value, str) and valid_digest(value):
found.add(value)
return
if depth >= _REF_DEPTH:
return
if isinstance(value, dict):
@@ -371,7 +380,7 @@ def _references_in(value: Any, found: set[str], depth: int = 0) -> None:
else:
return
for item in items:
_references_in(item, found, depth + 1)
_references_in(item, found, depth + 1, bare)
def sweep_artifacts(
@@ -412,9 +421,12 @@ def referenced_artifacts(
) -> set[str]:
"""Every artifact digest something still refers to.
Three things do: a run that recorded it, a message currently holding it,
and a flow input's ``initial``, published or draft, which a flow that has
never started holds nowhere else.
Four things do: a run that recorded it, a message currently holding it,
a flow input's ``initial``, which a flow that has never started holds
nowhere else, and any node setting naming it, such as a Service's
``weights``. Both the published flow and its draft count, since the draft
is what gets published next. Older versions live only in git history and
do not count.
"""
with Session(db_engine) as session:
keep = set(session.exec(select(col(RunArtifact.digest)).distinct()).all())
@@ -428,6 +440,8 @@ def referenced_artifacts(
continue
for declared in flow.inputs:
_references_in(declared.initial, keep)
for node in flow.nodes:
_references_in(node.params, keep, bare=True)
keys = state.keys()
for start in range(0, len(keys), _SWEEP_BATCH):