Files
mtusi2026lab4/openspec/changes/add-lab4-storage-reconciler/specs/lab4-attachments/spec.md
T
ArtyomandClaude Opus 5.5 148868bdfb 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
2026-10-29 03:05:42 +03:00

31 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 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`