feat: compensate failed uploads and clean stale pending attachments

- upload: delete the stored object when ready fails before COMMIT or the
  pending row is gone (503 instead of 500); unknown COMMIT outcome keeps it
- cleaner service (python -m src.cleaner): stale pending rows older than
  grace (900 s, must exceed 17 s live-upload bound) under FOR UPDATE SKIP
  LOCKED, object before row, own S3 user with read/delete only
- shared session_scope for API and cleaner; early_stop process name
- partial index on pending attachments, CREATE INDEX CONCURRENTLY
- s3-bootstrap: cleaner user, policy and checks; make env_setup appends
  missing template variables to an existing .env
- failure checks: cleaner on the failure stand, id-list hook actions,
  five new and three updated tests; driver upload-consistency
- sync upload-consistency deltas into main specs (storage-consistency)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 06:10:37 +03:00
co-authored by Claude Opus 5.5
parent 450b091ae3
commit 5b42bd2891
54 changed files with 2958 additions and 411 deletions
+8 -1
View File
@@ -1,4 +1,9 @@
from .attachment import AttachmentContentDTO, AttachmentFullDTO
from .attachment import (
AttachmentContentDTO,
AttachmentFullDTO,
AttachmentInListDTO,
CleanupPassDTO,
)
from .chat import ChatFullDTO, ChatPageDTO
from .idempotency import IdempotencyRecordDTO
from .message import MessageFullDTO, MessagePageDTO
@@ -8,8 +13,10 @@ from .user import UserCredentialsDTO, UserFullDTO
__all__ = [
"AttachmentContentDTO",
"AttachmentFullDTO",
"AttachmentInListDTO",
"ChatFullDTO",
"ChatPageDTO",
"CleanupPassDTO",
"CurrentSessionDTO",
"IdempotencyRecordDTO",
"MessageFullDTO",
+27
View File
@@ -27,6 +27,33 @@ class AttachmentFullDTO:
updated_at: datetime
@dataclass(frozen=True, slots=True)
class AttachmentInListDTO:
"""Незавершённая загрузка для уборщика: `id`, ключ объекта и время
записи строки — ровно то, что нужно проходу (design change
`upload-consistency`, решение 3)."""
id: UUID
object_key: str
created_at: datetime
@dataclass(frozen=True, slots=True)
class CleanupPassDTO:
"""Итог прохода уборщика.
`skipped` — кандидаты, которых к блокировке уже не было: их убрал или
держит другой процесс, либо они стали `ready`. `interrupted_by` —
причина прерывания (`object_storage`, `database`, `stop` — сигнал
остановки процесса) или `None`, если проход дошёл до конца.
"""
removed: int
skipped: int
interrupted_by: str | None
duration_ms: int
@dataclass(frozen=True, slots=True)
class AttachmentContentDTO:
"""Оригинал вложения на отдачу потоком.