fix(ever-connect): renew the scheduler lease on a timer while a round runs

Merged
EV
2d ago
+135-2

Follow-up to Greptile's finding on the 0.24.1 prod PR #645 ("Maintenance work can overlap"). This goes into 0.24.2; 0.24.1 already narrows the window compared with 0.24.0.

Change

EverConnectSchedulerService.round(): once the lease is acquired, a timer renews it every third of the lease (keepAliveMs, 40 s), so one long step (a backup or restore check longer than the 2-minute lease, a slow call, a long feed page) never outlives it. Before, the lease was renewed only between steps. The renewal uses the same conditional acquire(), so it never takes a lease another process holds. The round's stop checks between steps stay as they are. The timer is cleared, and a renewal still in flight is awaited, before the release, so the lease is never taken again after the round. unref() keeps the timer from holding the process open.

Changelog entry under next.

Tests

  • New unit test (ever-connect-managed.service.spec.ts): a round whose maintenance step takes 4 × 40 ms with a 20 ms renewal sees the lease held by this process with a later leaseUntil at each reading, and the lease is free after the round, with no late renewal taking it back.
  • Local (Node 24, SQLite): src/ever-connect/ unit 6 suites, 69 tests; e2e ever-connect, -managed, -person, -provision 4 suites, 25 tests; tsc clean, prettier --check clean.

No migration, no setting, no API change.

🤖 Generated with Claude Code


Summary by cubic

Fixes the EverConnect scheduler so a maintenance round renews its lease on a timer, preventing one long step from outliving the 2-minute lease and letting another API process start overlapping maintenance work.

  • Renewal now happens every third of the lease duration while the round runs; before, it only happened between steps.
  • Renewals run one at a time, each with the time it starts at, so a slower renewal never lands an older expiry after a newer one.
  • The timer skips while a renewal is in flight, so a slow renewal is never overtaken, and the release awaits it before the round finishes, preventing a late renewal from taking the lease back.
  • Renewals use the same conditional acquire, so they never take a lease another process holds; failed renewals are logged and don't stop the round.
  • Adds three unit tests covering long-step renewal, an in-flight renewal, and renewal ordering, plus a changelog entry under next.