-
Notifications
You must be signed in to change notification settings - Fork 3
feat(speculation): add path scorer extension #316
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-enumerator
Choose a base branch
from
preetam/ext/speculation-scorer
base: preetam/ext/speculation-enumerator
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.
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
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 = ["pathscorer.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/pathscorer", | ||
| 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,17 @@ | ||
| # Speculation Path Scorer | ||
|
|
||
| Vendor-agnostic interface for scoring the paths in a batch's **speculation tree** — the predicted-success probability of each candidate bet, recomputed as the batch's world changes. | ||
|
|
||
| See the [Speculation RFC](/doc/rfc/submitqueue/speculation.md) for the end-to-end design and how scoring fits into the orchestrator pipeline. | ||
|
|
||
| ## Scorer | ||
|
|
||
| A path's score is a **prediction**: *how likely is this bet to pay off, right now?* The scorer answers it from the current state — the per-batch success probabilities of a path's base batches (`entity.Batch.Score`, set by the score stage), which of those dependencies have already landed or had their build pass (resolved assumptions raise confidence), and optionally other signals such as how long the batch has waited or historical pass rates. The score is the common currency the [selector](../selector) and prioritizer both rank on, so keeping it current is what makes both act on the latest reality. | ||
|
|
||
| Because it is a prediction over live state, the scorer is **re-run on every respeculate**, right after the controller reconciles path status — so when a dependency lands, its build passes, or a sibling path fails, the surviving paths' scores are recomputed before anything is selected or prioritized. The controller drives *when* to rescore (it is part of reconciliation) and persists the result; the scorer owns the *formula*. | ||
|
|
||
| This is the per-**path** scorer, distinct from the per-**batch** [score stage](../../scorer), which sets `entity.Batch.Score`. The path scorer consumes those batch scores to score whole paths. The controller hands it the batch's **speculation tree** directly — the subject it scores — and any richer signal an implementation needs (the dependency batches' scores, historical pass rates) is injected at its factory, not passed in. It never writes: it returns the scored tree and the controller persists the scores, so the controller stays the single writer of tree state. Path structure and status pass through unchanged; only `Score` is recomputed. | ||
|
|
||
| ## Factory | ||
|
|
||
| A per-queue factory returns the scorer for a queue, following the repo's extension contract. It is handed only the queue identity; scoring knobs and read access to any extra signals are injected at construction by the integrator in the wiring layer, which resolves per-queue settings through `queueconfig`. Scoring itself stays config-free. |
23 changes: 23 additions & 0 deletions
23
submitqueue/extension/speculation/pathscorer/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/pathscorer/fake", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//submitqueue/entity:go_default_library", | ||
| "//submitqueue/extension/speculation/pathscorer: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", | ||
| ], | ||
| ) |
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,67 @@ | ||
| // 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 pathscorer.Scorer for tests and examples. By | ||
| // default Score echoes the tree it is given; Returns overrides that with a | ||
| // canned scored tree, and 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/entity" | ||
| "github.com/uber/submitqueue/submitqueue/extension/speculation/pathscorer" | ||
| ) | ||
|
|
||
| // Scorer is a programmable pathscorer.Scorer. | ||
| type Scorer struct { | ||
| tree entity.SpeculationTree | ||
| hasTree bool | ||
| err error | ||
| } | ||
|
|
||
| // New returns a fake Scorer that echoes the tree it is given. Override the | ||
| // returned tree with Returns. | ||
| func New() *Scorer { | ||
| return &Scorer{} | ||
| } | ||
|
|
||
| // Returns makes every Score call return tree instead of echoing its input. | ||
| func (s *Scorer) Returns(tree entity.SpeculationTree) *Scorer { | ||
| s.tree = tree | ||
| s.hasTree = true | ||
| return s | ||
| } | ||
|
|
||
| // FailWith makes every Score call return err. | ||
| func (s *Scorer) FailWith(err error) *Scorer { | ||
| s.err = err | ||
| return s | ||
| } | ||
|
|
||
| // Score returns the canned tree if one was set with Returns, otherwise the tree | ||
| // it was given, unchanged. | ||
| func (s *Scorer) Score(_ context.Context, tree entity.SpeculationTree) (entity.SpeculationTree, error) { | ||
| if s.err != nil { | ||
| return entity.SpeculationTree{}, s.err | ||
| } | ||
| if s.hasTree { | ||
| return s.tree, nil | ||
| } | ||
| return tree, nil | ||
| } | ||
|
|
||
| // ensure the fake satisfies the interface. | ||
| var _ pathscorer.Scorer = (*Scorer)(nil) |
56 changes: 56 additions & 0 deletions
56
submitqueue/extension/speculation/pathscorer/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,56 @@ | ||
| // 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" | ||
| "github.com/uber/submitqueue/submitqueue/entity" | ||
| ) | ||
|
|
||
| func TestScore_EchoesInputByDefault(t *testing.T) { | ||
| tree := entity.SpeculationTree{ | ||
| BatchID: "q/batch/2", | ||
| Paths: []entity.SpeculationPathInfo{ | ||
| {Path: entity.SpeculationPath{Head: "q/batch/2"}, Score: 0.9}, | ||
| }, | ||
| } | ||
| got, err := New().Score(context.Background(), tree) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tree, got) | ||
| } | ||
|
|
||
| func TestScore_ReturnsCanned(t *testing.T) { | ||
| in := entity.SpeculationTree{BatchID: "q/batch/2"} | ||
| scored := entity.SpeculationTree{ | ||
| BatchID: "q/batch/2", | ||
| Paths: []entity.SpeculationPathInfo{ | ||
| {Path: entity.SpeculationPath{Head: "q/batch/2"}, Score: 0.75}, | ||
| }, | ||
| } | ||
| got, err := New().Returns(scored).Score(context.Background(), in) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, scored, got) | ||
| } | ||
|
|
||
| func TestScore_FailWith(t *testing.T) { | ||
| sentinel := errors.New("boom") | ||
| _, err := New().FailWith(sentinel).Score(context.Background(), entity.SpeculationTree{BatchID: "q/batch/1"}) | ||
| require.ErrorIs(t, err, sentinel) | ||
| } |
13 changes: 13 additions & 0 deletions
13
submitqueue/extension/speculation/pathscorer/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 = ["pathscorer_mock.go"], | ||
| importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/pathscorer/mock", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//submitqueue/entity:go_default_library", | ||
| "//submitqueue/extension/speculation/pathscorer:go_default_library", | ||
| "@org_uber_go_mock//gomock:go_default_library", | ||
| ], | ||
| ) |
97 changes: 97 additions & 0 deletions
97
submitqueue/extension/speculation/pathscorer/mock/pathscorer_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
submitqueue/extension/speculation/pathscorer/pathscorer.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,73 @@ | ||
| // 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 pathscorer | ||
|
|
||
| //go:generate mockgen -source=pathscorer.go -destination=mock/pathscorer_mock.go -package=mock | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/uber/submitqueue/submitqueue/entity" | ||
| ) | ||
|
|
||
| // Scorer computes the predicted-success score of every path in a batch's | ||
| // speculation tree. | ||
| // | ||
| // A path's score is a prediction — "how likely is this bet to pay off?" — and | ||
| // predictions must move as evidence arrives. The scorer answers "how good is | ||
| // each path right now" from the current state: the per-batch success | ||
| // probabilities of a path's base batches (entity.Batch.Score, set by the score | ||
| // stage), which of those dependencies have already landed or had their build | ||
| // pass (resolved assumptions raise confidence), and optionally other signals | ||
| // (how long the batch has waited, historical pass rates). | ||
| // | ||
| // The controller re-runs the scorer on every respeculate, right after it | ||
| // reconciles path status — so when a dependency lands, its build passes, or a | ||
| // sibling path fails, the surviving paths' scores are recomputed against the new | ||
| // reality before anything is selected or prioritized. The controller drives | ||
| // *when* to rescore and persists the result; the scorer owns the *formula*. | ||
| // | ||
| // This is the per-*path* scorer, distinct from the per-*batch* score stage | ||
| // (extension/scorer), which sets entity.Batch.Score. The path scorer consumes | ||
| // those batch scores to score whole paths. | ||
| // | ||
| // The controller hands the scorer the batch's speculation tree directly — the | ||
| // subject it scores. Any richer signal an implementation needs (the dependency | ||
| // batches' scores, historical pass rates) is injected at its Factory, not passed | ||
| // here. It never writes: it returns the scored tree and the controller persists | ||
| // the scores, keeping the controller the single writer of tree state. | ||
| type Scorer interface { | ||
| // Score returns the given tree with each path's Score set to its freshly | ||
| // computed predicted-success value. Path structure and controller-stamped | ||
| // Status are carried through unchanged; only Score is (re)computed. The | ||
| // combination formula is the implementation's concern. | ||
| Score(ctx context.Context, tree entity.SpeculationTree) (entity.SpeculationTree, error) | ||
| } | ||
|
|
||
| // Config carries the per-queue identity handed to a Factory. The system knows | ||
| // only the queue name; everything an implementation needs (scoring knobs, and | ||
| // read access to any extra signals such as the dependency batches' scores) is | ||
| // injected at construction by the integrator. | ||
| type Config struct { | ||
| // QueueName identifies the queue this Scorer serves. | ||
| QueueName string | ||
| } | ||
|
|
||
| // Factory builds the Scorer for a queue. Implementations are provided by | ||
| // integrators (and tests) and inject whatever they need at construction. | ||
| type Factory interface { | ||
| // For returns the Scorer for the given queue. | ||
| For(cfg Config) (Scorer, 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.
Uh oh!
There was an error while loading. Please reload this page.