← Back to PRs

#6689: Fix: auto-remove idle session lanes to prevent unbounded command queue growth

by kamb5686 open 2026-02-01 23:24 View on GitHub →
agents
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