fix(mothership): back off the transport poll instead of retrying every second

Merged
WA
2d ago
+128-7

Summary

  • The outbound transport receiver retried every failed poll after a fixed 1 s, forever. A self-hosted deployment whose COPILOT_API_KEY the worker rejects polls once a second, all day, and writes a warning on every attempt
  • A refused key (401/403) now backs off from 30 s to a 10-minute ceiling with jitter, and still reconnects by itself once the key is accepted
  • Other failures (lost connection, worker deploy, 5xx, a bad batch) back off from 1 s to 4 s, so with jitter a healthy deployment is back within the worker's 5 s run-control deadline
  • One warning per outage, and another only when it changes kind (outage → refused key), plus one info line on reconnect. The refused-key warning names COPILOT_API_KEY
  • The wait is interruptible, so SIGTERM never sits behind a long backoff

Type of Change

  • Bug fix

Testing

  • receiver.test.ts: four new backoff tests (refused key, transient ceiling, reset after a good poll, reset when an outage changes kind). All failed on the old fixed 1 s retry; removing the reset on a kind change turns its test red
  • Transport suites: 22 passing
  • biome and a type-check of the changed file; CI runs the full audits and type-check

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)