Renew job leases, spread retries with jitter and add crash points

Leases: the worker renews its lease before the first side effect and
every JOB_TIMEOUT_SECONDS/3 while the variants are produced; a renewal
that finds the lease taken cancels the work (and its render process)
and settles the job as fenced without writing anything.

Retries: the delay before attempt n+1 is drawn from [d/2, d] with
d = min(cap, base * 2^(n-1)) (equal jitter), the next attempt time is
computed by PostgreSQL and the delay is kept in the job event.

Faults: the Faults port is async; relay reaches after_commit_before_publish
and after_publish_before_confirm, worker reaches after_claim_before_side_effect,
stall_after_claim (once, FAULT_STALL_SECONDS), after_s3_write_before_commit
and after_commit_before_ack. Crashes are os._exit(137).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-29 03:08:31 +03:00
co-authored by Claude Opus 5.5
parent f2242eb39d
commit ecb4827e75
14 changed files with 432 additions and 70 deletions
+11 -3
View File
@@ -10,6 +10,7 @@ from httpx import AsyncClient
from test_attachments import storage, trio, upload
from conftest import DATABASE, actor
from messenger.attachments.application.pipeline import TRANSIENT_ERROR
from messenger.attachments.application.ports import Rendition
from messenger.attachments.domain.errors import ImageTooDemanding
from messenger.attachments.domain.jobs import Job, Outcome, RetryPolicy
@@ -287,9 +288,16 @@ async def test_backoff_delays_the_next_attempt(client: AsyncClient) -> None:
"WHERE attachment_id = $1",
attachment_id,
)
assert 25 < row["wait"] <= 30
assert 20 < row["wait"] <= 22.5
(event,) = await rows(
"SELECT (detail->>'delay_seconds')::float8 AS delay FROM job_events "
"WHERE attachment_id = $1 AND kind = 'retry_scheduled'",
attachment_id,
)
assert event["delay"] == 22.5
class FailingFaults:
def reach(self, point: str) -> None:
raise Unavailable(point)
async def reach(self, point: str) -> None:
if point == TRANSIENT_ERROR:
raise Unavailable(point)