Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:23blocks OS Ai maestro Heartbeat Liveness Check

From Leeroopedia
Knowledge Sources
Domains Network, Client
Last Updated 2026-10-26 18:00 GMT

Overview

Send periodic heartbeat (ping) frames on a WebSocket and close+reconnect if no pong returns within a timeout, so a half-open connection is detected and recovered.

Description

A TCP/WebSocket connection can be half-open: the socket appears alive locally but the peer is gone (network change, host crash, NAT timeout). The `useWebSocket` hook (`hooks/useWebSocket.ts`) sends a heartbeat on a fixed interval and expects a response within a timeout. If no response arrives, it treats the connection as dead, closes it, and triggers reconnect (via Heuristic:23blocks_OS_Ai_maestro_Exponential_Backoff_Reconnect). This detects silent failure that the OS wouldn't otherwise signal for minutes.

Usage

Use this heuristic for any persistent connection that must detect silent peer death within a bounded time — terminal, status, and voice channels.

The Insight (Rule of Thumb)

  • Action: Every N seconds send a ping; if no pong within M ms, close and reconnect.
  • Value: N ~10–30s, M ~5s.
  • Trade-off: Heartbeats add minor traffic; cheaper than a stuck connection.

Reasoning

Without application-level heartbeats, a half-open socket surfaces only when the OS TCP keepalive timer fires (often minutes to hours). For a live UI, that's too long — the user sees a frozen terminal. A short heartbeat bound detects death in seconds and triggers recovery.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment