feat(speculation): generator contract and bestfirst impl - #446
Merged
Conversation
This was referenced Jul 27, 2026
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
3 times, most recently
from
July 27, 2026 23:14
c8ec6b1 to
3fb7e2b
Compare
behinddwalls
marked this pull request as ready for review
July 27, 2026 23:17
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
2 times, most recently
from
July 28, 2026 19:13
5e0bdbd to
3fb7e2b
Compare
This was referenced Jul 28, 2026
sbalabanov
requested changes
Jul 28, 2026
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
July 29, 2026 18:12
3fb7e2b to
5e2ad89
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
July 29, 2026 18:24
5e2ad89 to
4c727b2
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
July 29, 2026 22:31
4c727b2 to
ccb1aa4
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
3 times, most recently
from
July 29, 2026 23:18
e9e54ca to
ee4ab40
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
July 29, 2026 23:18
ee4ab40 to
d5dd68b
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
July 30, 2026 01:19
d5dd68b to
e3d56b0
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
7 times, most recently
from
August 5, 2026 04:57
727009d to
110a679
Compare
behinddwalls
changed the base branch from
main
to
preetam/speculation-generator-rfc
August 5, 2026 05:05
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
August 5, 2026 17:05
110a679 to
60850bb
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
2 times, most recently
from
August 5, 2026 19:05
22e1452 to
e4f82f3
Compare
sbalabanov
approved these changes
Aug 5, 2026
sbalabanov
left a comment
Contributor
There was a problem hiding this comment.
accepting to unblock, please address comments
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
August 6, 2026 02:15
e4f82f3 to
334f49e
Compare
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
2 times, most recently
from
August 6, 2026 03:04
ae9aab0 to
28e0ab5
Compare
## Summary ### Why? The standard Speculator needs a ranked stream of candidate speculation paths to fund. Nothing enumerates or ranks the path space today. ### What? Adds `submitqueue/extension/speculation/generator` — the Generator/Iterator contract — plus the `bestfirst` implementation and mocks. The generator is a pure enumerator: `Generate` takes only the queue’s batches and offers every coherent path, including ones whose builds already ran. Suppressing those belongs to the Allocator, which reconciles candidates against stored path sets by ID. The snapshot is a strict contract: every batch a head’s direct dependencies reference must be present, and a snapshot with a missing dependency, empty or duplicate IDs, or a self or repeated dependency errors instead of opening a stream — any defaulting for a batch that is hard to score belongs to the scorer, not the generator. `bestfirst` ranks each path by how likely all its assumptions are to hold and generates lazily in two levels: each head enumerates its own paths through a per-head stream — extend/swap moves over a cheapest-first flip list, worked out only when the head is first pulled — and a global heap holds each head’s current best, so pulling k paths does O(k) work however large the space behind them. Scores are summed log probabilities so wide heads cannot underflow into ties, every score is summed fresh from the head’s best score so the ordering holds in floating point as computed, and the extend/swap tree emits each path exactly once in non-increasing score order. The full algorithm, tie-breaks, derivation, and floating-point constraints live in `doc/rfc/submitqueue/speculation-generator-best-first.md`; the package README records only operational behavior. Also clarifies `scorer.Scorer`’s contract as final success: the probability that the batch ultimately succeeds — reaches its terminal Succeeded state with its changes landed — not merely that its build passes. That is the quantity bestfirst consumes: a path’s assumptions resolve at terminal batch states, and a Merging dependency has already passed its build yet can still fail to land. ## Test Plan ✅ `./tool/bazel test //submitqueue/extension/speculation/...` ✅ `make fmt` ✅ `make lint` ✅ `make check-tidy` ✅ `make check-gazelle` ✅ `make check-mocks` — fails only on the pre-existing `storage/mock/request_batch_store_mock.go` header drift that exists on `main`; the new `generator/mock` is up to date
behinddwalls
force-pushed
the
preetam/speculation-generator
branch
from
August 6, 2026 03:17
28e0ab5 to
90bdbe3
Compare
behinddwalls
temporarily deployed
to
stack-rebase
August 6, 2026 03:32 — with
GitHub Actions
Inactive
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
Why?
The standard Speculator needs a ranked stream of candidate speculation paths to fund. Nothing enumerates or ranks the path space today.
What?
Adds
submitqueue/extension/speculation/generator— the Generator/Iterator contract — plus thebestfirstimplementation and mocks.The generator is a pure enumerator:
Generatetakes only the queue’s batches and offers every coherent path, including ones whose builds already ran. Suppressing those belongs to the Allocator, which reconciles candidates against stored path sets by ID. The snapshot is a strict contract: every batch a head’s direct dependencies reference must be present, and a snapshot with a missing dependency, empty or duplicate IDs, or a self or repeated dependency errors instead of opening a stream — any defaulting for a batch that is hard to score belongs to the scorer, not the generator.bestfirstranks each path by how likely all its assumptions are to hold and generates lazily in two levels: each head enumerates its own paths through a per-head stream — extend/swap moves over a cheapest-first flip list, worked out only when the head is first pulled — and a global heap holds each head’s current best, so pulling k paths does O(k) work however large the space behind them. Scores are summed log probabilities so wide heads cannot underflow into ties, every score is summed fresh from the head’s best score so the ordering holds in floating point as computed, and the extend/swap tree emits each path exactly once in non-increasing score order. The full algorithm, tie-breaks, derivation, and floating-point constraints live indoc/rfc/submitqueue/speculation-generator-best-first.md; the package README records only operational behavior.Also clarifies
scorer.Scorer’s contract as final success: the probability that the batch ultimately succeeds — reaches its terminal Succeeded state with its changes landed — not merely that its build passes. That is the quantity bestfirst consumes: a path’s assumptions resolve at terminal batch states, and a Merging dependency has already passed its build yet can still fail to land.Test Plan
✅
./tool/bazel test //submitqueue/extension/speculation/...✅
make fmt✅
make lint✅
make check-tidy✅
make check-gazelle✅
make check-mocks— fails only on the pre-existingstorage/mock/request_batch_store_mock.goheader drift that exists onmain; the newgenerator/mockis up to date