Propose the storage reconciler as an openspec change

Track 2 of grade 5: a one-off reconciler that merges the sorted bucket
listing with keyset pages of the attachments table, so a pass is linear
in time and holds one page per side in memory. It finds objects without
a row, ready rows without an object or with another size or digest, and
abandoned intents; by default it only reports, with --apply it deletes
old orphans after a row recheck, drops stale intents object first, and
quarantines broken ready rows instead of deleting them, so referenced
attachments survive and a restored object heals. A quarantined
attachment answers 404 on its content. An advisory lock keeps a single
pass at a time.

The design states the hypotheses on correctness and on the cost of a
pass, the reproducible method behind make reconcile-demo and make
reconcile-cost, and the acceptance criteria.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
This commit is contained in:
Artyom
2026-10-29 03:05:42 +03:00
co-authored by Claude Opus 5.5
parent d2744bc1ac
commit 148868bdfb
6 changed files with 291 additions and 0 deletions
@@ -0,0 +1,30 @@
## MODIFIED Requirements
### Requirement: Метаданные и скачивание только участникам
`GET /api/v1/attachments/{attachment_id}` SHALL возвращать `200 Attachment` участнику чата вложения. `GET /api/v1/attachments/{attachment_id}/content` SHALL возвращать участнику `200` с исходными байтами, `Content-Type` вложения и `Content-Length`, через API, без redirect, вне зависимости от заголовка `Accept`. Параметр `variant` SHALL принимать только `original` (по умолчанию). Посторонний, неизвестный id и ещё не готовое вложение SHALL получать `404` с кодом `not_found`, не раскрывающим существование вложения; невалидный UUID и неизвестный `variant` — `400`. Вложение, помещённое сверкой в карантин (capability `lab4-storage-reconciler`), SHALL отдавать метаданные как прежде, а `/content` SHALL отвечать `404` без обращения к S3, чтобы клиент не получил байты, расходящиеся с `sha256` метаданных. Все ответы, включая бинарный `200`, SHALL нести `X-Request-Id` и `X-Instance-Id`.
#### Scenario: Второй участник скачивает оригинал
- **WHEN** второй участник чата запрашивает `/content` загруженного вложения с `Accept: application/json`
- **THEN** ответ `200`, `Content-Type: image/png`, байты совпадают с загруженными, SHA-256 равен `sha256` метаданных
#### Scenario: Посторонний
- **WHEN** пользователь вне чата запрашивает метаданные или `/content`
- **THEN** оба ответа `404` с кодом `not_found`
#### Scenario: Неизвестный вариант
- **WHEN** запрошен `/content?variant=thumbnail`
- **THEN** ответ `400` с кодом `invalid_request`
#### Scenario: Объект пропал из хранилища
- **WHEN** метаданные готового вложения есть, а объекта в bucket нет
- **THEN** `/content` отвечает `404`, событие пишется в журнал без ключа объекта
#### Scenario: Вложение в карантине
- **WHEN** сверка поместила вложение в карантин из-за расхождения байтов с метаданными
- **THEN** метаданные отвечают `200` с прежними полями, `/content` — `404` с кодом `not_found`