← Back to PRs

#18962: feat: add priority preemption — heartbeat lane separation

by rsepulveda23 open 2026-02-17 06:45 View on GitHub →
docs gateway cli agents size: M
## Summary - Route heartbeat runs to a dedicated `heartbeat` lane so they never block human messages on the main lane - Controlled by a new config toggle: `messages.queue.priorityPreemption` (default: `false`) - When disabled, all behavior is identical to before; when enabled, heartbeats get their own lane with concurrency 1 ## Changes 7 lines of logic across 6 files: 1. **`src/process/lanes.ts`** — add `CommandLane.Heartbeat` to lane enum 2. **`src/config/types.messages.ts`** — add `priorityPreemption` to `QueueConfig` type 3. **`src/config/zod-schema.core.ts`** — add schema validation for the new config field 4. **`src/gateway/server-lanes.ts`** — configure heartbeat lane concurrency (1) at gateway startup 5. **`src/auto-reply/reply/agent-runner-execution.ts`** — route heartbeat agent runs to heartbeat lane when enabled 6. **`src/infra/heartbeat-runner.ts`** — heartbeat runner checks its own lane instead of main when enabled Plus: lint fix for unused vars in `command-queue.test.ts`, changelog entry, and doc updates to queue and heartbeat pages. ## Test plan - [x] All 12 command queue tests pass (lane isolation, concurrency, clearLane, error recovery, default routing) - [x] All 20 heartbeat core tests pass - [x] All 38 heartbeat runner tests pass - [x] 2/2 queue followup tests pass - [x] 2/2 config validation tests pass - [x] Lint clean on all changed files - [x] Type-check clean on all changed files - [x] Live tested on gateway with `priorityPreemption: true` enabled — heartbeats routed to dedicated lane, human messages unblocked 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds opt-in heartbeat lane separation via `messages.queue.priorityPreemption` config toggle. When enabled, heartbeat runs route to a dedicated `CommandLane.Heartbeat` lane (concurrency 1) instead of sharing the `main` lane with human messages, preventing heartbeats from blocking real user interactions for 30-60+ seconds. - Adds `Heartbeat` to `CommandLane` enum, `priorityPreemption` to config type + Zod schema - `server-lanes.ts` unconditionally sets heartbeat lane concurrency to 1 (negligible cost when unused) - `agent-runner-execution.ts` routes heartbeat runs to the heartbeat lane when enabled; `undefined` correctly falls through to `main` via `resolveGlobalLane()` - `heartbeat-runner.ts` checks the heartbeat lane (not main) for capacity when preemption is ON, ensuring human messages on main don't cause heartbeats to unnecessarily skip - Test file adds comprehensive safety-net tests for lane isolation, concurrency, `clearCommandLane`, `getTotalQueueSize`, error recovery, and default routing - PR also bundles unrelated new skill files and design documents <h3>Confidence Score: 5/5</h3> - This PR is safe to merge — the feature is opt-in (default `false`), minimal in scope, and well-tested. - The core logic is 7 lines across 6 files, all guarded behind an opt-in config flag. When disabled, behavior is identical to before. The lane routing flows correctly through the existing `resolveGlobalLane` → `enqueueCommandInLane` pipeline. The queue size check in `heartbeat-runner.ts` is consistent with where heartbeats are actually enqueued. New tests cover the underlying lane infrastructure. No security concerns, no breaking changes, no regressions when the feature is off. - No files require special attention. All changes are straightforward and well-documented. <sub>Last reviewed commit: c581e40</sub> <!-- 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