Repository navigation
Global concurrency cap with a run queue (#166) - #1574
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee94e6b317
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| active.delete(threadId); | ||
| // After the caller finishes its terminal bookkeeping. | ||
| queueMicrotask(admitQueuedRuns); |
There was a problem hiding this comment.
Disable queue admission while stopping runs on quit
When the app quits with both active and queued turns, stopAll() calls clearRun() for each active turn, and this microtask runs immediately after the synchronous stop phase yields in runAppCleanup. It can therefore launch queued agents during shutdown; those agents were not in stopAll()'s snapshot and may spawn detached provider processes or persist a new working state just before exit. Suppress admission while shutdown is in progress so queued turns remain parked for the documented boot-time admission.
Useful? React with 👍 / 👎.
| // startRun is synchronous up to claiming its `active` slot, so the | ||
| // next iteration already sees this one counted. | ||
| startRun({ ...input, threadId: t.id, fromRunQueue: true }).catch( |
There was a problem hiding this comment.
Reserve each slot before launching an admitted run
On a normal desktop boot with persisted queued turns, the login-shell PATH promise is still pending when this loop runs. Every startRun() call awaits that promise before reaching active.set, so this non-awaited loop sees the same free-slot count for every item, clears all their runQueue records, and schedules all of them; once PATH resolves, fromRunQueue bypasses the concurrency gate and the cap can be exceeded by the entire saved queue. Reserve a slot synchronously or serialize admissions until each start claims active.
Useful? React with 👍 / 👎.
| if ( | ||
| thread.memoryConsolidate !== true && | ||
| !input.fromRunQueue && |
There was a problem hiding this comment.
Apply the concurrency gate before the Ask-mode return
When an Ask-mode thread is started while the cap is full or older turns are queued, execution has already returned through startAskRun() before reaching this gate. That function adds the Ask turn to the same active map counted by runSlotsFree, so Ask starts can exceed maxConcurrentRuns and jump the FIFO queue; only memory consolidation is declared exempt. Run the queue decision before the Ask-mode dispatch while retaining Ask's budget and worktree exemptions.
Useful? React with 👍 / 👎.
Settings-level maxConcurrentRuns (default 4, null = no cap). Starts beyond the cap park their turn on the thread as runQueue and are admitted FIFO as runs settle; Stop leaves the queue. Queue position shows in the Agents panel. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ee94e6b to
fb64850
Compare
Closes #166.
What
maxConcurrentRuns(Settings → Spending), default 4, empty/null = no cap.startRun(after the budget and provider-binary checks, so a missing CLI still fails fast and pool failover still works): a start beyond the cap appends the user message, parks the fully-built turn on the thread asrunQueue(persisted), posts a "Queued #N" event and returns{ runId: null, queued: true }.clearRun→admitQueuedRunsstarts the oldest turns while slots are free. Raising or clearing the cap admits right away. Turns queued at quit are admitted on boot.queued #Nbadge plus stop button on queued worker rows.Not covered
Tests
electron/test/run-queue.test.js: queue/FIFO admission, one user message per turn, Stop leaves the queue, clearing the cap admits.test/teamView.test.tsx: queue line, worker badge, Leave queue.🤖 Generated with Claude Code