Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Restart‑Safe and Duplicate‑Free: How Baize Makes Long‑running Agent Runs Resumable

Description and use

Baize guarantees restart‑safe, duplicate‑free long‑running agent runs by persisting each Run in a database, using leases and heartbeats for single execution, a reconciler for orphan recovery, and replayable event streams for resilient front‑end.

Problem

Agent runs can span minutes to hours, involve human approvals, and may be retried across replicas, leading to lost or duplicated work when workers crash or restart.

Outcome

Baize achieves restart‑safe, duplicate‑free long‑running agent runs by persisting Runs in a database, using leases and heartbeats for single execution, a reconciler for orphan recovery, and replayable event streams for front‑end resilience.

Workflow

  • 1. Trigger (chat, webhook, schedule, approval, child receipt) enqueues a Job and creates a Run row. 2. Workers pull Jobs (default 8 concurrency) and attempt to lease the Run via a DB UPDATE. 3. If lease acquired, worker heartbeats every ~20s to extend a 60s TTL. 4. Run executes; may enter waiting_human state for approvals or child receipts. 5. On worker crash, reconciler scans every 15s, re‑enqueues orphan Runs. 6. On shutdown, workers stop pulling new Jobs, allow 5s grace for in‑flight work, and rely on DB state for recovery. 7. Human approvals trigger either a hot wake‑up (same process) or an approval_resume job (cross‑restart). 8. Events are written to an event table with sequence numbers; front‑end reconnects replay missing events. 9. Scheduled tasks scan every 15s, clear stale placeholders, and enqueue new runs without duplicates.

Evidence

make a Run a first‑class row in the database, not a goroutine in memory.

Source

Workers pull Jobs off the queue with a default concurrency of 8.

Source

Lease TTL is 60 seconds; heartbeat renews it roughly every 20 seconds.

Source

Reconciler runs every 15 seconds, re‑enqueues orphan Runs.

Source

  • Record date: 2026-10-26T04:26:28.383Z