Skip to content

feat: standalone relay supervisor for scheduled health checks (#166) - #175

Merged
OBenner merged 2 commits into
mainfrom
feat/166-relay-supervisor
Nov 21, 2026
Merged

OBenner merged 2 commits into
mainfrom
feat/166-relay-supervisor

Conversation

@OBenner

@OBenner OBenner commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Проблема (issue #166)

Standalone team relay может умереть, пока ролевые чаты настроены — auto-relay (#124) поднимает его только по запросу живого канала. Инцидент 2026-11-19: relay умер в непустом контуре, и некому было его поднять (keepalive-задачу удалили 17.11, а она делала и рестарт).

Решение

synloq relay-supervisor (новый CLI-субкоманд, TS, в vitest-контуре) для запуска по расписанию (Scheduled Task, каждые 5 мин):

  • Health-first: GET /v1/health с таймаутом 3 с; живой relay (маркер service: synloq-relay) → мгновенный выход. serve.lock не читается и не трогается вообще — recovery локов целиком в коде relay (Relay resilience: stale-lock recovery (dead-PID verified) + fail-loud diagnostics instead of silent fetch failed #141). Тест-гард: файл serve.lock с контентом остаётся нетронутым.
  • Exactly-one: атомарный claim supervisor-лока (wx, рядом с БД в synloq-home data). Гонка двух запусков → один старт. Stale supervisor-лок мёртвого PID чистится (мой лок, не relay'ев). Liveness unknown → fail closed (никого не стартуем). ALREADY_RUNNING из serve ([P1] Advisory lock beside the project database: refuse a second synloq serve #110) = кто-то уже поднимает → тихий выход.
  • Без restart-шторма: cooldown-маркер 10 мин — сломанный relay не респаунится каждые 5 мин; протухший маркер разрешает новую попытку.
  • Bounded диагностика: мини-лог рядом с БД, capped на 200 строк (протухшие отрезаются). Дублирования [P2] Timestamped logging for relay and plugin error/diagnostic paths #24 нет.

scripts/install-relay-supervisor.ps1 — тонкий идемпотентный регистратор Scheduled Task (существующая задача → пропуск; schtasks, без хрупких COM-командлетов).

Тесты (test/cli/relay-supervisor.test.ts, 8 шт)

healthy-skip · один старт при мёртвом · гонка двух одновременных → один старт · stale supervisor-lock cleanup · serve.lock нетронут · лог capped на 200 строк · истёкший cooldown разрешает повтор · unknown-liveness fail-closed.

Полный pnpm verify зелёный: 138 файлов / 1253 теста.

Ограничения

  • Живой acceptance (остановить relay → задача поднимает) — операторским окном после мержа, по issue.
  • Временный keepalive-обход не возвращается: старый relay-keepalive.ps1 удалял serve.lock вручную — этот путь не восстановлен и не нужен.

Closes #166.

The standalone team relay can die while role chats stay configured; the
auto-relay only starts on a live channel's request, so nobody noticed
until the 2026-11-19 incident. A scheduled task now probes /v1/health:

- healthy (service marker) → instant exit, no action;
- unreachable → atomic supervisor-lock claim (wx, beside the DB) →
  detached serve start → bounded log line (capped at 200 lines);
- cooldown marker (10 min) prevents a restart storm against a broken
  relay; an expired marker allows a new attempt;
- ALREADY_RUNNING from the serve lock (#110) and a live supervisor
  claimant both exit quietly; a stale supervisor lock owned by a dead
  PID is cleaned up (my own lock, not the relay's);
- serve.lock is never read or touched — stale-lock recovery belongs to
  the relay (#141).

scripts/install-relay-supervisor.ps1 registers the 5-minute Scheduled
Task idempotently (existing task → skip).

Tests: healthy skip, single start, concurrent-run race, stale-lock
cleanup, serve.lock untouched, bounded log, cooldown expiry,
unknown-liveness conservatism.
CTO final review found the plumbing gap: the supervisor probed/logged
against the custom home but spawned serve without the flag, so a relay
would come up against the DEFAULT home (different DB/configs).

startRelay now takes RelayStartOptions including synloqHome, and the
argv builder (relayStartArgv, exported) appends --synloq-home.
Regression test: the custom home reaches both the start options and the
spawned argv.
@OBenner
OBenner merged commit b2ffc55 into main Nov 21, 2026
5 checks passed
@OBenner
OBenner deleted the feat/166-relay-supervisor branch November 21, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] Supervise the standalone relay process on health failure

1 participant