Skip to main content

acquire_embedding_singleton

Function acquire_embedding_singleton 

Source
pub fn acquire_embedding_singleton(
    namespace: &str,
    db_path: &Path,
    wait_seconds: Option<u64>,
    force: bool,
) -> Result<File, AppError>
Expand description

G45: acquires a cross-process singleton lock for LLM embedding operations against a given (namespace, db) pair.

The lock is opened and held with flock (same mechanism as acquire_job_singleton). Two CLI invocations writing to the same database while both are calling the LLM on entity names will now serialise: the second one receives AppError::EmbeddingSingletonLocked (exit 75) instead of double-spawning claude -p / codex exec subprocesses.

Behaviour:

  • wait_seconds = Some(0) or None → fail immediately if held.
  • wait_seconds = Some(n) > 0 → poll every JOB_SINGLETON_POLL_INTERVAL_MS ms until the lock drops or the deadline expires.
  • force = true → remove a stale lock file before acquiring (operator escape hatch, same contract as acquire_job_singleton).

The returned File MUST be kept alive for the duration of the embedding work; dropping it releases the singleton for the next process.