Conversation
…s uploads The optimize phase runs right after finalize, but finalize's PauseAndUpload pushes its uploads (snapshot data and the pre-prefetch metadata) onto the build's UploadErrGroup and returns immediately — the only wait for that group runs after every phase. The optimize phase then collected its mapping and re-uploaded metadata with no ordering against the finalize goroutine, so the two writers raced on the same metadata object for the build: an interleaving where the finalize upload finished last clobbered the just-uploaded prefetch mapping (silent loss, manifests as "prefetch mapping sometimes missing"). finalizeUploadsSettled now waits on the build's UploadErrGroup before the optimize phase re-uploads metadata. A failed finalize upload skips publishing — the remote build is incomplete, and the same error resurfaces at the builder-level wait, so the build still fails loudly. Test: TestFinalizeUploadsSettled covers the settled, failed, blocked (ordering invariant: the gate does not return while the finalize upload is in flight) and nil-group cases. Co-Authored-By: Claude <noreply@anthropic.com>
JooKS-me
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
September 15, 2026 12:02
|
We require contributors to sign our Contributor License Agreement, and we don't have @JooKS-me on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check' |
Author
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
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.
Problem
The optimize phase (
packages/orchestrator/pkg/template/build/phases/optimize, from #1705)runs right after finalize, but finalize's
PauseAndUploadpushes its uploads — snapshotdata and the pre-prefetch metadata — onto the build's
UploadErrGroupand returnsimmediately. The only wait for that group runs at the builder level, after every
phase has completed.
So the optimize phase collects its intersection mapping and calls
updateMetadatawithno ordering against the finalize goroutine: two writers race on the same metadata
object for the build. An interleaving where the finalize upload finishes last clobbers
the just-uploaded prefetch mapping — a silent loss that would manifest as "prefetch
mapping sometimes missing" for freshly built templates, with nothing in the logs.
Solution
finalizeUploadsSettled()gates the optimize phase's metadata re-upload on the build'sUploadErrGroup:updateMetadatapublishes the prefetch-enriched metadata. The mapping can no longerinterleave with the finalize upload.
same error resurfaces at the builder-level
UploadErrGroup.Wait(), so the buildstill fails loudly rather than dangling a mapping over uploads that never landed.
The gate sits after
collectMemoryPrefetchMapping(the expensive part), so the waitoverlaps the tail of the finalize upload rather than adding to the critical path.