A worker keeps running after losing its lease
Detect: Fencing checks reject writes from the old ownership version.
Recover: Stop the worker and reconcile any external actions.
Control how agent instances are created, leased, reused, drained, and retired so long-running work does not accumulate abandoned resources or authority.
Agent lifespan management governs the operational lifetime of an execution instance and its associated resources. These resources can include worker slots, browser sessions, tool connections, temporary artifacts, credentials, and memory. A durable conversation or task can outlive any particular process; the process should not become the sole owner of its business state.
Choose deliberately between short-lived workers and reusable sessions. Reuse can reduce initialization cost but increases contamination and leakage risks. Lease ownership, explicit cleanup, and terminal-state handling ensure that abandoned clients or failed workers do not leave active agents consuming capacity indefinitely.
A prototype often creates an agent for each request and relies on process exit for cleanup. Inventory every resource that actually survives completion.
Production defines creation limits, idle expiry, maximum runtime, cancellation, and cleanup ownership. Credentials should expire independently of whether cleanup succeeds.
At scale, workers need graceful draining during deployments and controllers must reclaim orphaned leases. Measure live instances against active business operations to detect silent resource accumulation before capacity exhaustion.
Creates and tracks agent instances under tenant and capability quotas.
Assigns renewable ownership and fences expired workers from further writes.
Records sessions, connections, temporary objects, and credentials associated with each run.
Stops new assignments while allowing bounded in-flight work to finish or checkpoint.
Detects expired, abandoned, or terminal instances and performs retryable cleanup.
stateDiagram-v2
[*] --> Allocated
Allocated --> Running: Lease acquired
Running --> Idle: Waiting without active work
Idle --> Running: New permitted work
Running --> Draining: Deployment or shutdown
Draining --> Checkpointed: Progress saved
Checkpointed --> Released: Resources closed
Running --> Expired: Lease lost
Idle --> Expired: Idle limit reached
Expired --> Reaping: Independent cleanup
Reaping --> Released: Cleanup verified
Released --> [*]Check quotas and register the run, owner, maximum age, and resource budget.
Create only necessary sessions and attach them to the resource registry.
Heartbeat the lease while checking cancellation, idle timeout, and parent task status.
Save progress before deployment, lease handoff, or graceful termination.
Commit terminal business status before releasing resources and revoking capabilities.
Reconcile expired leases and cleanup failures using an independent controller.
Enterprise SaaS · Illustrative enterprise scenario, not a reported customer outcome.
A finance platform uses browser automation to reconcile supplier portals that lack stable machine interfaces.
Abandoned browser sessions retain cookies and consume memory after users close their dashboards or tasks fail.
The assistant must preserve reconciliation progress while bounding session lifetime and access to external accounts.
An instance manager leases browser workers, tracks their resources, and hands completed checkpoints to durable storage.
If a worker disappears, its lease expires and the reaper closes remaining sessions while a new worker resumes from durable state.
Track orphaned sessions, memory per active run, cleanup latency, credential age, and drain completion before increasing concurrency.
| Decision | Benefit | Cost |
|---|---|---|
| Short-lived workers | Cleanup and tenant separation are easier to reason about. | Repeated initialization increases cold-start cost. |
| Session reuse | Expensive browser or tool setup can be amortized. | State contamination and resource leakage become more likely. |
| Graceful draining | Deployments interrupt less useful work. | Shutdown takes longer and needs a hard upper bound. |
Detect: Fencing checks reject writes from the old ownership version.
Recover: Stop the worker and reconcile any external actions.
Detect: Resource registry retains unreleased objects past their deadline.
Recover: Retry independently and alert with resource ownership details.
Persist business state separately from worker resources.
Use short-lived scoped credentials with independent expiry.
Isolate sessions and clear all state before any permitted reuse.