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 Delta High Water Mark

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

Overview

Track a per-file high-water mark (last indexed size/count) so only new conversation lines are processed — avoiding full re-indexing on every poll.

Description

The delta indexing engine tracks the last-indexed file size in an in-memory cache (`fileSizeCache`). On each poll, `hasFileChanged` compares `fs.statSync().size` against the cached size — a constant-time stat with no file read. Only files whose size has grown are opened and parsed. After indexing, the cache is updated to the indexed size; if the file grew during embedding (a common case for live conversations), the cache is deleted rather than updated, so the appended lines are caught on the next run.

This is a high-water mark because the mark only moves forward: lines below the mark are never re-read. Combined with a global concurrency throttle (`MAX_CONCURRENT_INDEX = 1`), this prevents CPU overload from simultaneous indexing across many agents.

Usage

Use this heuristic when:

  • Indexing conversation transcripts that grow monotonically (JSONL append-only)
  • Polling for new content where full re-reads would be wasteful (files can be tens of MB)
  • Multiple agents' files are indexed in rotation and CPU must be bounded

The Insight (Rule of Thumb)

  • Action: Cache `fs.statSync().size` per conversation file. Only read the file if the current size exceeds the cached size.
  • Value: `fileSizeCache: Map<string, number>`; throttle `MAX_CONCURRENT_INDEX = 1`.
  • Trade-off: A stat call per poll per file (cheap) vs. a full file read (expensive). If a file grew mid-indexing, delete the cache entry rather than mark it indexed — the new bytes were outside the ingestion snapshot.
  • Compatibility: Works with any append-only format (JSONL, log files). Does not handle file truncation/rotation — a smaller file resets the mark.

Reasoning

Conversation transcripts are append-only JSONL files that can grow to tens of MB. Re-reading and re-embedding the entire file on every subconscious poll (which runs every few minutes) would waste CPU and ONNX inference time on already-indexed content. The file size is a cheap proxy for "has new content arrived" — `statSync` is a single syscall that returns the size without reading the file. Only files that grew are opened and read from the last indexed offset.

The subtlety is the mid-indexing growth: a live conversation file can append lines while embeddings are running (which takes seconds). If the cache is updated to the file's size at the end of indexing, those appended lines (written between the read snapshot and the size check) are marked as "indexed" but were never actually processed. The fix: if `size !== indexedSize`, delete the cache entry so the next poll re-reads from the original offset.

Related Pages

Page Connections

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