feat: add reconcile strategies, deep check, rate limit and cost profile

- reconcile --strategy head, --deep (checksum_mismatch), restore needs the same SHA-256
- [reconciler] max_objects_per_second (2000), pause interrupted by signal
- --apply stops rechecks once the limit is exceeded (unchecked)
- pass cost in the summary: S3 objects and requests, bytes, DB sessions, phases
- S3 client counters, cleaner exits with os._exit after main()
- fault tests, hook args, driver reconcile-signal --pace
- bench profile reconcile / reconcile_quick: fill outside the API, gateway metrics, background load
- sync spec deltas, rules, AGENTS.md, PLAN.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 04:52:56 +03:00
co-authored by Claude Opus 5.5
parent dcdfe5f2e4
commit 8d4cf7eebf
41 changed files with 5344 additions and 441 deletions
+53 -7
View File
@@ -82,11 +82,18 @@
`attachments/`, символы [A-Za-z0-9._/-]
lost-ids `id` вложений с потерянным оригиналом
(lost_at задан)
reconcile dry-run|apply [<предел>]
reconcile dry-run|apply [<предел>] [--strategy batch|head] [--deep]
[--max-objects-per-second R]
разовая сверка (`docker compose run --rm
--no-deps -T cleaner reconcile [--apply]
[--max-changes N]`): записи процесса и
строка `exit_code=<n>`; код hook — 0
[--max-changes N] …`): стратегия обхода,
глубокая сверка и предел скорости (R —
неотрицательное число, 0 — без предела)
проверяются по списку и передаются команде
как есть (design change
`track2-reconcile-cost`, решение 14);
записи процесса и строка `exit_code=<n>`;
код hook — 0
stop|start cleaner сервис уборщика стенда
run-cleaner <секунд> отдельный уборщик
`<FAULT_PROJECT>-cleaner-scheduled` с
@@ -421,6 +428,10 @@ client.put_object(Bucket=s3.bucket, Key=sys.argv[1], Body=body)
# символы ключа объекта, который hook пишет или удаляет мимо API
OBJECT_KEY_RE = re.compile(r"^[A-Za-z0-9._/-]+$")
RECONCILE_MODES = {"dry-run": (), "apply": ("--apply",)}
# стратегии обхода и предел скорости сверки (change track2-reconcile-cost):
# неотрицательное число, целое или с дробной частью
RECONCILE_STRATEGIES = ("batch", "head")
RATE_PATTERN = re.compile(r"[0-9]+(\.[0-9]+)?")
# плановая сверка отдельного уборщика: раз в секунду
SCHEDULED_CLEANER_ENV = "RECONCILER__INTERVAL_SECONDS=1"
SCHEDULED_CLEANER_MAX_S = 60
@@ -817,12 +828,47 @@ def row_change(project: str, sql: str, attachment_id: str, value: str) -> str:
return ""
def reconcile_options(args: list[str]) -> list[str]:
"""Аргументы сверки после режима: необязательный предел изменений
первым, затем `--strategy batch|head`, `--deep`,
`--max-objects-per-second R`. Каждый — по списку разрешённых, иначе
код 2 hook."""
usage = (
"reconcile dry-run|apply [<max changes>] [--strategy batch|head] "
"[--deep] [--max-objects-per-second R]"
)
options: list[str] = []
rest = list(args)
if rest and not rest[0].startswith("--"):
if not rest[0].isdigit() or int(rest[0]) < 1:
raise HookError(usage)
options += ["--max-changes", str(int(rest.pop(0)))]
seen: set[str] = set()
while rest:
name = rest.pop(0)
if name in seen:
raise HookError(usage)
seen.add(name)
if name == "--deep":
options.append(name)
elif name == "--strategy" and rest and rest[0] in RECONCILE_STRATEGIES:
options += [name, rest.pop(0)]
elif name == "--max-objects-per-second" and rest:
value = rest.pop(0)
if not RATE_PATTERN.fullmatch(value):
raise HookError(usage)
options += [name, value]
else:
raise HookError(usage)
return options
def reconcile(project: str, mode: str, args: list[str]) -> str:
"""Разовая сверка в одноразовом контейнере уборщика стенда: записи
процесса и строка `exit_code=<n>`."""
if mode not in RECONCILE_MODES or len(args) > 1:
raise HookError("reconcile dry-run|apply [<max changes>]")
limit = ("--max-changes", str(int(args[0]))) if args else ()
if mode not in RECONCILE_MODES:
raise HookError("reconcile dry-run|apply [<max changes>] [options]")
options = reconcile_options(args)
result = compose_run(
project,
"run",
@@ -832,7 +878,7 @@ def reconcile(project: str, mode: str, args: list[str]) -> str:
"cleaner",
"reconcile",
*RECONCILE_MODES[mode],
*limit,
*options,
)
lines = [*result.stdout.splitlines(), *result.stderr.splitlines()]
return "\n".join([*lines, f"exit_code={result.returncode}"])