GatewayRestartGovernor (gateway/restart-governor.ts)

ClawX · electron/gateway/restart-governor.ts · typescript · MIT
infra, tag:knn-classified

A lightweight TypeScript class that limits gateway restarts by enforcing a cooldown.

// Source: https://github.com/ValueCell-ai/ClawX | License: MIT | Copyright 2026 ValueCell Team
// Provided via justclaw.it.com; keep this notice with the code.
export type RestartDecision =
  | { allow: true }
  | {
    allow: false;
    reason: 'cooldown_active';
    retryAfterMs: number;
  };

type RestartGovernorOptions = {
  /** Minimum interval between consecutive restarts (ms). */
  cooldownMs: number;
};

const DEFAULT_OPTIONS: RestartGovernorOptions = {
  cooldownMs: 2500,
};

/**
 * Lightweight restart rate-limiter.
 *
 * Prevents rapid-fire restarts by enforcing a simple cooldown between
 * consecutive restart executions.  Nothing more — no circuit breakers,
 * no sliding-window budgets, no exponential back-off.  Those mechanisms
 * were previously present but removed because:
 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key