Skip to content

Implement per-group workloops and queue-aware claiming#1293

Merged
stuartc merged 51 commits intofastlanesfrom
1289-per-group-workloops
Mar 10, 2026
Merged

Implement per-group workloops and queue-aware claiming#1293
stuartc merged 51 commits intofastlanesfrom
1289-per-group-workloops

Conversation

@stuartc
Copy link
Member

@stuartc stuartc commented Mar 9, 2026

Short Description

Implements per-group workloops and queue-aware claiming for the fast lanes feature. Each slot group now gets its own independent workloop with its own queue preference chain, capacity tracking, and backoff. Claims include the queues field and the join payload reports the slot distribution to Lightning.

Fixes #1289

Implementation Details

This builds on #1288 (CLI parsing) and wires slot groups through the entire claim lifecycle:

  • Slot group model (parse-queues.ts): SlotGroup config type and RuntimeSlotGroup with runtime state (activeRuns, openClaims, workloop). groupHasCapacity() helper consolidates the repeated capacity-check pattern.
  • Claim protocol (claim.ts): Claims are now scoped to a group — capacity checks use per-group tracking, queues array is sent in every claim payload, and claimed runs are associated with their owning group via app.runGroupMap.
  • Per-group workloops (workloop.ts): Each group runs its own independent backoff-driven workloop. Stopping one group's workloop does not affect others.
  • Server orchestration (server.ts): resumeWorkloop(group?) selectively restarts workloops. work-available triggers claims for all groups with free capacity. Run completion cleans up from the owning group and resumes only that group's workloop.
  • Join payload (worker-queue.ts): Includes informational queues map ({ "fast_lane": 1, "manual,*": 4 }) for future WorkerPresence tracking.
  • Lexicon: Added queues?: string[] to ClaimPayload type.
  • Backward compatibility: No --queues flag defaults to manual,*:<capacity>. Old Lightning ignores the new queues field; old workers without it get Lightning's default ["manual", "*"].

QA Notes

  • All 303 existing + new tests pass
  • Key test areas: parse-queues.test.ts (parsing, validation, groupHasCapacity), claim.test.ts (per-group capacity, payload shape, run-to-group tracking), workloop.test.ts (independence of group workloops), worker-queue.test.ts (queues in join payload), cli.test.ts (--queues / WORKER_QUEUES / mutual exclusivity with --capacity)
  • Integration testing: deploy Lightning first (without queue support), then a worker with --queues "fast_lane:1 manual,*:4" — should work identically to current behavior since Lightning ignores unknown claim fields
  • When Lightning queue support lands, fast-lane slots will only claim from their pinned queue

AI Usage

  • I have used Claude Code
  • I have used another model
  • I have not used AI

@github-project-automation github-project-automation bot moved this to New Issues in Core Mar 9, 2026
@stuartc stuartc force-pushed the 1289-per-group-workloops branch from 1782d26 to 9015b38 Compare March 9, 2026 18:34
stuartc added 11 commits March 10, 2026 11:00
Introduce queue-aware slot allocation to support fast lanes. Workers can
now dedicate specific slots to specific queues via a new `--queues` flag
(e.g. `--queues "fast_lane:1 manual,*:4"`).

- Add parseQueues() with SlotGroup type and full validation
- Add --queues CLI option with WORKER_QUEUES env var support
- Enforce mutual exclusivity between --queues and --capacity
- Derive effectiveCapacity from slot groups in start.ts
- Add queues field to ClaimPayload in lexicon
- Remove unreachable ?? 5 fallback in start.ts (capacity always has default)
- Add TODO(#1289) for passing slotGroups to createWorker
- Warn on duplicate queue names within a preference chain
- Warn on identical queue configurations across slot groups
- Add test for WORKER_QUEUES + WORKER_CAPACITY env var mutual exclusivity
capacity always receives a default value via setArg, so the type
should reflect that rather than requiring a runtime fallback.
Each slot group now gets its own independent workloop, tracks its own
active runs and capacity, and sends queue-scoped claims to Lightning.
The join payload includes a queues map so Lightning knows the slot
distribution. Default behavior (no --queues) is preserved with a single
manual,* group.
The pattern of computing pending claims and comparing against maxSlots
was duplicated 4 times across server.ts. Extracts it into a single
groupHasCapacity() function in parse-queues.ts with 5 unit tests.
Fold run-to-group tracking assertions into the existing execute test,
remove the redundant workloop-stop test (already covered), and drop
the now-covered todo.
pnpm v7+ passes the '--' separator through to process.argv, causing
yargs to treat all subsequent flags as positional arguments. Strip a
leading '--' before parsing so --queues and other flags work correctly
whether invoked via pnpm, npm, or directly.
The per-group workloops use Promise.any which requires ES2021 or later
in the TypeScript lib setting.
@stuartc stuartc force-pushed the 1289-per-group-workloops branch from 53ccdb9 to 85a8acc Compare March 10, 2026 09:17
@stuartc stuartc merged commit 8fcdd31 into fastlanes Mar 10, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from New Issues to Done in Core Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants