* feat: add Runpod serverless image collector pools * fix: prevent worker settings clipping and remove preview copy * fix: initialize worker settings before mounting the form * fix: validate complete serverless requests against 10 MB limit * fix: simplify serverless cards and keep status dots circular * fix: match serverless endpoint box to master card * fix: preserve serverless capacity and recovery across job failures Retain durable reservations until provider termination or explicit recovery, protect unresolved pools and credentials, and add scoped reconciliation. Consolidate lifecycle and secret policies and split prompt/media stages with regression coverage. * feat: add dynamic per-image list queue with Start and End nodes * fix(image-list): reject upstream data bypasses around Start * fix(image-list): make optional End text a connection-only input * fix(image-list): isolate unavailable workers during preflight * fix(image-list): bound acknowledgements and configure run deadline * fix(media-sync): preserve output and temp source roots * fix(image-list): own job lifecycle and preserve worker preparation * feat(image-list): let master participate unless orchestrator-only * feat(image-list)!: replace fixed Start extras with growable value_N slots Distributed Image List Start no longer has reference_image, text, strength, seed or per-slot mode dropdowns. It now takes images, mask and up to 10 generic value_N inputs (IMAGE, MASK, STRING, INT, FLOAT, BOOLEAN) that grow via native V3 Autogrow, each with a matching output. - One value is shared by every image; one per image pairs in order; any other count fails before dispatch. Only images is split into frames. - Outputs are declared up front (image, mask, item_index, context, value_1..value_10). web/imageListStart.js hides unused value outputs, mirrors input types, and follows Autogrow compaction so downstream links keep their value. - Image-list protocol bumped to v2; older workers fail preflight. Breaking: saved workflows using the old Start inputs must recreate Start. * fix(serverless): disable Clear saved API key while the worker is enabled The checkbox read "Clear saved API key (disable pool first)", but the panel never defines "pool" and saving with it ticked on an enabled worker was rejected by the backend. - Disable the checkbox while the worker is enabled, with a tooltip saying to turn the worker off first. Also disable it when no key is saved. - Use "worker" instead of "pool" in user-facing serverless errors, the serverless guide and the README entry. * feat(serverless): replace Concurrent jobs with a single Images per run setting - Remove the separate Concurrent jobs field; rename Jobs per run to Images per run (1-16) with a tooltip explaining that Runpod's max workers decides how many GPUs run them. - Backend uses a fixed per-worker limit of 16 outstanding jobs, so all images of a run are submitted at once. Unresolved jobs still count against it. The limit is constant, so it never has to change while jobs are unresolved. - Legacy 'concurrency' in saved configs and older browser tabs is accepted and ignored/dropped; it no longer triggers the busy guard. - Revert the enable toggle and show the reason when the backend rejects it. - Trim a pasted api.runpod.ai/v2/<id> URL to the endpoint ID; plainer endpoint-ID error otherwise. - Confirm before a type change deletes a saved Runpod API key. - Update docs and tests.
178 lines
6.2 KiB
Python
178 lines
6.2 KiB
Python
"""Tests for periodic image-list server lifecycle cleanup."""
|
|
import asyncio
|
|
import time
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
from typing import Any, cast
|
|
from unittest.mock import patch
|
|
|
|
from aiohttp import web
|
|
|
|
from image_list import lifecycle, runtime
|
|
|
|
|
|
class ImageListLifecycleTests(unittest.IsolatedAsyncioTestCase):
|
|
def setUp(self):
|
|
with runtime._LOCK:
|
|
runtime._MASTER_JOBS.clear()
|
|
runtime._WORKER_ITEMS.clear()
|
|
|
|
def tearDown(self):
|
|
with runtime._LOCK:
|
|
runtime._MASTER_JOBS.clear()
|
|
runtime._WORKER_ITEMS.clear()
|
|
|
|
@staticmethod
|
|
def _state(prompt_id=None, *, active=False, age=10_000.0):
|
|
return SimpleNamespace(
|
|
prompt_id=prompt_id,
|
|
active=active,
|
|
created_at=time.monotonic() - age,
|
|
)
|
|
|
|
@staticmethod
|
|
def _server(queue):
|
|
return SimpleNamespace(app=web.Application(), prompt_queue=queue)
|
|
|
|
async def _start(self, server, *, interval=0.01, grace=0.01):
|
|
lifecycle.install_lifecycle(
|
|
server,
|
|
runtime,
|
|
interval_seconds=interval,
|
|
orphan_grace_seconds=grace,
|
|
)
|
|
runner = web.AppRunner(server.app)
|
|
await runner.setup()
|
|
return runner
|
|
|
|
async def test_unattended_sweep_removes_orphan_and_expired_staging(self):
|
|
context_id = "orphan"
|
|
with runtime._LOCK:
|
|
cast(Any, runtime._MASTER_JOBS)[context_id] = self._state()
|
|
runtime._WORKER_ITEMS["expired-token"] = (time.monotonic() - 1, {"image": "stale"})
|
|
|
|
queue = SimpleNamespace(
|
|
get_current_queue_volatile=lambda: ([], []),
|
|
)
|
|
server = self._server(queue)
|
|
swept = asyncio.Event()
|
|
sweep_worker_items = runtime._sweep_worker_items
|
|
|
|
def track_worker_sweep():
|
|
swept.set()
|
|
sweep_worker_items()
|
|
|
|
with patch.object(runtime, "_sweep_worker_items", side_effect=track_worker_sweep):
|
|
runner = await self._start(server)
|
|
try:
|
|
await asyncio.wait_for(swept.wait(), timeout=0.5)
|
|
self.assertNotIn(context_id, runtime._MASTER_JOBS)
|
|
self.assertNotIn("expired-token", runtime._WORKER_ITEMS)
|
|
with self.assertRaisesRegex(ValueError, "Unknown or expired"):
|
|
runtime.set_master_result(context_id, 0, "late-token", {})
|
|
finally:
|
|
await runner.cleanup()
|
|
|
|
async def test_old_active_and_queued_contexts_survive_but_orphans_expire(self):
|
|
states = {
|
|
"active": self._state("active-prompt", active=True),
|
|
"queued": self._state("queued-prompt"),
|
|
"orphan": self._state("missing-prompt"),
|
|
"unbound": self._state(None),
|
|
}
|
|
with runtime._LOCK:
|
|
cast(Any, runtime._MASTER_JOBS).update(states)
|
|
queue = SimpleNamespace(
|
|
get_current_queue_volatile=lambda: (
|
|
[[1, "active-prompt", {}]],
|
|
[(2, "queued-prompt", {}, {}, None, None)],
|
|
),
|
|
)
|
|
runner = await self._start(self._server(queue))
|
|
try:
|
|
await asyncio.sleep(0.04)
|
|
self.assertIs(runtime._MASTER_JOBS.get("active"), states["active"])
|
|
self.assertIs(runtime._MASTER_JOBS.get("queued"), states["queued"])
|
|
self.assertNotIn("orphan", runtime._MASTER_JOBS)
|
|
self.assertNotIn("unbound", runtime._MASTER_JOBS)
|
|
finally:
|
|
await runner.cleanup()
|
|
|
|
async def test_falls_back_to_nonvolatile_queue_reader(self):
|
|
state = self._state("queued-prompt")
|
|
with runtime._LOCK:
|
|
cast(Any, runtime._MASTER_JOBS)["queued"] = state
|
|
fallback_reads = 0
|
|
|
|
def volatile_failure():
|
|
raise RuntimeError("volatile view unavailable")
|
|
|
|
def current_queue():
|
|
nonlocal fallback_reads
|
|
fallback_reads += 1
|
|
return ([], [[1, "queued-prompt", {}]])
|
|
|
|
queue = SimpleNamespace(
|
|
get_current_queue_volatile=volatile_failure,
|
|
get_current_queue=current_queue,
|
|
)
|
|
runner = await self._start(self._server(queue))
|
|
try:
|
|
await asyncio.sleep(0.04)
|
|
self.assertGreaterEqual(fallback_reads, 1)
|
|
self.assertIs(runtime._MASTER_JOBS.get("queued"), state)
|
|
finally:
|
|
await runner.cleanup()
|
|
|
|
async def test_queue_read_error_protects_bound_contexts(self):
|
|
with runtime._LOCK:
|
|
cast(Any, runtime._MASTER_JOBS)["bound"] = self._state("bound-prompt")
|
|
cast(Any, runtime._MASTER_JOBS)["unbound"] = self._state(None)
|
|
|
|
def fail_read():
|
|
raise RuntimeError("queue unavailable")
|
|
|
|
queue = SimpleNamespace(
|
|
get_current_queue_volatile=fail_read,
|
|
get_current_queue=fail_read,
|
|
)
|
|
runner = await self._start(self._server(queue))
|
|
try:
|
|
await asyncio.sleep(0.04)
|
|
self.assertIn("bound", runtime._MASTER_JOBS)
|
|
self.assertNotIn("unbound", runtime._MASTER_JOBS)
|
|
finally:
|
|
await runner.cleanup()
|
|
|
|
async def test_install_and_removal_are_idempotent_and_task_stops_on_cleanup(self):
|
|
queue_reads = 0
|
|
|
|
def read_queue():
|
|
nonlocal queue_reads
|
|
queue_reads += 1
|
|
return ([], [])
|
|
|
|
server = self._server(SimpleNamespace(get_current_queue_volatile=read_queue))
|
|
lifecycle.install_lifecycle(server, runtime, interval_seconds=0.01, orphan_grace_seconds=0.01)
|
|
lifecycle.install_lifecycle(server, runtime, interval_seconds=0.01, orphan_grace_seconds=0.01)
|
|
self.assertEqual(len(server.app.cleanup_ctx), 1)
|
|
|
|
with runtime._LOCK:
|
|
cast(Any, runtime._MASTER_JOBS)["removed"] = self._state()
|
|
runtime.remove_master_job("removed")
|
|
runtime.remove_master_job("removed")
|
|
self.assertNotIn("removed", runtime._MASTER_JOBS)
|
|
|
|
runner = web.AppRunner(server.app)
|
|
await runner.setup()
|
|
await asyncio.sleep(0.035)
|
|
self.assertGreaterEqual(queue_reads, 1)
|
|
await runner.cleanup()
|
|
reads_after_cleanup = queue_reads
|
|
await asyncio.sleep(0.035)
|
|
self.assertEqual(queue_reads, reads_after_cleanup)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|