-
Notifications
You must be signed in to change notification settings - Fork 5
feat(speculation): speculator extension contract #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
behinddwalls
wants to merge
1
commit into
preetam/speculation-entities
from
preetam/speculation-speculator
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["speculator.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/speculator", | ||
| visibility = ["//visibility:public"], | ||
| deps = ["//submitqueue/entity:go_default_library"], | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # speculator | ||
|
|
||
| The `speculator` package defines the one speculation extension the speculate controller calls. A `Speculator` decides **which speculation paths to build and which running ones to cancel**, within the queue's build budget — and nothing else. It can never express a verdict: whether a batch merges or fails is fixed by the facts and computed by the controller, so swapping in a different `Speculator` changes which paths run, never a batch's outcome. | ||
|
|
||
| `Speculate` is handed the queue's in-flight batches plus any finalized batches still referenced as dependencies (each with its dependency list and state) and every path set for them — live and recently finished, so a `Speculator` will not re-propose a path that already passed or failed. It returns a list of build and cancel actions; a path it wants left as-is has no entry in the result. The controller validates the output (dropping builds it shouldn't propose and rejecting cancels of passed paths), so an implementation may read extra injected data without affecting correctness. | ||
|
|
||
| `Cancel` is a `Speculator`'s only cancel power — preempting an in-flight path to free budget for a better candidate. Correctness cancels (refuting a path whose bet a resolved dependency broke, and batch cancellation) belong to the controller and are not routed through the extension. | ||
|
|
||
| Like the other extensions, a `Speculator` is selected **per queue** by the wiring layer through the `Config` (queue name) and `Factory` interface. Budget, depth bound, clock, and any extra data are injected at construction by the integrator, not carried on the contract. | ||
|
|
||
| ## Adding a backend | ||
|
|
||
| Create a package under `speculator/<backend>/` whose `New(...)` returns a `speculator.Speculator`, injecting whatever it needs at construction. Resolve any content it requires internally; do not add a `Config` or `Factory` implementation here — per-queue routing and the factory adapter live in the wiring layer. |
13 changes: 13 additions & 0 deletions
13
submitqueue/extension/speculation/speculator/mock/BUILD.bazel
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["speculator_mock.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/speculator/mock", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//submitqueue/entity:go_default_library", | ||
| "//submitqueue/extension/speculation/speculator:go_default_library", | ||
| "@org_uber_go_mock//gomock:go_default_library", | ||
| ], | ||
| ) |
97 changes: 97 additions & 0 deletions
97
submitqueue/extension/speculation/speculator/mock/speculator_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
submitqueue/extension/speculation/speculator/speculator.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) 2025 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package speculator | ||
|
|
||
| //go:generate mockgen -source=speculator.go -destination=mock/speculator_mock.go -package=mock | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/uber/submitqueue/submitqueue/entity" | ||
| ) | ||
|
|
||
| // Speculator decides which speculation paths to build and which running ones to | ||
| // cancel, within the queue's build budget. It is the only speculation extension the | ||
| // speculate controller calls. It can never express a verdict: whether a batch | ||
| // merges or fails is fixed by the facts and computed by the controller, so a | ||
| // swapped-in Speculator changes which paths run, never a batch's outcome. | ||
| type Speculator interface { | ||
| // Speculate is handed the queue's in-flight batches plus any finalized | ||
| // batches still referenced as dependencies (each with its dependency list and | ||
| // state) and every path set for them — live and recently finished, so it will | ||
| // not re-propose a path that already passed or failed. It returns the build | ||
| // and cancel actions it proposes; a path it wants left as-is has no entry in | ||
| // the result. | ||
| Speculate(ctx context.Context, batches []entity.Batch, pathSets []entity.SpeculationPathSet) ([]entity.Speculation, error) | ||
| } | ||
|
|
||
| // Config carries the per-queue identity handed to a Factory. The system knows | ||
| // only the queue name; everything an implementation needs is injected at | ||
| // construction by the integrator. | ||
| type Config struct { | ||
| // QueueName identifies the queue this Speculator serves. | ||
| QueueName string | ||
| } | ||
|
|
||
| // Factory builds the Speculator for a queue. Implementations are provided by | ||
| // integrators (and tests) and inject whatever they need — budget, depth bound, | ||
| // clock, and any extra data — at construction. | ||
| type Factory interface { | ||
| // For returns the Speculator for the given queue. | ||
| For(cfg Config) (Speculator, error) | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a formal definition of arguments as a list? and return values, including error contract (i.e. context errors passed out).