Lanes + Queues (Implementation): session/global two-level queuing
Lanes + Queues (Implementation): session/global two-level queuing
This page turns concurrency control into a replicable state machine: per-session ordering, global limits, and post-restart recovery.
Entry point (concept):
Code entry points (optional)
src/process/command-queue.tssrc/agents/pi-embedded-runner/lanes.tssrc/gateway/server-lanes.tssrc/agents/pi-embedded-runner/runs.ts
Core data structures (keep them explicit)
LaneState:queue,activeTaskIds,maxConcurrent,draining,generationQueueEntry:enqueuedAt,warnAfterMs,onWait(warn-only, no cancel)
Critical flow (enqueue → drain → finalize)
- drain immediately on enqueue (don’t wait for the next event).
drainingprevents re-entrant pumps.- pump on failures too (avoid starving the queue).
reset/generation (the key to “no dead queue after restart”)
If tasks are interrupted, their finally blocks may not run; generation guards prevent stale callbacks from writing into new state.
Failure modes and troubleshooting
- Out-of-order in the same session: confirm session lane serializes and
maxConcurrentwasn’t raised accidentally. - Dead lanes: verify failure paths still pump and
drainingisn’t stuck. - Probe lane log spam: treat probe failures as expected and keep them quiet.
Acceptance checks
- stable ordering for a single session under burst.
- two sessions can run concurrently.
- after reset, backlog continues draining (no deadlocks).