feat: limit accepted attachment work and add queue overload bench

Reject uploads with 429 at [uploads] max_unfinished_jobs, counted by the existing partial indexes in the membership block. Add the bench_queue profile, hypotheses H1-H9 and the fifth failure-stand API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-01 07:30:08 +03:00
co-authored by Claude Opus 5.5
parent 5b5f59aa3b
commit d667fa3c57
53 changed files with 5043 additions and 122 deletions
+58
View File
@@ -880,6 +880,64 @@ async def check_count_and_mark_published(new_uow: NewUow) -> None:
assert other.published_at is None
async def check_count_unfinished(new_uow: NewUow) -> None:
world = await _world(new_uow)
async def count(limit: int) -> int:
async with new_uow() as uow:
return await uow.jobs.count_unfinished(limit=limit)
assert await count(1) == 0
# завершённые не считаются
await _failed_job(new_uow, world)
succeeded = await _started_job(new_uow, world)
async with new_uow() as uow:
await uow.jobs.finish_job(
job_id=succeeded.id,
state=AttachmentJobState.SUCCEEDED,
reason=None,
now=at(1),
)
await uow.commit()
assert await count(10) == 0
# queued без отметки
outbox = await _job(new_uow, world)
assert await count(10) == 1
# queued с отметкой
published = await _job(new_uow, world)
async with new_uow() as uow:
await uow.jobs.mark_published(job_ids=[published.id], now=at(1))
await uow.commit()
assert await count(10) == 2
# processing
await _started_job(new_uow, world, lease_expires_at=at(100))
assert await count(10) == 3
# queued со сроком следующей попытки: ждёт, но считается
retrying = await _started_job(new_uow, world, lease_expires_at=at(100))
async with new_uow() as uow:
assert await uow.jobs.return_to_queued(
job_id=retrying.id,
attempt=retrying.attempt,
reason=AttachmentJobReason.STORAGE_UNAVAILABLE,
next_attempt_at=at(1000),
now=at(1),
)
await uow.commit()
assert await count(10) == 4
# решение «не меньше предела»: ниже, на пределе и выше
assert await count(5) < 5
assert await count(4) >= 4
assert await count(3) >= 3
# одна группа больше предела: счёт обрывается, решение то же
assert outbox is not None
extra = [await _job(new_uow, world) for _ in range(3)]
assert len(extra) == 3
assert await count(2) >= 2
# в outbox теперь 5 строк (retrying с outbox), две другие группы по одной
assert await count(3) == 3 + 1 + 1
assert await count(1) == 3
async def check_recover_expired_leases(new_uow: NewUow) -> None:
world = await _world(new_uow)
expired = await _started_job(new_uow, world, lease_expires_at=at(-5))