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
+18
View File
@@ -226,6 +226,23 @@ class Idempotency(BaseModel):
ttl_seconds: int = Field(default=86400, gt=0)
class Cleaner(BaseModel):
"""Уборщик незавершённых загрузок (`python -m src.cleaner`).
Значения — из `config.toml`, разовая подмена — окружением
`CLEANER__*`. Реплики API секцию не читают. Grace сравнивает с
границей живой загрузки сам уборщик при старте (design change
`upload-consistency`, решение 4).
"""
# секунды между проходами
interval_seconds: float = Field(default=60, gt=0)
# секунды: моложе строку pending уборщик не трогает (grace period)
pending_grace_seconds: int = Field(default=900, gt=0)
# строк pending в одной выборке кандидатов
batch_size: int = Field(default=100, ge=1)
class Settings(BaseSettings):
model_config = SettingsConfigDict(
extra="ignore",
@@ -241,6 +258,7 @@ class Settings(BaseSettings):
cache: Cache = Cache()
s3: S3 = S3()
idempotency: Idempotency = Idempotency()
cleaner: Cleaner = Cleaner()
@classmethod
def settings_customise_sources(