---
title: "Lane-Based Execution Queueing"
description: "Isolate concurrent agent tasks into named queues with per-lane concurrency limits to prevent output interleaving, race conditions, and deadlocks."
term: "Lane-Based Execution Queueing"
tags:
  - agent-design
  - tool-agnostic
  - multi-agent
aliases:
  - execution lane isolation
  - named queue concurrency
  - per-lane concurrency limits
last_reviewed: 2026-10-30
maturity: established
---

<!-- source: nibzard/awesome-agentic-patterns (Apache 2.0, https://github.com/nibzard/awesome-agentic-patterns) — retain attribution per license -->

# Lane-Based Execution Queueing

> Organize agent task execution into named, isolated queues, each draining independently with configurable concurrency, to eliminate the three core hazards of concurrent agent systems.

## The problem

Concurrent agent systems face three failure modes that a single shared queue cannot prevent:

- Interleaving — simultaneous stdout/stdin writes corrupt terminal output
- Race conditions — unsynchronized shared state produces inconsistent results
- Deadlocks — cross-task dependencies with no structured resolution

Lane-based queueing addresses all three. Each class of work gets its own isolated execution context.

## Lane structure

Each lane is an independent queue with a concurrency cap. A minimal TypeScript representation from the [Clawdbot reference implementation](https://github.com/nibzard/awesome-agentic-patterns/blob/main/patterns/lane-based-execution-queueing.md):

```typescript
type LaneState = {
  queue: Task[];
  active: number;
  maxConcurrent: number;
  draining: boolean;
};
```

Two operations run each lane:

- `drainLane()` — pumps tasks from the queue up to `maxConcurrent`, then yields
- `enqueueCommandInLane<T>()` — schedules work and returns a promise the caller can await

A shipped harness states the number. Claude Code release 2.1.302 changed "prompt and agent hooks so that at most 12 of one event run at a time; the rest wait their turn" ([Claude Code changelog](https://code.claude.com/docs/en/changelog#2-1-302)). Release 2.1.312 adds a session-wide ceiling for those same hooks. They run "at most 24 at a time per session, sub-agents included, plus at most 12 that have waited longer than their event's timeout" ([Claude Code changelog](https://code.claude.com/docs/en/changelog#2-1-312)). The changelog also records that "a `timeout` under 1 second now counts as 1 second".

Lanes never share state or communicate directly. Isolation is structural, not enforced by locks.

## Lane taxonomy

A typical multi-agent platform uses four lane types ([nibzard/awesome-agentic-patterns](https://github.com/nibzard/awesome-agentic-patterns/blob/main/patterns/lane-based-execution-queueing.md)):

| Lane | `maxConcurrent` | Purpose |
|------|-----------------|---------|
| `main` | 1 | Serial CLI default — one task at a time |
| `cron` | 1 | Scheduled tasks — isolated from interactive work |
| `subagent` | N | Spawned agent work — parallelizable |
| `session:<id>` | 1 | Per-user auto-reply — hierarchical ID |

The `session:<id>` pattern gives each user isolation without cross-session interference. Use stable identifiers. Unstable IDs spawn new lanes without limit, and memory grows without bound.

## Hierarchical composition

Nested lanes (a `subagent` lane spawning `session` lanes) prevent deadlocks through structured completion: inner lanes complete before outer lanes proceed. This replaces ad-hoc locking with a deterministic hierarchy. Direct cross-lane dependencies outside this hierarchy will deadlock.

```mermaid
graph TD
    A[main lane] --> B[subagent lane]
    B --> C[session:user1]
    B --> D[session:user2]
    C -->|completes| B
    D -->|completes| B
    B -->|completes| A
```

## Observability

You can monitor each lane on its own. The signals to watch per lane ([nibzard/awesome-agentic-patterns](https://github.com/nibzard/awesome-agentic-patterns/blob/main/patterns/lane-based-execution-queueing.md)):

- `queue_size_per_lane` — backlog depth
- `active_tasks_per_lane` — in-flight count
- `wait_time_p95` — tail latency per work class

Per-lane metrics let you diagnose starvation (a busy `subagent` lane blocking `cron` tasks) without correlating across a unified queue.

## Trade-offs

| Trade-off | Detail |
|-----------|--------|
| Memory overhead | Idle lanes hold allocated state |
| Concurrency tuning | Each lane's `maxConcurrent` must be sized to available resources — over-parallelization exhausts file handles and memory |
| Starvation risk | High-priority lanes with unbounded throughput can starve low-priority ones without explicit priority controls |

This pattern draws on established foundations: [Actor Model](https://en.wikipedia.org/wiki/Actor_model) isolation (Hewitt, Bishop & Steiger, 1973), [Work-Stealing](https://dl.acm.org/doi/10.1145/324133.324234) scheduling (Blumofe & Leiserson, JACM 1999), and queue-based routing in [Sidekiq](https://github.com/sidekiq/sidekiq/wiki/Advanced-Options), [BullMQ](https://github.com/taskforcesh/bullmq), and Airflow pools. Per-queue concurrency without dedicated worker processes is a [long-standing pain point](https://github.com/sidekiq/sidekiq/issues/983) in those systems — lane isolation makes the constraint explicit rather than emergent.

## Relation to worktree isolation

Worktree isolation works at the process and filesystem level. Each agent gets its own working directory. Lane-based queueing works at the task-scheduling level. Each class of work gets its own queue. The two complement each other: worktrees prevent filesystem conflicts between parallel agents, and lanes prevent scheduling conflicts between concurrent tasks within a platform. See [Worktree Isolation](../../workflows/worktree-isolation.md) and [/batch and Worktrees](../../tools/claude/batch-worktrees.md) for Claude Code's built-in worktree orchestration.

## Key Takeaways

- Name lanes by workload class (`main`, `cron`, `subagent`, `session:<id>`), not by caller identity
- Set `maxConcurrent=1` for any lane where ordering or serial execution matters
- Enforce hierarchical composition — inner lanes complete before outer lanes proceed
- Expose per-lane metrics; a unified queue makes starvation invisible
- Avoid dynamic lane IDs — stable identifiers prevent memory leaks

## Related

- [Agent Composition Patterns: Chains, Fan-Out, Pipelines, Supervisors](../multi-agent/agent-composition-patterns.md)
- [Idempotent Agent Operations: Safe to Retry](idempotent-agent-operations.md)
- [Agent Loop Middleware](../../loop-engineering/agent-loop-middleware.md)
- [Worktree Isolation](../../workflows/worktree-isolation.md)
- [VS Code Agents App: Agent-Native Parallel Task Execution](../../tools/copilot/vscode-agents-parallel-tasks.md)
- [Exception Handling and Recovery Patterns](exception-handling-recovery-patterns.md)
