-
Notifications
You must be signed in to change notification settings - Fork 3
feat(speculation): add selector + selection-limit extensions #317
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/ext/speculation-scorer
Choose a base branch
from
preetam/ext/speculation-selector
base: preetam/ext/speculation-scorer
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+630
−1
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,8 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["selectionlimit.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/selectionlimit", | ||
| visibility = ["//visibility:public"], | ||
| ) |
17 changes: 17 additions & 0 deletions
17
submitqueue/extension/speculation/selectionlimit/README.md
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,17 @@ | ||
| # Speculation Selection Limit | ||
|
|
||
| Vendor-agnostic "how much" policy that bounds how many paths a batch may build in parallel. | ||
|
|
||
| See the [Speculation RFC](../../../../doc/rfc/submitqueue/speculation.md) for the end-to-end design and how limits fit into the two-layer speculation model. | ||
|
|
||
| ## Selection Limit | ||
|
|
||
| The selection limit is the [selector](../selector)'s companion. The selector decides **which** of a batch's paths are worth building — its ranking over the tree; the selection limit decides **how many** of them may run at once. Keeping "which" and "how much" separate keeps selector logic free of resource accounting and lets the bound scale with build resources without touching that logic. | ||
|
|
||
| The value is **signal-driven**, not a fixed constant. Its primary input is the build system's available capacity, but a policy may also weigh historical pass rates, cost budgets, time of day, or an experiment toggle. | ||
|
|
||
| Unlike the dependency limit — which the controller holds and applies as an eligibility gate — the selection limit is **injected into the seam that uses it**: the selector is constructed with it and calls it itself, never receiving it as a method parameter. This follows the repo's extension-contract pattern (dependencies injected at the `Factory`), keeps the selector interface limit-free and stable, and lets the limit be swapped independently of selector logic. | ||
|
|
||
| ## Factory | ||
|
|
||
| A per-queue factory returns the limit policy for a queue, following the repo's extension contract. It is handed only the queue identity; the signals a policy weighs — a capacity feed, historical metrics, config — are injected at construction by the integrator in the wiring layer, which is also where the limit is handed to the selector. Computing the limit itself takes no further inputs. | ||
19 changes: 19 additions & 0 deletions
19
submitqueue/extension/speculation/selectionlimit/fake/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,19 @@ | ||
| load("@rules_go//go:def.bzl", "go_library", "go_test") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["fake.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/selectionlimit/fake", | ||
| visibility = ["//visibility:public"], | ||
| deps = ["//submitqueue/extension/speculation/selectionlimit:go_default_library"], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "go_default_test", | ||
| srcs = ["fake_test.go"], | ||
| embed = [":go_default_library"], | ||
| deps = [ | ||
| "@com_github_stretchr_testify//assert:go_default_library", | ||
| "@com_github_stretchr_testify//require:go_default_library", | ||
| ], | ||
| ) |
52 changes: 52 additions & 0 deletions
52
submitqueue/extension/speculation/selectionlimit/fake/fake.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,52 @@ | ||
| // 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 fake provides a programmable selectionlimit.SelectionLimit for tests | ||
| // and examples. New sets the value returned by Limit; FailWith injects an error | ||
| // on every call. It is intended for examples and tests only, never production. | ||
| package fake | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/uber/submitqueue/submitqueue/extension/speculation/selectionlimit" | ||
| ) | ||
|
|
||
| // SelectionLimit is a programmable selectionlimit.SelectionLimit. | ||
| type SelectionLimit struct { | ||
| limit int | ||
| err error | ||
| } | ||
|
|
||
| // New returns a fake SelectionLimit whose Limit returns the given value. | ||
| func New(limit int) *SelectionLimit { | ||
| return &SelectionLimit{limit: limit} | ||
| } | ||
|
|
||
| // FailWith makes every Limit call return err. | ||
| func (l *SelectionLimit) FailWith(err error) *SelectionLimit { | ||
| l.err = err | ||
| return l | ||
| } | ||
|
|
||
| // Limit returns the configured value, or the injected error if FailWith was set. | ||
| func (l *SelectionLimit) Limit(_ context.Context) (int, error) { | ||
| if l.err != nil { | ||
| return 0, l.err | ||
| } | ||
| return l.limit, nil | ||
| } | ||
|
|
||
| // ensure the fake satisfies the interface. | ||
| var _ selectionlimit.SelectionLimit = (*SelectionLimit)(nil) |
36 changes: 36 additions & 0 deletions
36
submitqueue/extension/speculation/selectionlimit/fake/fake_test.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,36 @@ | ||
| // 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 fake | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestLimit_ReturnsConfiguredValue(t *testing.T) { | ||
| got, err := New(2).Limit(context.Background()) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 2, got) | ||
| } | ||
|
|
||
| func TestLimit_FailWith(t *testing.T) { | ||
| sentinel := errors.New("boom") | ||
| _, err := New(2).FailWith(sentinel).Limit(context.Background()) | ||
| require.ErrorIs(t, err, sentinel) | ||
| } |
12 changes: 12 additions & 0 deletions
12
submitqueue/extension/speculation/selectionlimit/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,12 @@ | ||
| load("@rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["selectionlimit_mock.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/selectionlimit/mock", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//submitqueue/extension/speculation/selectionlimit:go_default_library", | ||
| "@org_uber_go_mock//gomock:go_default_library", | ||
| ], | ||
| ) |
96 changes: 96 additions & 0 deletions
96
submitqueue/extension/speculation/selectionlimit/mock/selectionlimit_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
submitqueue/extension/speculation/selectionlimit/selectionlimit.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,57 @@ | ||
| // 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 selectionlimit | ||
|
|
||
| //go:generate mockgen -source=selectionlimit.go -destination=mock/selectionlimit_mock.go -package=mock | ||
|
|
||
| import "context" | ||
|
|
||
| // SelectionLimit is the "how much" policy that bounds how many paths a batch may | ||
| // build in parallel. | ||
| // | ||
| // It is the selector's companion: the selector decides *which* of a batch's | ||
| // paths are worth building (its ranking); the selection limit decides *how many* | ||
| // of them may run at once. Separating the two keeps selector logic free of | ||
| // resource accounting and lets the bound scale with build resources without | ||
| // touching that logic. | ||
| // | ||
| // The value is dynamic: it may change between calls, so the selector reads it | ||
| // each pass rather than caching it. | ||
| // | ||
| // Unlike the dependency limit, this limit is injected into the seam that uses it | ||
| // — the selector is constructed with it and calls it itself — never passed as a | ||
| // method parameter, keeping the selector interface limit-free and stable. | ||
| type SelectionLimit interface { | ||
| // Limit returns the current maximum number of paths a batch may build in | ||
| // parallel. The selector caps its Promote decisions at this. It takes no | ||
| // parameters; anything an implementation needs is injected at construction. | ||
| Limit(ctx context.Context) (int, error) | ||
| } | ||
|
|
||
| // Config carries the per-queue identity handed to a Factory. The system knows | ||
| // only the queue name; everything a policy needs to compute the limit (a | ||
| // capacity feed, historical metrics, config) is injected at construction by the | ||
| // integrator. | ||
| type Config struct { | ||
| // QueueName identifies the queue this SelectionLimit serves. | ||
| QueueName string | ||
| } | ||
|
|
||
| // Factory builds the SelectionLimit for a queue. Implementations are provided by | ||
| // integrators (and tests) and inject whatever signals they need at construction. | ||
| type Factory interface { | ||
| // For returns the SelectionLimit for the given queue. | ||
| For(cfg Config) (SelectionLimit, error) | ||
| } |
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 = ["selector.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/selector", | ||
| 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,19 @@ | ||
| # Speculation Path Selector | ||
|
|
||
| Vendor-agnostic interface for deciding what the orchestrator should do with each path in a batch's enumerated speculation tree. | ||
|
|
||
| See the [Speculation RFC](../../../../doc/rfc/submitqueue/speculation.md) for the end-to-end design and how selection fits into the orchestrator pipeline. | ||
|
|
||
| ## Selector | ||
|
|
||
| A selector is the **policy** — the part that decides how aggressively to spend build resources. *Given the candidate paths in the batch's tree and their current status, what should we do with each, right now?* It returns an **action** per path — `Promote` (advance it one stage toward running) or `Cancel`. Strategies span a spectrum: build only the single optimistic path (cheapest — bet on the happy case), build every candidate (maximum parallelism, maximum build cost), or a top-K / budget-bounded subset in between. | ||
|
|
||
| The selector decides only where to spend build resources. It does **not** decide merging: a path becomes mergeable when its build passed and its base matches what actually landed, which is deterministic, not a policy choice — so the controller finalizes it on its own. | ||
|
|
||
| The controller hands the selector the batch's **speculation tree** directly — the subject it decides over. The controller is the single writer: it reconciles each path's status (candidate, selected, prioritized, building, passed, failed, cancelling, cancelled) from the latest builds and dependency states, and it maps each of the selector's decisions to a status transition — `Promote` → `Selected`, `Cancel` → `Cancelling` (or `Cancelled` when nothing is building) — applied under the tree's optimistic lock and persisted. The selector's only output is decisions; it **never** writes status. This keeps it a deterministic policy over the tree it is given. | ||
|
|
||
| Because it is re-run on every build signal, a selector can start narrow — build the optimistic path first — and widen later, committing more paths only once earlier bets resolve. Returning no action for a path leaves it as-is. Policy parameters — a top-K cap, a build budget, an experiment toggle — are configured when the selector is constructed rather than passed through this contract. | ||
|
|
||
| ## Factory | ||
|
|
||
| A per-queue factory returns the selector for a queue, following the repo's extension contract. It is handed only the queue identity and nothing else; policy knobs — a top-K cap, a build budget, an experiment toggle — are injected at construction by the integrator in the wiring layer, which resolves per-queue settings through `queueconfig`. Selection itself stays config-free. |
23 changes: 23 additions & 0 deletions
23
submitqueue/extension/speculation/selector/fake/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,23 @@ | ||
| load("@rules_go//go:def.bzl", "go_library", "go_test") | ||
|
|
||
| go_library( | ||
| name = "go_default_library", | ||
| srcs = ["fake.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/selector/fake", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//submitqueue/entity:go_default_library", | ||
| "//submitqueue/extension/speculation/selector:go_default_library", | ||
| ], | ||
| ) | ||
|
|
||
| go_test( | ||
| name = "go_default_test", | ||
| srcs = ["fake_test.go"], | ||
| embed = [":go_default_library"], | ||
| deps = [ | ||
| "//submitqueue/entity:go_default_library", | ||
| "@com_github_stretchr_testify//assert:go_default_library", | ||
| "@com_github_stretchr_testify//require:go_default_library", | ||
| ], | ||
| ) |
Oops, something went wrong.
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.
do relative to root path instead