#6689: Fix: auto-remove idle session lanes to prevent unbounded command queue growth
agents
Cluster:
Session Management Enhancements
Fixes #5264.
The command queue stores per-lane state in an in-process Map. Session-derived lanes ("session:*") are created as new sessions appear and previously were never removed, leading to unbounded growth over long runtimes.
This change removes *idle* session lanes (no active tasks, empty queue) once they become idle, while keeping the main lane persistent. Includes a unit test to prevent regression.
Testing: `pnpm vitest run src/process/command-queue.test.ts`
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR addresses unbounded growth in the in-process command queue’s per-lane `Map` by auto-removing idle session-derived lanes (`session:*`) once they have no active tasks and an empty queue. The change hooks lane cleanup into the lane draining loop and into `clearCommandLane`, and adds a unit test to assert that a `session:*` lane is removed after its work completes.
The changes fit into the existing `command-queue.ts` design where lanes are lightweight in-memory schedulers; the PR keeps the `main` lane persistent while allowing ephemeral session lanes to be garbage-collected to avoid long-lived processes accumulating lane state.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge, with a small risk of edge-case lane state getting stuck.
- The core change is localized and conceptually correct (remove `session:*` lanes when idle). The main concern is correctness around `state.active` bookkeeping if a task throws synchronously, plus some minor test/cleanup triggering nuances.
- src/process/command-queue.ts (active decrement and cleanup trigger paths), src/process/command-queue.test.ts (test stability)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#21851: fix: drain pending system events when main command lane goes idle
by alan-purring · 2026-02-20
76.4%
#12987: fix(cli): exit process after successful command completion
by omair445 · 2026-02-10
74.7%
#9266: fix(gateway): configure nested lane concurrency to prevent sessions...
by 100menotu001 · 2026-02-05
74.1%
#11522: Fix #10904: Add hard timeout to lane tasks to prevent cron wedging
by divol89 · 2026-02-07
73.0%
#18962: feat: add priority preemption — heartbeat lane separation
by rsepulveda23 · 2026-02-17
72.9%
#11194: fix(slack): queue drain drops string thread_ts — replies leak to ma...
by Lukavyi · 2026-02-07
72.3%
#4749: fix: handle string thread IDs in queue drain for Slack
by nvonpentz · 2026-01-30
72.2%
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
70.7%
#13881: fix: Address Greptile feedback - test isolation and channel resolution
by trevorgordon981 · 2026-02-11
70.5%
#13104: fix: persist user command message in chat transcript
by mcaxtr · 2026-02-10
70.5%