Files
mtusi2026lab3/evidence/idempotency/config-checks.md
T
ricoromaandClaude Opus 5.5 c5840bfaa8 docs: add idempotency and X-Instance-Id evidence to the report
- evidence for replay, conflict, replay through a new API process and
  after restarting API and storages, keys table, key race,
  X-Instance-Id in responses and logs, explicit and invalid
  instance_id and key TTL, test runs
- stand evidence: make wipe_data leaves the lab 2 volume intact, build
  from a fresh git clone passes smoke, bench restore stage sends with
  Idempotency-Key
- REPORT.md: X-Instance-Id, idempotency design, IDEMPOTENCY_TTL_SECONDS
  mapping, limitations and evidence rows
- tasks.md: mark the change tasks done, add follow-ups from verify

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 17:08:47 +03:00

78 lines
4.3 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.
# Настройки `instance_id` и срока ключа: явное и недопустимое значение
| | |
|---|---|
| Спеки | `service-configuration` «Идентификатор экземпляра» — «Явное значение», «Недопустимое значение»; «Срок ключа идемпотентности» — «Срок ключа не число» |
| Change | `instance-id-idempotency`, доработка по `/opsx:verify` |
| Дата | 2026-10-10 14:00:50–14:01:10 UTC |
| Commit | `af4bca0` |
| Стенд | API в консоли (`APP__RUN_MODE=console`, `uv run python -m src`) на `127.0.0.1:8091` и `:8092`; Postgres и Valkey — рабочий стенд `mtusi-lab3`; файлы настроек не менялись, значения — только из окружения |
| Хост | macOS arm64 |
## Явное значение: `APP__INSTANCE_ID=api-a`
```text
$ APP__RUN_MODE=console APP__INSTANCE_ID=api-a APP__PORT=8091 uv run python -m src > console_api_a.log 2>&1 &
$ curl -sD - -o /dev/null http://127.0.0.1:8091/health/live
HTTP/1.1 200 OK
x-instance-id: api-a
$ curl -sD - -o /dev/null http://127.0.0.1:8091/api/v1/users/me
HTTP/1.1 401 Unauthorized
x-instance-id: api-a
$ kill -INT <pid> # остановка, как Ctrl+C
```
Без переменной в консоли значение было бы hostname машины
(`MacBook-Pro-Roman`), так что `api-a` пришёл именно из окружения.
Журнал этого запуска: 14 JSON-записей, без `instance_id` — 0, значений
— одно: `api-a`. Записи по порядку (поля сокращены; строка reloader с
путём каталога `src` опущена):
```json
{"event": "Uvicorn running on http://127.0.0.1:8091 (Press CTRL+C to quit)", "instance_id": "api-a"}
{"event": "Started reloader process [83651] using WatchFiles", "instance_id": "api-a"}
{"event": "Started server process [83655]", "instance_id": "api-a"}
{"event": "Waiting for application startup.", "instance_id": "api-a"}
{"event": "Started API", "instance_id": "api-a"}
{"event": "Application startup complete.", "instance_id": "api-a"}
{"event": "HTTP request completed", "instance_id": "api-a", "path": "/api/v1/users/me", "status": 401}
{"event": "Shutting down", "instance_id": "api-a"}
{"event": "Waiting for application shutdown.", "instance_id": "api-a"}
{"event": "Stopped API", "instance_id": "api-a"}
{"event": "Application shutdown complete.", "instance_id": "api-a"}
{"event": "Finished server process [83655]", "instance_id": "api-a"}
{"event": "Stopping reloader process [83651]", "instance_id": "api-a"}
```
## Недопустимые значения: сервис не стартует
Каждая команда завершилась с кодом 1 до старта сервера: строки
«Started API» в выводе нет, порт 8092 после них свободен. Ошибка
проверки настроек приходит из pydantic при загрузке `settings`, ещё до
настройки JSON-журнала, поэтому это traceback в stderr; ниже — его
конец.
```text
$ APP__INSTANCE_ID="api a" APP__RUN_MODE=console APP__PORT=8092 uv run python -m src
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
app.instance_id
Value error, must match ^[A-Za-z0-9._-]{1,64}$ [type=value_error, input_value='api a', input_type=str]
exit=1
$ IDEMPOTENCY__TTL_SECONDS=abc APP__RUN_MODE=console APP__PORT=8092 uv run python -m src
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
idempotency.ttl_seconds
Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='abc', input_type=str]
exit=1
$ IDEMPOTENCY__TTL_SECONDS=0 APP__RUN_MODE=console APP__PORT=8092 uv run python -m src
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
idempotency.ttl_seconds
Input should be greater than 0 [type=greater_than, input_value='0', input_type=str]
exit=1
```
В ошибке — только имя поля и отвергнутое значение; остальные настройки
(в том числе пароли) не печатаются.