Repository navigation
fix(indexer): keep every concurrency slot busy with a worker pool (#204) - #210
Open
MikeBishop wants to merge 1 commit into
Open
MikeBishop wants to merge 1 commit into
MikeBishop wants to merge 1 commit into
Conversation
…ra#204) processBatch() ran fixed batches: slice `concurrency` items, await Promise.all, then start the next slice. One slow item left the other slots idle until it finished. In a real `index --cleanup --concurrency 8` backfill, one long conversation (hierarchical summary, chunks run one after another) held the whole run at a single summarizer subprocess for over 20 minutes. Replace it with a worker pool: `concurrency` workers each pull the next item when their current one finishes. Peak concurrency is unchanged, so the bound on live summarizer subprocesses from obra#61 still holds. Results stay in input order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
index --cleanup --concurrency Ndoesn't keep N summarizations running.processBatch()insrc/indexer.tsruns fixed batches: it takes N items, awaitsPromise.all, and only then starts the next N. One slow item idles the other N−1 slots until it finishes.In a real backfill with
--concurrency 8, one long conversation (hierarchical summary, chunks summarized one after another) held the run at a single summarizer subprocess from 17:12 until about 17:58. The first 5 minutes had produced 39 summaries; that stretch produced none. Details in #204.Fix
Replace the fixed batches with a worker pool: N workers each pull the next item as soon as their current one finishes.
src/concurrency.ts(mapWithConcurrency) so it can be tested on its own.processBatch()insrc/indexer.tskeeps its signature and call sites and now delegates to it. That also keeps this PR from conflicting with fix(indexer): don't resume the parent session to summarize a subagent (#205) #208, which edits the code right next toprocessBatch().dist/is regenerated withnpm run build.dist/mcp-server.jsdoesn't bundle the indexer and isn't included.This covers part 1 of the proposal in #204, which gets most of the benefit: a long conversation now ties up one slot while the others keep working through the queue. Part 2, running its chunks through the same limit, would only help once it's the last item left, so I've left it out for now.
Test plan
test/concurrency.test.ts(4 tests):concurrencyitems run at once (peak measured: 4 of 4);main, where only item 1 can finish;npm test(full suite): 354/354 pass, 64 test files.npm run build: clean.npm testpasses 366/366.Refs #204.
Drafted with AI assistance (Claude Code). I reviewed the change; the timings are from my own backfill run.
🤖 Generated with Claude Code