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:777genius Agent teams ai IPC Deduplication

From Leeroopedia
Knowledge Sources
Domains Performance, IPC
Last Updated 2026-10-22 00:00 GMT

Overview

Cache IPC handler results with a short TTL (5 seconds) to prevent rapid UI polling from triggering redundant expensive operations like CLI status probes.

Description

The Electron renderer may poll IPC handlers rapidly (e.g., on every render cycle or state change). Without caching, each poll triggers a full status probe that spawns CLI processes, reads config files, and checks authentication. The IPC deduplication pattern caches the result with a 5-second TTL (`STATUS_CACHE_TTL_MS = 5_000`). Within the TTL window, subsequent calls return the cached result without re-probing. The cache also tracks a generation counter for explicit invalidation — bumping the generation forces a fresh probe on the next call.

Usage

Use this heuristic for IPC handlers that are polled frequently by the renderer and whose results are expensive to compute. This applies to `cliInstaller:getStatus` and any status-checking IPC handler. Combine with in-flight deduplication for concurrent identical requests.

The Insight (Rule of Thumb)

  • Action: Cache IPC results in a `Map<mode, { value, at }>` with a TTL check: `Date.now() - cached.at < TTL`.
  • Value: TTL is 5 seconds (`STATUS_CACHE_TTL_MS = 5_000`). Cache generation counter enables explicit invalidation.
  • Trade-off: Status updates lag by up to 5 seconds. Acceptable for UI polling; users can trigger explicit invalidation.
  • Compatibility: Works with any IPC handler. Cache is per-mode (e.g., `full` vs `fast` status).

Reasoning

The renderer polls `cliInstaller:getStatus` frequently — on mount, on focus, on tab switch, and on state changes. Without caching, each poll spawns CLI processes (Claude, Codex, Gemini, OpenCode) and reads config files. This is wasteful and slow. A 5-second TTL cache reduces probes to at most one per 5 seconds per mode, while still providing reasonably fresh data. Explicit invalidation (bumping `statusCacheGeneration`) handles user-initiated refreshes.

Code Evidence

TTL constant from `cliInstaller.ts:61`:

const STATUS_CACHE_TTL_MS = 5_000;

Cache check from `cliInstaller.ts:347`:

if (cached && Date.now() - cached.at < STATUS_CACHE_TTL_MS) {
  return cached.value;
}

Cache storage with generation from `cliInstaller.ts:56-60`:

const cachedStatus = new Map<
  CliInstallerProviderStatusMode,
  { value: CliInstallationStatus; at: number }
>();
let statusCacheGeneration = 0;

Related Pages

Page Connections

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