scale > 1 on an agent, multiple instances run concurrently. Without coordination, two instances might pick up the same GitHub issue, review the same PR, or deploy the same service at the same time. Resource locks prevent this.
Why Locks Exist
Locks let concurrent agent instances claim exclusive ownership of a resource before working on it. If another instance already holds the lock, the agent skips that resource and moves on.How It Works
- Before working on a shared resource, the agent calls
acquire_lockwith a resource URI (e.g."github://acme/app/issues/42"). - If the lock is free, the agent gets it and proceeds.
- If another instance already holds the lock, the tool returns the holder’s identity — the agent skips that resource.
- When done, the agent calls
release_lock.
SKILL.md workflow.
Tools
| Tool | Description |
|---|---|
acquire_lock | Acquire an exclusive lock. Fails if another instance holds it. |
release_lock | Release a lock. Only the holder can release. |
Resource Key URIs
Lock keys use URI format. Use a scheme that identifies the resource type, and a path that uniquely identifies the instance:| Pattern | Example |
|---|---|
github://owner/repo/issues/number | github://acme/app/issues/42 |
github://owner/repo/pr/number | github://acme/app/pr/17 |
deploy://service-name | deploy://api-prod |
TTL and Expiry
Locks expire automatically after 30 minutes by default. This prevents deadlocks if an agent crashes or hangs without releasing its lock. The timeout is configurable viaresourceLockTimeout in config.toml (value in seconds).
For work that takes longer than the timeout, acquire the lock with a larger ttl_seconds value. If the lock expires, another instance can claim it.
Multiple Locks and Deadlock Detection
An agent instance can hold multiple locks simultaneously when working across related resources. However, this introduces the possibility of circular waits — agent A holds lock X and waits for lock Y, while agent B holds lock Y and waits for lock X. The scheduler detects these cycles automatically. When anacquire_lock call would create a circular wait in the wait-for graph, it returns a deadlock error with the cycle path instead of blocking forever. The agent can then release its held locks and retry.
Auto-release on Exit
When an agent session ends — whether it finishes successfully, hits an error, or times out — all of its locks are released automatically by the scheduler. You don’t need to worry about cleanup in error paths.Example in SKILL.md
Configuration
| Setting | Location | Default | Description |
|---|---|---|---|
resourceLockTimeout | config.toml | 1800 (30 min) | Default TTL for locks in seconds |
See Also
- Agent Tools — Scheduler Tools — full tool reference
- Scaling Agents — guide on scaling with locks