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_exclusivefor atomic cross-process acquire (fcntl on Unix, LockFileEx on Windows —fs40.9 with trustScore 9.6 confirmed via context7)- RAII guard
LlmSlotGuardwithDropreleases automatically on panic - Integration with
reaper.rs::scan_and_kill_orphansto 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 scopeStructs§
- LlmSlot
Guard - RAII guard that releases the slot automatically on panic, abrupt cancellation, or normal scope exit.
- Slot
Status - Returns the current status of the LLM slots (for the
slots status --jsonsubcommand).
Functions§
- acquire_
llm_ slot - Acquires a free LLM slot, waiting up to
wait_secsseconds. - 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 --yessubcommand). - read_
status - slot_
path - slots_
dir