docs: add upload-consistency verify evidence and report

Capture the cleaner pass under a paused S3 (row stays marked pending,
next pass removes it), re-run failure checks (32 of 32 with red runs of
the new checks), student tests and the isolated run on 87c48b9, and
describe the marked three-step cleanup and its rolling-update window in
the report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 21:42:31 +03:00
co-authored by Claude Opus 5.5
parent 87c48b940b
commit 6551839807
9 changed files with 296 additions and 130 deletions
+106 -50
View File
@@ -1,9 +1,10 @@
# `make failure_checks`: проверки отказов с уборщиком и согласованностью БД и S3
- Дата: 2026-10-21, 03:20:17–03:23:44 UTC.
- Commit: `5b42bd2` (change `upload-consistency`: компенсация в загрузке,
уборщик, hook и тесты отказов); незакоммичены только файлы `evidence/`
этого change.
- Дата: 2026-10-21, 18:30:28–18:34:30 UTC.
- Commit: `87c48b9` (правки change `upload-consistency` по verify: пометка
строки уборщиком до удаления объекта, режимы hook `commit`, `outlive`,
`undeletable` и три новых теста); рабочее дерево чистое (`git status`
пуст), образ собран из него.
- Стенд отказов: проект `mtusi-lab4-failures` — свои PostgreSQL, Valkey
и S3 (с bootstrap, пользователи `api` и `cleaner`), порты хранилищ не
публикуются; уборщик `cleaner` с grace 20 с и интервалом 1 с
@@ -11,16 +12,16 @@
обычный — с `MAX_UPLOAD_BYTES=1` и `MAX_IMAGE_PIXELS=1` в окружении, и
«тесный» (сроки сессии и ключа 2 с, пул 1). Рабочий стенд `mtusi-lab4`
в это время запущен. Docker Desktop 29.9.1, Apple M3 Pro.
- Прежний снимок этого файла (commit `e1f8531`, change `attachments`) —
24 из 24 за 94 с; сейчас 29 из 29 за 190 с: пять новых тестов и три
изменённых (design change `upload-consistency`, решение 10).
- Прежний снимок этого файла (commit `5b42bd2`) — 29 из 29 за 190 с;
сейчас 32 из 32 за 224 с: три теста по замечаниям verify W1–W3 (design
change `upload-consistency`, «Уточнения apply», п. 16–18).
## Итог: код 0, 29 из 29
## Итог: код 0, 32 из 32
Вывод сборки образа (BuildKit), строки `Container …` compose и записи
alembic о прежних пяти ревизиях опущены;
строки `platform` и `rootdir` pytest с путём к рабочему каталогу
заменены на `…`.
Вывод сборки образа (BuildKit), строки `Container …` compose, записи
alembic о прежних пяти ревизиях и журналы контейнеров стенда опущены;
путь к рабочему каталогу в строках `platform` и `rootdir` pytest заменён
на `…`.
```
$ make failure_checks
@@ -29,7 +30,7 @@ python3 student-tests/run_failures.py
[failure_checks] build image
[failure_checks] start postgres, valkey and s3
[failure_checks] migrations
{"event": "Running upgrade ef25d50b01a8 -> 739b8f04d5fb, added pending attachments index", "instance_id": "7dc2d0220d90", "level": "info", "logger": "alembic.runtime.migration", "timestamp": "2026-10-21T03:20:24.135091Z"}
{"event": "Running upgrade ef25d50b01a8 -> 739b8f04d5fb, added pending attachments index", "instance_id": "16f65334b59e", "level": "info", "logger": "alembic.runtime.migration", "timestamp": "2026-10-21T18:30:36.141892Z"}
[failure_checks] s3 bootstrap
s3-bootstrap-1 | s3-bootstrap: bucket messenger created
s3-bootstrap-1 | s3-bootstrap: user api created
@@ -38,64 +39,71 @@ s3-bootstrap-1 | s3-bootstrap: checks passed (api key put/get; cleaner key get/
s3-bootstrap-1 exited with code 0
[failure_checks] start cleaner: grace 20 s, interval 1 s
[failure_checks] start api containers
[failure_checks] ready: api=http://127.0.0.1:65050 tight=http://127.0.0.1:65068
[failure_checks] ready: api=http://127.0.0.1:57436 tight=http://127.0.0.1:57440
[failure_checks] pytest -m fault
platform darwin -- Python 3.12.12, pytest-9.1.1, pluggy-1.6.0 -- …
collecting ... collected 226 items / 197 deselected / 29 selected
collecting ... collected 229 items / 197 deselected / 32 selected
student-tests/test_failures.py::test_expired_token PASSED [ 3%]
student-tests/test_failures.py::test_use_does_not_extend_session PASSED [ 6%]
student-tests/test_failures.py::test_token_while_database_stopped PASSED [ 10%]
student-tests/test_failures.py::test_members_failure_rolls_back_chat PASSED [ 13%]
student-tests/test_failures.py::test_database_stopped_and_back PASSED [ 17%]
student-tests/test_failures.py::test_pool_exhausted PASSED [ 20%]
student-tests/test_failures.py::test_connection_limit_reached PASSED [ 24%]
student-tests/test_failures.py::test_pool_keeps_connections PASSED [ 27%]
student-tests/test_failures.py::test_readiness_without_database PASSED [ 31%]
student-tests/test_failures.py::test_readiness_without_cache PASSED [ 34%]
student-tests/test_failures.py::test_readiness_without_object_storage[stop] PASSED [ 37%]
student-tests/test_failures.py::test_readiness_without_object_storage[pause] PASSED [ 41%]
student-tests/test_failures.py::test_flush_cache PASSED [ 44%]
student-tests/test_failures.py::test_valkey_stopped PASSED [ 48%]
student-tests/test_failures.py::test_valkey_paused PASSED [ 51%]
student-tests/test_failures.py::test_valkey_back PASSED [ 55%]
student-tests/test_failures.py::test_message_failure_keeps_key_free PASSED [ 58%]
student-tests/test_failures.py::test_database_outage_keeps_key_free PASSED [ 62%]
student-tests/test_failures.py::test_key_free_after_ttl PASSED [ 65%]
student-tests/test_failures.py::test_upload_with_object_storage_stopped PASSED [ 68%]
student-tests/test_failures.py::test_rejected_uploads_leave_nothing PASSED [ 72%]
student-tests/test_failures.py::test_metadata_insert_failure PASSED [ 75%]
student-tests/test_failures.py::test_interrupted_body PASSED [ 79%]
student-tests/test_failures.py::test_ready_failure_compensated PASSED [ 82%]
student-tests/test_failures.py::test_killed_between_put_and_ready PASSED [ 86%]
student-tests/test_failures.py::test_cleaner_survives_outages PASSED [ 89%]
student-tests/test_failures.py::test_token_while_database_stopped PASSED [ 9%]
student-tests/test_failures.py::test_members_failure_rolls_back_chat PASSED [ 12%]
student-tests/test_failures.py::test_database_stopped_and_back PASSED [ 15%]
student-tests/test_failures.py::test_pool_exhausted PASSED [ 18%]
student-tests/test_failures.py::test_connection_limit_reached PASSED [ 21%]
student-tests/test_failures.py::test_pool_keeps_connections PASSED [ 25%]
student-tests/test_failures.py::test_readiness_without_database PASSED [ 28%]
student-tests/test_failures.py::test_readiness_without_cache PASSED [ 31%]
student-tests/test_failures.py::test_readiness_without_object_storage[stop] PASSED [ 34%]
student-tests/test_failures.py::test_readiness_without_object_storage[pause] PASSED [ 37%]
student-tests/test_failures.py::test_flush_cache PASSED [ 40%]
student-tests/test_failures.py::test_valkey_stopped PASSED [ 43%]
student-tests/test_failures.py::test_valkey_paused PASSED [ 46%]
student-tests/test_failures.py::test_valkey_back PASSED [ 50%]
student-tests/test_failures.py::test_message_failure_keeps_key_free PASSED [ 53%]
student-tests/test_failures.py::test_database_outage_keeps_key_free PASSED [ 56%]
student-tests/test_failures.py::test_key_free_after_ttl PASSED [ 59%]
student-tests/test_failures.py::test_upload_with_object_storage_stopped PASSED [ 62%]
student-tests/test_failures.py::test_rejected_uploads_leave_nothing PASSED [ 65%]
student-tests/test_failures.py::test_metadata_insert_failure PASSED [ 68%]
student-tests/test_failures.py::test_interrupted_body PASSED [ 71%]
student-tests/test_failures.py::test_ready_failure_compensated PASSED [ 75%]
student-tests/test_failures.py::test_killed_between_put_and_ready PASSED [ 78%]
student-tests/test_failures.py::test_ready_commit_outcome_unknown PASSED [ 81%]
student-tests/test_failures.py::test_upload_outlives_grace PASSED [ 84%]
student-tests/test_failures.py::test_cleaner_failure_after_object_delete PASSED [ 87%]
student-tests/test_failures.py::test_cleaner_survives_outages PASSED [ 90%]
student-tests/test_failures.py::test_object_storage_stopped PASSED [ 93%]
student-tests/test_failures.py::test_environment_does_not_change_limits PASSED [ 96%]
student-tests/test_failures.py::test_object_storage_paused PASSED [100%]
================ 29 passed, 197 deselected in 190.40s (0:03:10) ================
[failure_checks] postgres log: 418 lines, crash markers 0; "too many clients" 31, "administrator command" 138
================ 32 passed, 197 deselected in 223.70s (0:03:43) ================
[failure_checks] postgres log: 424 lines, crash markers 0; "too many clients" 20, "administrator command" 137
[failure_checks] cleanup
[failure_checks] results: {'fault': 0, 'postgres': 0}
exit=0
```
Вся команда — 242 с (18:30:28–18:34:30). «too many clients» и
«administrator command» — следы проверок «Предел соединений PostgreSQL
исчерпан» (`fill-connections`) и остановок PostgreSQL, признаков
аварийного перезапуска нет.
## Уборка и рабочий стенд
```
$ docker inspect -f '{{.Name}} {{.State.StartedAt}}' $(docker compose ps -q) # до и после — одинаково
/mtusi-lab4-api-7 2026-10-21T03:02:55.127674845Z
/mtusi-lab4-api-8 2026-10-21T03:03:45.600925174Z
/mtusi-lab4-cleaner-1 2026-10-21T03:14:42.071533631Z
/mtusi-lab4-haproxy-1 2026-10-21T03:02:55.18557422Z
/mtusi-lab4-postgres-1 2026-10-21T03:02:33.641433585Z
/mtusi-lab4-s3-1 2026-10-21T03:02:48.641611592Z
/mtusi-lab4-valkey-1 2026-10-21T03:02:33.670361668Z
/mtusi-lab4-api-11 2026-10-21T18:28:46.759887001Z
/mtusi-lab4-api-12 2026-10-21T18:28:49.979426419Z
/mtusi-lab4-cleaner-1 2026-10-21T18:29:04.322478592Z
/mtusi-lab4-haproxy-1 2026-10-21T03:30:26.991596804Z
/mtusi-lab4-postgres-1 2026-10-21T03:30:05.896306378Z
/mtusi-lab4-s3-1 2026-10-21T03:30:20.918287843Z
/mtusi-lab4-valkey-1 2026-10-21T03:30:05.925240128Z
left: containers 0, volumes 0
```
- `StartedAt` всех контейнеров `mtusi-lab4`, в том числе его уборщика,
до и после совпали (`diff` пуст): рабочий стенд не тронут.
до и после совпали: рабочий стенд не тронут.
- У проекта `mtusi-lab4-failures` не осталось ни контейнеров, ни volumes.
## Что проверяют проверки вложений и уборщика
@@ -136,6 +144,23 @@ left: containers 0, volumes 0
`pending` и объект → `kill-api` (docker kill обычного API) → 201 до
клиента не дошёл, строка и объект на месте → `start-api` → после grace
ни строки, ни объекта, объектов без строки нет; загрузка — 201.
- «Исход фиксации неизвестен» (`test_ready_commit_outcome_unknown`,
verify W2): отложенный триггер ограничения роняет COMMIT перевода в
`ready` (08006) → 503, строка `pending`, по API не видна, **объект на
месте** сразу после ответа (исход для API неизвестен, компенсации
нет); не позже G + I + 5 с ни строки, ни объекта, объектов без строки
нет.
- «Загрузка дольше grace» (`test_upload_outlives_grace`, verify W3):
строка вставлена на час старше (`created_at` и `updated_at` вместе),
перевод в `ready` ждёт в триггере уровня оператора `BEFORE UPDATE OF
status`, пока уборщик стенда не уберёт строку → 503, а не 201 и не 500;
ни строки, ни объекта, объектов без строки нет.
- «Сбой уборки после удаления объекта»
(`test_cleaner_failure_after_object_delete`, verify W1): то же, но
удаление строки падает с 08006 уже после удаления объекта → 503, а не
201; строка `pending` (помечена уборщиком), по API не видна, вложений
`ready` без объекта нет; после снятия триггера следующий проход
убирает строку, объектов без строки нет.
- «S3 недоступен во время уборки», «БД недоступна во время уборки»,
«Готовые вложения не тронуты» (`test_cleaner_survives_outages`):
готовое вложение R; S3 остановлен → загрузка 503 (строка X);
@@ -175,3 +200,34 @@ E AssertionError: attachment 359413af-… is not cleaned 26.4s aft
«Сбой записи метаданных», «Обрыв передачи тела» и «Незавершённая
загрузка не видна» прежний код уже выполнял — эти тесты закрепляют
поведение.
## Красные прогоны тестов по замечаниям verify (2026-10-21)
Новые тесты и режимы hook против кода `f2dc0b3` (рабочее дерево до
правки уборщика; `make failure_checks FAULT_ARGS='-k "commit_outcome or
outlives or failure_after_object"'`):
```
student-tests/test_failures.py::test_ready_commit_outcome_unknown PASSED [ 33%]
student-tests/test_failures.py::test_upload_outlives_grace PASSED [ 66%]
student-tests/test_failures.py::test_cleaner_failure_after_object_delete FAILED [100%]
E AssertionError: POST /api/v1/chats/0ba258db-…/attachments: expected 503; got 201 {"id":"2dd20f36-…", …}
================= 1 failed, 2 passed, 226 deselected in 31.21s =================
```
- W1 на прежнем коде — 201 за 4,6 с: уборщик удалил объект, его
транзакция откатилась на DELETE строки, и ждавший `mark_ready`
перевёл строку в `ready` без объекта.
- W2 и W3 на прежнем коде зелёные: эти ветки были верны, тесты их
закрепляют. Краснеют на временных регрессиях (правки возвращены, `git
diff src/core/services/attachment.py` пуст): «компенсация на любой
сбой» и возврат `RuntimeError` вместо 503
(`FAULT_ARGS='-k "commit_outcome or outlives"'`):
```
student-tests/test_failures.py::test_ready_commit_outcome_unknown FAILED [ 50%]
student-tests/test_failures.py::test_upload_outlives_grace FAILED [100%]
E AssertionError: assert '2b1ccadf-…' in set() # объект удалён после неизвестного COMMIT
E AssertionError: POST /api/v1/chats/e6a74a0b-…/attachments: expected 503; got 500 {"error":{"code":"internal_error","message":"Internal server error","request_id":"…"}}
====================== 2 failed, 227 deselected in 3.49s =======================
```