docs: record async-attachments evidence and report

Evidence taken on ff1a83b. The report covers level 3; levels 4 and 5 are
closed by the following changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 08:30:46 +03:00
co-authored by Claude Opus 5.5
parent ff1a83b6ff
commit acc6584dd3
184 changed files with 30760 additions and 20 deletions
+45
View File
@@ -0,0 +1,45 @@
# Согласованность БД и S3 на рабочем стенде
- Команда: `python3 .claude/skills/run-mtusi-messenger/driver.py --port 8080 upload-consistency`
- Дата: 2026-10-31, 03:51 UTC; код выхода 0
- Commit: `ff1a83b`, рабочее дерево чистое
- Стенд: проект compose `mtusi-lab5`, собран `make run_docker` из `HEAD`
- Что показано: загрузка при замороженном S3 и со сбоем фиксации `queued` — 503; строки `pending` не видны (404); компенсация удалила объект staging; `cleaner --once` с grace 30 с убрал обе строки и объекты по ключу staging; объектов без строки нет; готовое вложение R цело
```text
upload with paused S3: 503 after 5.1 s
pending e2cb151f-c974-41e5-b34a-519674f94fd5: pending age 5 s key messenger/attachments/e2cb151f-c974-41e5-b34a-519674f94fd5/original
pending b09647d4-29c0-4701-8855-56a1f54c870f: pending age 0 s key messenger/attachments/b09647d4-29c0-4701-8855-56a1f54c870f/original
waiting 30 s for grace 30 s
cleaner --once (grace 30 s): exit 0
{"event": "Started cleaner", "instance_id": "9da70523aa0e", "module": "cleaner", "mode": "once", "interval_seconds": 60.0, "pending_grace_seconds": 30, "batch_size": 100, "live_upload_bound_seconds": 17.0, "once": true, "reconcile_interval_seconds": 3600.0, "reconcile_page_size": 1000, "reconcile_max_changes": 100, "reconcile_max_objects_per_second": 2000.0, "reconcile_apply": null, "reconcile_strategy": null, "reconcile_deep": null, "database_host": "postgres", "database_port": 5432, "database_name": "messenger", "database_pool_size": 1, "s3_host": "s3", "s3_port": 8333, "s3_bucket": "messenger", "level": "info", "timestamp": "2026-10-31T03:51:55.193513Z", "lineno": 229, "filename": "main.py", "func_name": "run"}
{"event": "Removed stale attachment", "instance_id": "9da70523aa0e", "module": "attachment_cleanup_service", "method": "clean_stale_pending", "attachment_id": "e2cb151f-c974-41e5-b34a-519674f94fd5", "object_key": "messenger/staging/e2cb151f-c974-41e5-b34a-519674f94fd5/original", "age_seconds": 42, "level": "info", "timestamp": "2026-10-31T03:51:55.381637Z", "lineno": 204, "filename": "attachment_cleanup.py", "func_name": "remove_stale_pending"}
{"event": "Removed stale attachment", "instance_id": "9da70523aa0e", "module": "attachment_cleanup_service", "method": "clean_stale_pending", "attachment_id": "b09647d4-29c0-4701-8855-56a1f54c870f", "object_key": "messenger/staging/b09647d4-29c0-4701-8855-56a1f54c870f/original", "age_seconds": 36, "level": "info", "timestamp": "2026-10-31T03:51:55.387529Z", "lineno": 204, "filename": "attachment_cleanup.py", "func_name": "remove_stale_pending"}
{"event": "Finished cleanup pass", "instance_id": "9da70523aa0e", "module": "attachment_cleanup_service", "method": "clean_stale_pending", "removed": 2, "skipped": 0, "interrupted_by": null, "duration_ms": 194, "level": "info", "timestamp": "2026-10-31T03:51:55.387656Z", "lineno": 127, "filename": "attachment_cleanup.py", "func_name": "clean_stale_pending"}
{"event": "Stopped cleaner", "instance_id": "9da70523aa0e", "module": "cleaner", "exit_code": 0, "level": "info", "timestamp": "2026-10-31T03:51:55.390025Z", "lineno": 273, "filename": "main.py", "func_name": "run"}
bucket messenger, prefix messenger/: 1159 objects, 1161 rows, 0 objects without a row
attachment R uploaded expected 202 got 202
attachment R processed expected ready got ready
upload with paused S3 expected 503 got 503
new pending rows (paused) expected 1 got 1
upload with queued failure expected 503 got 503
new pending rows (queued failure) expected 1 got 1
staging object after compensation expected absent got absent
staging object of the paused upload expected absent got absent
driver trigger left expected 0 got 0
metadata of pending e2cb151f expected 404 got 404
content of pending e2cb151f expected 404 got 404
message with e2cb151f expected 404 got 404
metadata of pending b09647d4 expected 404 got 404
content of pending b09647d4 expected 404 got 404
message with b09647d4 expected 404 got 404
cleaner --once exit code expected 0 got 0
row of e2cb151f expected absent got absent
object of e2cb151f expected absent got absent
row of b09647d4 expected absent got absent
object of b09647d4 expected absent got absent
objects without a row expected 0 got 0
R downloaded expected 200 got 200
R sha256 = uploaded expected yes got yes
PASS: pending rows are invisible, the queued failure is compensated, the cleaner removed both uploads, no object without a row, R intact
```
+68
View File
@@ -0,0 +1,68 @@
# Сценарий защиты лабы 5
- Команда: `python3 .claude/skills/run-mtusi-messenger/driver.py --port 8080 defense-scenario`
- Дата: 2026-10-31, 03:50 UTC; код выхода 0
- Commit: `ff1a83b` (ветка `feat/async-attachments`), рабочее дерево чистое
- Стенд: проект compose `mtusi-lab5`, собран `make run_docker` из `HEAD`: HAProxy, две реплики API, worker, cleaner, PostgreSQL, Valkey, S3, RabbitMQ
- Порядок действий (`README.md`, «Сценарий защиты», шаги 1–3): worker остановлен → загрузка 202 → сообщение с вложением 201 → скачивание 409 → текст 201 → рестарт API и хранилищ с сохранением volumes → worker запущен → `ready`, оригинал и thumbnail
- Токенов и секретов в выводе нет; пользователи и чат синтетические
```text
fixture sample.png: 111817 bytes, sha256 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
docker compose stop worker: 0
upload sample.png: 202
attachment id 730db74b-8e88-4ed4-bb69-0fa821f8d41e, via 3ce76b35e8aa
snapshot status: queued
message with the attachment: 201
message id 9716846f-448b-41c4-aebd-7b83e3264964
download before processing: 409
text message: 201
text message id d102d380-6f95-4712-96fb-721030ed2bf6
job in the queue before restart: yes
queue consumers before restart: 0
scripts/restart.sh: 0
LB ready after restart: yes
job in the queue after restart: yes
metadata after restart (same session): 200
status after restart: queued
docker compose start worker: 0
attachment status: ready
download original: 200
original sha256 = uploaded: yes
download thumbnail: 200
thumbnail content type: image/jpeg
thumbnail by SOF: (256, 160)
thumbnail sha256 = metadata: yes
history after restart: 200
history keeps both messages: yes
containers: StartedAt before -> after
mtusi-lab5-api-1: 2026-10-31T03:49:55.670098888Z -> 2026-10-31T03:50:35.309647378Z
mtusi-lab5-api-2: 2026-10-31T03:49:55.607322638Z -> 2026-10-31T03:50:35.244859586Z
mtusi-lab5-rabbitmq-1: 2026-10-31T03:49:47.262600342Z -> 2026-10-31T03:50:09.308230255Z
docker compose stop worker expected 0 got 0
upload sample.png expected 202 got 202
snapshot status expected queued got queued
message with the attachment expected 201 got 201
download before processing expected 409 got 409
text message expected 201 got 201
job in the queue before restart expected yes got yes
queue consumers before restart expected 0 got 0
scripts/restart.sh expected 0 got 0
LB ready after restart expected yes got yes
job in the queue after restart expected yes got yes
metadata after restart (same session) expected 200 got 200
status after restart expected queued got queued
docker compose start worker expected 0 got 0
attachment status expected ready got ready
download original expected 200 got 200
original sha256 = uploaded expected yes got yes
download thumbnail expected 200 got 200
thumbnail content type expected image/jpeg got image/jpeg
thumbnail by SOF expected (256, 160) got (256, 160)
thumbnail sha256 = metadata expected yes got yes
history after restart expected 200 got 200
history keeps both messages expected yes got yes
api and rabbitmq restarted expected yes got yes
PASS: the file is accepted while the worker is stopped and becomes ready after the restart
worker running at the end: yes
```
+66
View File
@@ -0,0 +1,66 @@
# Принявшая реплика остановлена
- Команда: `python3 .claude/skills/run-mtusi-messenger/driver.py --port 8080 attachment-failover --mode stop`, затем `make replicas` и то же с `--mode kill`
- Дата: 2026-10-31, 03:51 UTC; оба прогона — код выхода 0
- Commit: `ff1a83b`, рабочее дерево чистое
- Стенд: проект compose `mtusi-lab5`, собран `make run_docker` из `HEAD`
- Сценарий: `attachments` «Принявшая реплика остановлена»
## Режим stop
```text
mode: stop; fixture sample.png: 111817 bytes
docker compose ps (before):
NAME STATUS
mtusi-lab5-api-1 Up 28 seconds (healthy)
mtusi-lab5-api-2 Up 28 seconds (healthy)
mtusi-lab5-cleaner-1 Up About a minute
mtusi-lab5-haproxy-1 Up 27 seconds (healthy)
mtusi-lab5-postgres-1 Up 55 seconds (healthy)
mtusi-lab5-rabbitmq-1 Up 15 seconds (healthy)
mtusi-lab5-s3-1 Up 35 seconds (healthy)
mtusi-lab5-valkey-1 Up 55 seconds (healthy)
mtusi-lab5-worker-1 Up 21 seconds
sha256 uploaded: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
sha256 downloaded: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
docker compose ps (after):
NAME STATUS
mtusi-lab5-api-1 Up 1 second (healthy)
mtusi-lab5-api-2 Up 31 seconds (healthy)
mtusi-lab5-cleaner-1 Up About a minute
mtusi-lab5-haproxy-1 Up 31 seconds (healthy)
mtusi-lab5-postgres-1 Up 58 seconds (healthy)
mtusi-lab5-rabbitmq-1 Up 18 seconds (healthy)
mtusi-lab5-s3-1 Up 38 seconds (healthy)
mtusi-lab5-valkey-1 Up 58 seconds (healthy)
mtusi-lab5-worker-1 Up 25 seconds
step expected got x-instance-id
alice uploads 202 202 3ce76b35e8aa
attachment is ready ready ready
alice sends message 201 201 f83660c720d2
stop-one.sh stop 0 0 3ce76b35e8aa
bob downloads 200 200 f83660c720d2
bob reads metadata 200 200 f83660c720d2
eve reads metadata 404 404 f83660c720d2
eve downloads 404 404 f83660c720d2
make replicas 0 0
LB slots UP 2 2
PASS: accepted by 3ce76b35e8aa, served by f83660c720d2 after stop, sha256 matches, outsider gets 404
```
## Режим kill
```text
step expected got x-instance-id
alice uploads 202 202 3ce76b35e8aa
attachment is ready ready ready
alice sends message 201 201 f83660c720d2
stop-one.sh kill 0 0 3ce76b35e8aa
bob downloads 200 200 f83660c720d2
bob reads metadata 200 200 f83660c720d2
eve reads metadata 404 404 f83660c720d2
eve downloads 404 404 f83660c720d2
make replicas 0 0
LB slots UP 2 2
PASS: accepted by 3ce76b35e8aa, served by f83660c720d2 after kill, sha256 matches, outsider gets 404
```
+95
View File
@@ -0,0 +1,95 @@
# Вложения: метаданные, байты и ограничения обработки
- Команда: `python3 .claude/skills/run-mtusi-messenger/driver.py --port 8080 attachment-storage`
- Дата: 2026-10-31, 03:50 UTC; код выхода 0
- Commit: `ff1a83b`, рабочее дерево чистое
- Стенд: проект compose `mtusi-lab5`, собран `make run_docker` из `HEAD`
- Сценарии: `attachments` «Байты не в БД и не на диске API», `data-storage` «Ограничения обработки в схеме» (пробы в откатываемой транзакции)
```text
columns of attachment tables:
attachment_jobs id uuid
attachment_jobs attachment_id uuid
attachment_jobs pipeline_version integer
attachment_jobs state text
attachment_jobs attempt integer
attachment_jobs last_error_code text
attachment_jobs next_attempt_at timestamp with time zone
attachment_jobs lease_expires_at timestamp with time zone
attachment_jobs published_at timestamp with time zone
attachment_jobs updated_at timestamp with time zone
attachment_jobs finished_at timestamp with time zone
attachment_jobs created_at timestamp with time zone
attachment_variants attachment_id uuid
attachment_variants pipeline_version integer
attachment_variants variant text
attachment_variants object_key text
attachment_variants content_type text
attachment_variants size_bytes integer
attachment_variants width integer
attachment_variants height integer
attachment_variants sha256 bytea
attachment_variants created_at timestamp with time zone
attachments id uuid
attachments chat_id uuid
attachments owner_id uuid
attachments filename text
attachments content_type text
attachments size_bytes integer
attachments sha256 bytea
attachments object_key text
attachments status text
attachments updated_at timestamp with time zone
attachments created_at timestamp with time zone
attachments lost_at timestamp with time zone
attachments staging_key text
attachments error_code text
message_attachments message_id uuid
message_attachments position smallint
message_attachments attachment_id uuid
message_attachments created_at timestamp with time zone
upload via f83660c720d2: object_key messenger/attachments/3fb40419-8f7a-467a-afdf-2a4fc0153f5c/original, staging_key messenger/staging/3fb40419-8f7a-467a-afdf-2a4fc0153f5c/original
sha256 uploaded 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75, downloaded by a member (200) 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
upload via 3ce76b35e8aa: object_key messenger/attachments/40d1bf94-3ac9-417d-89ed-07430e5f4b11/original, staging_key messenger/staging/40d1bf94-3ac9-417d-89ed-07430e5f4b11/original
sha256 uploaded 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75, downloaded by a member (200) 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
constraint probes (rolled back):
second job of the version: 23505 uq_attachment_jobs_attachment_id_pipeline_version
second variant of the name: 23505 pk_attachment_variants
error_code on not failed: 23514 ck_attachments_error_code_failed
docker diff 3ce76b35e8aa: 2 changes
C /app
A /app/config.toml
docker diff f83660c720d2: 2 changes
C /app
A /app/config.toml
docker diff f5a34a124c60: 2 changes
C /app
A /app/config.toml
bytea columns expected attachment_variants.sha256,attachments.sha256 got attachment_variants.sha256,attachments.sha256
octet_length(sha256) expected 32 got 32
object_key form expected messenger/attachments/3fb40419-8f7a-467a-afdf-2a4fc0153f5c/original got messenger/attachments/3fb40419-8f7a-467a-afdf-2a4fc0153f5c/original
staging_key form expected messenger/staging/3fb40419-8f7a-467a-afdf-2a4fc0153f5c/original got messenger/staging/3fb40419-8f7a-467a-afdf-2a4fc0153f5c/original
filename not in key expected no got no
thumbnail in bucket expected yes got yes
anonymous GET of the thumbnail expected 403 got 403
object in bucket, bytes expected 111817 got 111817
anonymous GET of the key expected 403 got 403
downloaded sha256 = uploaded expected yes got yes
object_key form expected messenger/attachments/40d1bf94-3ac9-417d-89ed-07430e5f4b11/original got messenger/attachments/40d1bf94-3ac9-417d-89ed-07430e5f4b11/original
staging_key form expected messenger/staging/40d1bf94-3ac9-417d-89ed-07430e5f4b11/original got messenger/staging/40d1bf94-3ac9-417d-89ed-07430e5f4b11/original
filename not in key expected no got no
thumbnail in bucket expected yes got yes
anonymous GET of the thumbnail expected 403 got 403
object in bucket, bytes expected 111817 got 111817
anonymous GET of the key expected 403 got 403
downloaded sha256 = uploaded expected yes got yes
probe: second job of the version expected 23505 uq_attachment_jobs_attachment_id_pipeline_version got 23505 uq_attachment_jobs_attachment_id_pipeline_version
probe: second variant of the name expected 23505 pk_attachment_variants got 23505 pk_attachment_variants
probe: error_code on not failed expected 23514 ck_attachments_error_code_failed got 23514 ck_attachments_error_code_failed
jobs | variants after the probes expected 1|1 got 1|1
original files in 3ce76b35e8aa expected 0 got 0
original files in f83660c720d2 expected 0 got 0
original files in f5a34a124c60 expected 0 got 0
sha256 of the fixture: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
PASS: metadata in PostgreSQL, bytes only in the private bucket messenger, none in the API containers
```