From ead0022067042191ebe1f1c4d2e67961d17d5c06 Mon Sep 17 00:00:00 2001 From: autocommit Date: Tue, 9 Jun 2026 02:37:56 -0700 Subject: [PATCH] =?UTF-8?q?feat(pipeline):=20=E2=9C=A8=20Add=20capability?= =?UTF-8?q?=20detection=20logic=20to=20validate=20video/system=20capabilit?= =?UTF-8?q?ies=20before=20processing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../service/src/pipeline/capability.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 services/imajin-video/service/src/pipeline/capability.py diff --git a/services/imajin-video/service/src/pipeline/capability.py b/services/imajin-video/service/src/pipeline/capability.py new file mode 100644 index 00000000..b297edfe --- /dev/null +++ b/services/imajin-video/service/src/pipeline/capability.py @@ -0,0 +1,31 @@ +"""Server-capability sizing for concurrent video work. + +The throttle on how many videos imajin-video decodes at once lives HERE, on the +server — never on the client that requests classification. A backfill consumer may +fire dozens of jobs; this is what keeps apricot from being swamped. + +Pure + unit-tested: the derivation takes the host's available RAM and a per-video +budget and returns a bounded concurrency, so it tests without a host or a GPU. +""" +from __future__ import annotations + + +def derive_video_concurrency( + available_bytes: int, + per_video_budget_bytes: int, + ceiling: int, + *, + floor: int = 1, +) -> int: + """How many videos to decode concurrently, bounded by host RAM. + + Returns ``ceiling`` clamped down to however many ``per_video_budget_bytes`` + chunks fit in ``available_bytes`` — never below ``floor``. A non-positive + budget disables the RAM clamp (returns ``max(floor, ceiling)``). + """ + if ceiling < floor: + ceiling = floor + if per_video_budget_bytes <= 0: + return ceiling + by_ram = available_bytes // per_video_budget_bytes + return max(floor, min(ceiling, int(by_ram)))