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:
@@ -217,8 +217,8 @@ def delete_artifact(
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail=(
|
||||
"The artifact is still referenced by a run, a current message or "
|
||||
"a flow input's initial value"
|
||||
"The artifact is still referenced by a run, a current message, "
|
||||
"a flow input's initial value or a node setting"
|
||||
),
|
||||
)
|
||||
if not store.delete(digest):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user