feat(image): parallelize image_generate batches + serialize FileSyncManager cycles (salvage #33971) - #77596
Merged
kshitijk4poor merged 3 commits intoAug 3, 2026
Conversation
kshitijk4poor
enabled auto-merge (rebase)
August 3, 2026 11:20
kshitijk4poor
force-pushed
the
salvage/33971-image-parallel
branch
from
August 3, 2026 13:46
deb11db to
2a05b54
Compare
kshitijk4poor
force-pushed
the
salvage/33971-image-parallel
branch
from
August 3, 2026 17:16
2a05b54 to
828f67c
Compare
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.
Salvage of #33971 by @EndeavorYen — both commits cherry-picked verbatim (authorship preserved); the only conflict was test-file context drift (main deleted 3 stale postprocess tests that sat in the hunk's context; resolution keeps only the PR's new test).
What this does for users
image_generatejoins_PARALLEL_SAFE_TOOLS: when the model requests several images in one turn, they generate CONCURRENTLY instead of one-after-another. Generation latency is network-bound (seconds per image), so a 4-image batch completes in ~1× single-image latency instead of ~4×.image_gen.max_parallel_requestsin config.yaml (default 4, clamped 1..8) — follows the documented convention thatimage_genis an intentionally-absent DEFAULT_CONFIG root; documented in the website image-generation docs.FileSyncManager.sync()/sync_back()had no in-process serialization (the existingfcntl.flockis cross-process,sync_back-only, and a no-op on Windows). Concurrent artifact syncs could drop files from_synced_files(lost update). Now serialized by athreading.Lock.Verification
test_file_sync.py+test_image_generation_artifacts.py+ newtest_image_generate_parallel.py)second.pngdropped from_synced_files) — the tests bind the race, they are not change-detectors<prefix>_<ts>_<uuid4[:8]>), config read is mtime-cached (stat + deepcopy per batch, no YAML parse)("parallel", …)segment →_execute_tool_calls_concurrent; mixed batches take the same executor per segmentHonest caveat on the cap: a mixed batch (images + fast reads) shares one worker pool per parallel segment, so
max_parallel_requests: 1serializes unrelated tools in that segment — blunt but user-opted-in and clamped ≥1; reads drain in milliseconds through remaining slots at the default of 4.Closes #33971.