Skip to content

Add exponential backoff for Amp status monitoring #6

Description

@dinsley

Summary

Priority: P0

Replace the fixed three-second amp top --stream-jsonl restart loop with capped exponential backoff and jitter.

The current loop recovers quickly, but a persistent configuration, authentication, or compatibility failure can cause the plugin to launch and log a new Amp process every three seconds indefinitely.

Proposed behavior

  • Keep the initial status launch immediate.
  • Increase the retry delay after consecutive failures.
  • Apply jitter so multiple plugin instances do not retry in lockstep.
  • Cap the maximum delay so recovery remains automatic.
  • Reset the failure count only after a valid live snapshot, or after a clearly defined stable period.
  • Cancel pending retries when monitoring is paused or the plugin shuts down.
  • Preserve the current fail-closed behavior while disconnected or receiving incompatible snapshots.
  • Surface retry attempt and next-delay information to diagnostics without making normal logs noisy.

Suggested defaults to validate during implementation:

  • initial delay: 3 seconds;
  • multiplier: 2;
  • maximum delay: 60 seconds; and
  • bounded/full jitter.

Acceptance criteria

  • Consecutive launch failures and unexpected exits increase the retry delay up to a cap.
  • A valid live connection resets the backoff state.
  • stop() reliably cancels every pending retry.
  • Only connection-state transitions and useful retry summaries are logged at normal production levels.
  • Retry scheduling is deterministic in tests through injected time and randomness.
  • Tests cover spawn errors, immediate exits, schema mismatch, recovery, stable reset, and shutdown during backoff.
  • Existing users still recover automatically when Amp becomes available again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestjavascriptPull requests that update javascript code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions