Render variants in killable processes with time and memory limits

The renderer adapter keeps one single-process pool per WORKER_CONCURRENCY
slot. A render that exceeds RENDER_TIMEOUT_SECONDS is killed and its slot
is respawned, the render process has RLIMIT_AS = RENDER_MEMORY_MB on
Linux, so both limits end in ImageTooDemanding, a permanent
processing_failed. A render process killed from outside is a transient
error. A cancelled render (lost lease, shutdown) kills its process too.
The worker container limit grows to 1g: two 448 MiB render processes
plus the worker itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-29 03:02:16 +03:00
co-authored by Claude Opus 5.5
parent 431b82fd43
commit f2242eb39d
10 changed files with 228 additions and 20 deletions
+26
View File
@@ -10,6 +10,8 @@ from httpx import AsyncClient
from test_attachments import storage, trio, upload
from conftest import DATABASE, actor
from messenger.attachments.application.ports import Rendition
from messenger.attachments.domain.errors import ImageTooDemanding
from messenger.attachments.domain.jobs import Job, Outcome, RetryPolicy
from messenger.attachments.entrypoints.schemas import JobMessage
from messenger.shared.application.errors import Unavailable
@@ -205,6 +207,30 @@ async def test_undecodable_image_fails_without_retries(client: AsyncClient) -> N
)
class DemandingRenderer:
async def render(self, data: bytes, pipeline_version: int) -> list[Rendition]:
raise ImageTooDemanding("рендер дольше допустимого времени")
@pytest.mark.parametrize("cause", ["limit", "missing"])
async def test_limits_and_lost_original_fail_without_retries(
client: AsyncClient, cause: str
) -> None:
_, _, attachment_id = await accepted(client)
pipeline = await pipeline_of(client)
if cause == "limit":
pipeline.renderer = DemandingRenderer()
else:
del (await storage(client)).objects[f"staging/{attachment_id}"]
await pipeline.drain()
failed = await state(attachment_id)
assert (failed["status"], failed["error_code"], failed["attempt"]) == (
"failed",
"processing_failed",
1,
)
async def test_expired_lease_is_recovered_and_old_holder_is_fenced(client: AsyncClient) -> None:
_, _, attachment_id = await accepted(client)
pipeline = await pipeline_of(client)