Fix: AI Agent Cron Job Collisions

AI agents (LLM inference jobs, RAG pipelines, embedding workers) running on cron are especially collision-prone because they use significant memory and GPU time. Two concurrent instances can exhaust VRAM or cause OOM kills.

flock-safe AI agent cron job
# Prevent concurrent AI agent runs:
*/10 * * * * flock -n /tmp/ai-agent.lock /usr/local/bin/run-agent.sh

# With GPU memory check before running:
*/10 * * * * flock -n /tmp/ai-agent.lock bash -c   'nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits |    awk "{if(NR==1 && int($1) < 2000) system("/usr/local/bin/run-agent.sh")}"'

For Ollama-based agents, also ensure Ollama is bound to 127.0.0.1 before exposing via cron-triggered scripts.

Visualise AI agent job schedules in the Cron Visualiser.

Open Tool →

Related Glossary Terms