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
+10
View File
@@ -52,6 +52,16 @@ services:
restart: "no"
ports: !reset []
# уборщик незавершённых загрузок (design change upload-consistency,
# решение 9) описан, как s3, и тоже не запускается: старт стенда
# перечисляет сервисы, реплики — с --no-deps. Если его всё же запустят —
# образ стенда, без config.toml рабочего стенда, без перезапуска
cleaner:
container_name: mtusi-bench-cleaner
image: mtusi-messenger:bench
restart: "no"
volumes: !reset []
migrate:
image: mtusi-messenger:bench
# без config.toml рабочего стенда: настройки — окружение и дефолты
+5 -1
View File
@@ -1211,7 +1211,9 @@ def compose_env(profile: Profile) -> dict[str, str]:
Секреты S3 compose требует при разборе файла (`:?` в
`docker-compose.yml`), хотя профили лаб 2–3 сервер S3 не запускают:
реплики API получают ключи, но к S3 не обращаются (design change
`s3-storage`, решение 9).
`s3-storage`, решение 9). С уборщиком (design change
`upload-consistency`, решение 9) — ещё ключи его пользователя: сервис
`cleaner` описан, но профили его не запускают.
"""
env = {key: os.environ[key] for key in HOST_ENV if key in os.environ}
return {
@@ -1224,6 +1226,8 @@ def compose_env(profile: Profile) -> dict[str, str]:
"S3_JWT_SIGNING_KEY": secrets.token_hex(32),
"S3_API_ACCESS_KEY": secrets.token_hex(10),
"S3_API_SECRET_KEY": secrets.token_hex(20),
"S3_CLEANER_ACCESS_KEY": secrets.token_hex(10),
"S3_CLEANER_SECRET_KEY": secrets.token_hex(20),
"BENCH_APP_CPUS": profile.cpus,
"BENCH_APP_MEMORY": profile.memory,
"BENCH_DB_CPUS": profile.db_cpus,