Skip to main content

Module lock

Module lock 

Source
Expand description

Counting semaphore via lock files to limit parallel invocations. Provides acquire_cli_slot (counting semaphore) and the G28-B per-namespace heavy-job singleton acquire_job_singleton for enrich, ingest --mode claude-code, ingest --mode codex. Counting semaphore via lock files to limit parallel CLI invocations.

acquire_cli_slot tries to acquire one of N available slots by opening the file cli-slot-{N}.lock in the OS cache directory and obtaining an exclusive flock. The returned std::fs::File MUST be kept alive for the entire duration of main; dropping it releases the slot automatically for the next invocation.

When wait_seconds is Some(n) > 0, the function polls every crate::constants::CLI_LOCK_POLL_INTERVAL_MS milliseconds until the deadline. When it is None or Some(0), a single attempt is made and Err(AppError::AllSlotsFull) is returned immediately if all slots are occupied.

§Job-type singleton (G28-B, v1.0.68)

Heavy long-running jobs (enrich, ingest --mode claude-code, ingest --mode codex) also acquire a singleton lock per (job_type, namespace) via acquire_job_singleton. This guarantees at most one heavy job per namespace runs at any time, which was the root cause of the 2026-06-03 process-proliferation incident (4 parallel enrich instances × N workers × 10 MCP servers = ~192 spawned processes).

Enums§

JobType
Job-type classification for acquire_job_singleton.

Functions§

acquire_cli_slot
Acquires a concurrency slot from the max_concurrency-position semaphore.
acquire_job_singleton
Acquires a process-wide singleton lock for a heavy job type and namespace.