DEV Community

Odd_Background_328
Odd_Background_328

Posted on

Long-Running AI Agents Need a Lease, a Heartbeat, and a Drain Test

NVIDIA's June 2026 GTC Taipei program includes a session on long-running AI agents that plan and operate over hours or days. Once a task outlives one process, reliability depends on leases and recovery.

Use explicit worker ownership:

UPDATE tasks
SET lease_owner = :worker,
    lease_expires_at = CURRENT_TIMESTAMP + INTERVAL '30 seconds'
WHERE id = :id
  AND state = 'queued'
  AND (lease_expires_at IS NULL OR lease_expires_at < CURRENT_TIMESTAMP)
RETURNING id;
Enter fullscreen mode Exit fullscreen mode

The worker renews the lease while it is healthy. Tool effects use idempotency keys. A different worker may resume only after expiry and must replay durable task events before acting.

Minimum telemetry

agent_task_lease_seconds
agent_task_heartbeat_age_seconds
agent_task_resume_total
agent_tool_effect_duplicate_total
agent_task_terminal_total{state}
Enter fullscreen mode Exit fullscreen mode

Alert on stale heartbeats and repeated resumes, not merely high task duration. Some tasks are expected to be long.

Run the drain test

  1. Start a task with a fake tool that sleeps between two durable steps.
  2. Send the worker its normal termination signal.
  3. Confirm it stops accepting new tasks.
  4. Confirm the active lease is renewed only during the drain window.
  5. Force termination after the deadline.
  6. Start another worker and verify it resumes without repeating the first effect.

Record timestamps, task IDs, lease owners, and effect idempotency keys. Clean up the disposable queue afterward.

This is a reason I recommend evaluating MonkeyCode as a workflow rather than judging only the model behind it: long-running coding tasks make durable status and deployment ownership visible concerns. The hosted SaaS avoids operating the platform yourself; the open-source version gives teams a self-hosting path when they need control. Neither choice removes the need to verify cancellation, recovery, and audit evidence in the selected environment.

I am not reporting a production fault-injection benchmark here. The procedure is a reusable acceptance test.

Disclosure: I'm a MonkeyCode user sharing my own experience, not affiliated with the project.

An agent that can run for a day must also survive a worker that cannot. Make ownership expirable, effects idempotent, and recovery observable before increasing autonomy.

Top comments (0)