fix: address upload-consistency verify findings

Mark a stale pending row in its own committed transaction before the
cleaner deletes the object, and let mark_ready promote only unmarked
rows, so a cleaner rollback after the object delete can no longer leave
a ready attachment without its object. Add fault checks for an unknown
COMMIT outcome, an upload outliving the grace period and a cleaner
failure after the object delete; fix the cleaner entrypoint in rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 21:27:47 +03:00
co-authored by Claude Opus 5.5
parent f2dc0b368a
commit 87c48b940b
20 changed files with 714 additions and 118 deletions
+8 -4
View File
@@ -50,8 +50,10 @@ paths:
Порог `expired_before`, решение «повтор или 409» и commit — в
сервисе. Ключ в исключения и логи не попадает.
- Repo вложений (лаба 4, design change `attachments`, решения 3, 4, 8):
- `attachment.py`: `insert_attachment`, `mark_ready` (`UPDATE … WHERE
status = 'pending' RETURNING`, `None` — строки `pending` нет),
- `attachment.py`: `insert_attachment` (`created_at` и `updated_at`
одним значением), `mark_ready` (`UPDATE … WHERE status = 'pending'
AND updated_at = created_at RETURNING`, `None` — строки `pending` нет
или уборщик пометил её к уборке),
`get_attachment`, `get_attachments` (до 10 строк по первичному
ключу). Значения `content_type` и `status` — `.value` enum на
записи и enum в DTO на чтении. Для уборщика (design change
@@ -59,8 +61,10 @@ paths:
`(created_at, id)`, `status = 'pending'`, `created_at <
older_than`, `LIMIT`), `lock_stale_pending` (те же условия по `id`,
`FOR UPDATE SKIP LOCKED`; `None` — строки нет, она `ready` или её
держат), `delete_attachment` (`RETURNING id`, `bool`); DTO —
`AttachmentInListDTO`. Статус в этих выражениях — константа
держат), `mark_removing` (пометка к уборке: `updated_at` = время
уборщика, позже `created_at`; без миграции, CHECK
`updated_after_created` выполняется), `delete_attachment`
(`RETURNING id`, `bool`); DTO — `AttachmentInListDTO`. Статус в этих выражениях — константа
(`literal(..., literal_execute=True)`), а не параметр: условие
частичного индекса `ix_attachments_pending_created_at` планировщик
доказывает только по константе, и общий план подготовленного