fix(pickled-core): make mine features stage --max-parallel actually parallelize - #32
Merged
Merged
Conversation
…arallelize Calling FeatureDrafter.draft_from_story (sync HTTP) from inside an `async def` blocked the event loop for the entire LLM round-trip, so the asyncio.Semaphore never released to a waiting coroutine. The advertised `--max-parallel N` flag silently degraded to 1-way serial execution despite the loop and semaphore looking correct on paper. Concrete blast radius: a workspace with 50 surfaces and 5s LLM calls and `--max-parallel 8` should mine in ~63s but actually took ~250s — a 4× regression on a CLI flag advertised to do parallel work, paid in real LLM-latency wallclock. The stories stage was already correct because it scheduled the same kind of sync work via asyncio.to_thread; only the features stage missed that handoff. Fix: extract `_draft_one_sync` as a synchronous helper and dispatch it through `asyncio.to_thread` from the parallel runner. The interactive (non-quick) path now also calls `_draft_one_sync` directly instead of round-tripping through `asyncio.run` — a small cleanup that lets a test reliably observe the LLM call without dragging in event-loop machinery. Adds a regression test that monkeypatches FeatureDrafter to track peak concurrent in-flight calls; with the fix peak >= 2 and 8 jobs of 0.2s finish in well under 1.5s, while the previous code pinned peak at 1 and took ~1.6s on the same hardware. Co-authored-by: Bartłomiej Rosa <bartrosa@users.noreply.github.com>
bartrosa
marked this pull request as ready for review
August 26, 2026 10:42
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.
Bug and impact
pickled-spec mine features(andmine all) advertises--max-parallel Nto overlap LLM drafts, but the flag had no effect: every run was 1-way serial regardless of the value passed.Blast radius is real wallclock time on every mining run that exercises the features stage. With 50 surfaces and 5s LLM calls,
--max-parallel 8should finish in ~63s but actually took ~250s — a ~4× regression on an advertised CLI flag, paid in LLM-latency dollars and developer wait time.Reproduction (before fix): a
FakeDrafter.draft_from_storythat records peak concurrent invocations and sleeps 0.5s showsmax_concurrent observed: 1and ~4.0s elapsed for 8 jobs with--max-parallel 4— exactly the serial-execution profile.Root cause
In
packages/pickled-core/src/pickled_core/mine/features_stage.py,_draft_onewas anasync defthat invoked the synchronousFeatureDrafter.draft_from_storydirectly:_run_parallelthenawait-ed_draft_onethrough anasyncio.Semaphore. Because the coroutine never yielded to the event loop during the LLM round-trip, the semaphore never released to a waiting task, andasyncio.gatherran the coroutines effectively in series.The stories stage was already correct because it dispatched the same kind of sync work through
asyncio.to_thread; only the features stage missed that handoff.Fix
_draft_one_syncas a synchronous helper.asyncio.to_thread(_draft_one_sync, ...)._draft_one_syncdirectly (drops theasyncio.run(...)round-trip that served no purpose now that the function is sync).Validation
max_concurrent observed: 1, elapsed ~4.0s.max_concurrent observed: 4, elapsed ~1.0s.test_max_parallel_actually_overlaps_llm_callsregression test inpackages/pickled-core/tests/test_mine_features_stage.pythat monkeypatchesFeatureDrafterto track peak concurrent in-flight calls and asserts both peak ≥ 2 and elapsed < 1.5s for 8 jobs × 0.2s with--max-parallel 4.uv run pytest -q).ruff checkandmypyclean on touched files.