Skip to main content

Module llm_slots

Module llm_slots 

Source
Expand description

GAP-004 (v1.0.82): Cross-process slot semaphore for LLM subprocesses. acquire_llm_slot limits concurrent codex/claude spawns per host to prevent OAuth rate limit saturation when N+ sessions run in parallel. GAP-004 (v1.0.82): cross-process semaphore for spawning LLM subprocesses.

When N Claude Code sessions run in parallel on the same host, each remember/edit/ recall/hybrid-search/enrich/deep-research/ingest wants to spawn its own codex exec or claude -p subprocess. Without coordination, N subprocesses saturate the shared OAuth rate limit (observed: 19+ concurrent codex in the transcript of 2026-06-15).

§Solution

  • Slot files at ${XDG_RUNTIME_DIR:-~/.local/share}/sqlite-graphrag/llm-slots/slot-{0..N}.lock
  • fs4::FileExt::try_lock_exclusive for atomic cross-process acquire (fcntl on Unix, LockFileEx on Windows — fs4 0.9 with trustScore 9.6 confirmed via context7)
  • RAII guard LlmSlotGuard with Drop releases automatically on panic
  • Integration with reaper.rs::scan_and_kill_orphans to detect orphaned slots

§Usage

use crate::llm_slots::acquire_llm_slot;

let _guard = acquire_llm_slot(4, 30)?;
// ... spawn LLM subprocess ...
// the guard releases the slot automatically when it leaves scope

Structs§

LlmSlotGuard
RAII guard that releases the slot automatically on panic, abrupt cancellation, or normal scope exit.
SlotStatus
Returns the current status of the LLM slots (for the slots status --json subcommand).

Functions§

acquire_llm_slot
Acquires a free LLM slot, waiting up to wait_secs seconds.
default_max_concurrency
Resolves the default LLM max-host-concurrency value.
find_stale_slots
Lists stale slot IDs (orphaned PIDs) — for automatic cleanup.
force_release
Releases a specific slot (for the slots release --slot-id N --yes subcommand).
read_status
slot_path
slots_dir