Docs / docs (push) Successful in 30s
Playwright Tests / test-playwright (1, 2) (push) Successful in 3m7s
Playwright Tests / test-playwright (2, 2) (push) Successful in 1m54s
pre-commit / pre-commit (push) Failing after 4m24s
Test Backend / test-backend (push) Successful in 3m8s
Compose Smoke Test / test-compose (push) Successful in 40s
Playwright Tests / merge-reports (push) Successful in 1m33s
A port may now declare `image`, `audio` or `video`. Each is the artifact
reference the engine already had, narrowed by the `media_type` on it, so a
speech recogniser declares what it eats rather than taking any bytes at all and
finding out. Bytes still never travel as a message and nothing on the wire
stops being JSON: a camera publishes one reference per frame, a microphone one
per chunk, and a reference may carry a `meta` dict nothing here interprets.
Streaming media is therefore an ordinary streaming port — with one change to
what that means. An emission used to journal an item with no payload, so
downstream read whatever was current when the item was claimed; a consumer
slower than its producer saw only the newest chunk and the ones between were
lost. That is right for a training curve and wrong for a second of speech, so
an emission now journals a `kind="emission"` item carrying its values, and the
executor hands them to the nodes reading that message instead of writing them
to state again. The value in state stays the latest, which is what everything
else reads, and the wave is filtered by what actually changed rather than
walking everything reachable. No queue serialization change — the existing
`outputs` field carries it.
Continuous media makes the store's missing GC a real problem, so this closes
it: `sweep_artifacts` runs hourly, keeps every digest a `run_artifact` row
records or a live message holds, spares anything written in the last hour, and
stands aside entirely while a run is in flight, since a node may store a
checkpoint long before it returns the reference to it. That also collects the
orphans a deleted flow has always left behind. `ARTIFACT_GC_INTERVAL_S=0` turns
it off.
Around the edges: `GET /artifacts/{digest}` serves the media type the caller
passes and answers ranged requests, so a browser plays a clip rather than
downloading it; `PUT` spools to disk instead of holding the whole body in
memory, as does `save_artifact` given a path; a Media widget draws whatever its
message points at, and a wall panel may fetch the bytes its own tiles are
showing and nothing else; and a connector gets `save_artifact`, for a device
whose readings are bytes.
What this cannot do is live video: a frame every second or two is a glance, and
the honest answer above that is the camera's own stream, which the widget takes
as a URL and the browser plays from source.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
111 lines
3.5 KiB
Python
111 lines
3.5 KiB
Python
import os
|
|
import time
|
|
from datetime import UTC, datetime
|
|
|
|
import pytest
|
|
from sqlmodel import Session, col, select
|
|
|
|
from fluksio.core.db import engine as db_engine
|
|
from fluksio.flow.artifacts import ArtifactStore
|
|
from fluksio.flow.runs import new_run_id, sweep_artifacts
|
|
from fluksio.flow.state import MemoryState
|
|
from fluksio.models import Run, RunArtifact
|
|
|
|
|
|
@pytest.fixture
|
|
def store(tmp_path) -> ArtifactStore:
|
|
return ArtifactStore(tmp_path / "artifacts")
|
|
|
|
|
|
def _run_row(status: str, digest: str = "") -> str:
|
|
"""A run, and optionally the artifact it recorded. Returns its id."""
|
|
run_id = new_run_id()
|
|
with Session(db_engine) as session:
|
|
session.add(
|
|
Run(id=run_id, flow="f", status=status, created_at=datetime.now(UTC))
|
|
)
|
|
if digest:
|
|
session.add(
|
|
RunArtifact(
|
|
run_id=run_id,
|
|
name="f.out",
|
|
node="n",
|
|
digest=digest,
|
|
size=3,
|
|
)
|
|
)
|
|
session.commit()
|
|
return run_id
|
|
|
|
|
|
def _forget(run_id: str) -> None:
|
|
with Session(db_engine) as session:
|
|
rows = session.exec(
|
|
select(RunArtifact).where(col(RunArtifact.run_id) == run_id)
|
|
).all()
|
|
for row in rows:
|
|
session.delete(row)
|
|
session.delete(session.get(Run, run_id))
|
|
session.commit()
|
|
|
|
|
|
def test_the_grace_window_spares_a_fresh_artifact(store):
|
|
ref = store.put([b"new"])
|
|
assert store.collect(set(), grace_s=3600) == 0
|
|
assert store.path(ref["digest"]) is not None
|
|
assert store.collect(set(), grace_s=0) == 1
|
|
assert store.path(ref["digest"]) is None
|
|
|
|
|
|
def test_a_sweep_keeps_what_a_run_recorded_and_what_a_message_holds(store):
|
|
recorded = store.put([b"kept by a run"])
|
|
held = store.put([b"kept by a message"])
|
|
nested = store.put([b"kept inside a payload"])
|
|
orphan = store.put([b"referred to by nothing"])
|
|
|
|
run_id = _run_row("ok", recorded["digest"])
|
|
state = MemoryState()
|
|
state.update(
|
|
{
|
|
"cam.frame": held,
|
|
# A reference inside a json payload counts as much as a bare one.
|
|
"cam.report": {"latest": {"clip": nested}},
|
|
"cam.count": 3,
|
|
}
|
|
)
|
|
|
|
try:
|
|
assert sweep_artifacts(store, state) == 1
|
|
finally:
|
|
_forget(run_id)
|
|
|
|
assert store.path(orphan["digest"]) is None
|
|
for kept in (recorded, held, nested):
|
|
assert store.path(kept["digest"]) is not None
|
|
|
|
|
|
def test_a_sweep_stands_aside_while_a_run_is_in_flight(store):
|
|
orphan = store.put([b"mid-run checkpoint"])
|
|
run_id = _run_row("running")
|
|
try:
|
|
assert sweep_artifacts(store, MemoryState()) == 0
|
|
finally:
|
|
_forget(run_id)
|
|
assert store.path(orphan["digest"]) is not None
|
|
|
|
|
|
def test_a_streamed_chunk_falls_out_once_the_message_moves_on(store):
|
|
"""What makes a media stream affordable: only the current frame is held."""
|
|
state = MemoryState()
|
|
first = store.put([b"frame one"], media_type="image/png")
|
|
state.update({"cam.frame": first})
|
|
assert sweep_artifacts(store, state) == 0
|
|
|
|
second = store.put([b"frame two"], media_type="image/png")
|
|
state.update({"cam.frame": second})
|
|
# Old enough to be swept: the sweep only spares what grace covers.
|
|
os.utime(store.path(first["digest"]), (time.time() - 10, time.time() - 10))
|
|
assert sweep_artifacts(store, state, grace_s=5) == 1
|
|
assert store.path(first["digest"]) is None
|
|
assert store.path(second["digest"]) is not None
|