Skip to content

fix: reconnect backoff and safe retry lifecycle in the CLI service - #9

Open
R44VC0RP wants to merge 1 commit into
masterfrom
fix/cli-reconnect-backoff
Open

fix: reconnect backoff and safe retry lifecycle in the CLI service#9
R44VC0RP wants to merge 1 commit into
masterfrom
fix/cli-reconnect-backoff

Conversation

@R44VC0RP

@R44VC0RP R44VC0RP commented Aug 29, 2026

Copy link
Copy Markdown

Summary

The daemon reconnect loop previously slept fixed delays inside the command loop, logged full stack traces every 2 seconds during outages (my daemon log reached 41 MB with 2,228 identical failures), and could strand retries or leak in-flight attempts across reload.

  • Capped, jittered exponential backoff (250 ms to 30 s from BridgeTiming), reset after a stable connection.
  • Connection attempts run in a supervised fiber, so stop/reload interrupt an in-flight attachment instead of waiting out the sleep.
  • Retries carry a generation number; a retry scheduled by a canceled attempt's cleanup cannot tear down its replacement.
  • Scopes are forked from the daemon scope and failed attempts close immediately, releasing partial resources.
  • Errors log as one timestamped JSON line, deduplicated while the message repeats; unexpected defects are reported and retried instead of leaving the daemon idle-but-"ok".

Independent of the client changes (#10); works against the unmodified client.

Verification

  • packages/cli: bun test test/service.test.mjs — 5 tests covering resource release and growing delays under repeated failure, partial route-registration retry, interruption of in-flight attachments, stale-retry cancellation across reload, and defect recovery.
  • bun run build (typecheck + bundle).

Split out of #7.

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.

1 participant