Skip to content

Commit 6ff6d6c

Browse files
committed
feat(speculation): add enumerator and selector extensions
Add the two pluggable seams from the speculation RFC, as vendor-agnostic extension interfaces under submitqueue/extension/speculation/. enumerator: given a batch and its dependency batches (carrying per-batch Score), mechanically lists the candidate Base/Head paths and scores each — pure, deterministic, status-free. selector: given a speculation tree with controller-stamped status, returns a per-path action (Build/Cancel) — the policy seam; reads status, emits actions, never writes status. Each follows the repo extension contract (conflict.Analyzer reference shape): Factory.For(Config) (T, error) with Config carrying only QueueName; behavioral knobs are integrator-injected at construction. Includes READMEs, gomock packages, and Makefile mock-gen wiring. Interfaces only; concrete impls and controller wiring are deferred.
1 parent 927e240 commit 6ff6d6c

11 files changed

Lines changed: 402 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ local-stovepipe-gateway-start: build-stovepipe-gateway-linux ## Start Stovepipe
336336

337337
mocks: ## Generate mock files using mockgen
338338
@echo "Generating mocks..."
339-
@$(BAZEL) run @rules_go//go -- generate ./submitqueue/extension/storage/... ./submitqueue/extension/buildrunner/... ./submitqueue/extension/changeprovider/... ./extension/counter/... ./extension/messagequeue/... ./submitqueue/extension/queueconfig/... ./submitqueue/extension/mergechecker/... ./submitqueue/extension/pusher/... ./submitqueue/extension/scorer/... ./submitqueue/extension/conflict/... ./submitqueue/core/consumer/...
339+
@$(BAZEL) run @rules_go//go -- generate ./submitqueue/extension/storage/... ./submitqueue/extension/buildrunner/... ./submitqueue/extension/changeprovider/... ./extension/counter/... ./extension/messagequeue/... ./submitqueue/extension/queueconfig/... ./submitqueue/extension/mergechecker/... ./submitqueue/extension/pusher/... ./submitqueue/extension/scorer/... ./submitqueue/extension/conflict/... ./submitqueue/extension/speculation/enumerator/... ./submitqueue/extension/speculation/selector/... ./submitqueue/core/consumer/...
340340
@echo "Mocks generated successfully!"
341341

342342
proto: ## Generate protobuf files from .proto definitions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "enumerator",
5+
srcs = ["enumerator.go"],
6+
importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/enumerator",
7+
visibility = ["//visibility:public"],
8+
deps = ["//submitqueue/entity"],
9+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Speculation Tree Enumerator
2+
3+
Vendor-agnostic interface for enumerating the **speculation tree** of a batch — the set of candidate speculation paths the orchestrator may build, each scored with its predicted probability of success.
4+
5+
See the [Speculation RFC](../../../../doc/rfc/submitqueue/speculation.md) for the end-to-end design and how enumeration fits into the orchestrator pipeline.
6+
7+
## Enumerator
8+
9+
An enumerator is deliberately **dumb**: *given a batch and its dependency batches, it mechanically lists the candidate paths and scores them.* It does **not** decide which paths to build — that is the [selector](../selector)'s job — it does **not** set path status, and it does **not** decide how far back to speculate. Speculation depth is the controller's responsibility: the controller trims the dependency list before calling the enumerator, which then enumerates over exactly the list it is handed.
10+
11+
Each candidate is a path: an assumed-good prefix of predecessor batches (the base) on top of which the batch under verification (the head) is built. The base maps directly onto the build stage's base changes and the head onto the changes being validated.
12+
13+
Enumeration is **pure and deterministic**: the same batch and dependency list always produce the same tree. This lets the controller regenerate a tree whenever the dependency graph changes without tracking incremental state in the enumerator. Keeping enumeration tractable for a very wide dependency list is the enumerator's only real concern.
14+
15+
Scores ride in on the inputs. Each dependency is passed as a full `entity.Batch`, which already carries its per-batch success probability (`Batch.Score`) from the score stage; the enumerator combines the scores of a path's base batches into the path's score. No separate scoring backend or injected probability source is needed, and tests just set `.Score` on literal batches. The head is passed as an ID — its score is constant across all of its own paths.
16+
17+
## Factory
18+
19+
`Factory.For(Config) (Enumerator, error)` returns the enumerator for a queue, following the repo's extension contract (`conflict.Analyzer` is the reference shape). `Config` carries only the queue identity (`QueueName`); the system hands the factory nothing else. Everything an implementation needs — including behavioral knobs like speculation depth — is injected at construction by the integrator in the wiring layer, which resolves per-queue settings through `queueconfig`. `Enumerate` itself stays config-free.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2025 Uber Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package enumerator
16+
17+
//go:generate mockgen -source=enumerator.go -destination=mock/enumerator_mock.go -package=mock
18+
19+
import (
20+
"context"
21+
22+
"github.com/uber/submitqueue/submitqueue/entity"
23+
)
24+
25+
// Enumerator builds the speculation tree for a batch: the set of candidate
26+
// speculation paths to consider, each scored with its predicted success
27+
// probability.
28+
//
29+
// Enumeration answers "what futures are possible" for a batch. It is
30+
// deliberately dumb: it mechanically lists candidate paths from the dependency
31+
// batches it is handed and attaches a Score to each. It does not decide which
32+
// paths to build — that is the selector's job (see
33+
// extension/speculation/selector) — and it does not decide how far back to
34+
// speculate: the controller trims the dependency list by speculation depth
35+
// before calling Enumerate.
36+
type Enumerator interface {
37+
// Enumerate returns the speculation tree for the batch identified by batchID,
38+
// given its dependency batches in arrival order. Each returned path carries a
39+
// Base/Head split and a predicted success Score; the returned paths leave
40+
// Status unset (the controller stamps it on persist).
41+
//
42+
// Path scores are derived from the dependency batches' Score field (the
43+
// per-batch success probability set by the score stage), so no separate
44+
// scoring backend is needed. The combination formula is the implementation's
45+
// concern.
46+
//
47+
// Enumeration is pure and deterministic: the same (batchID, deps) always
48+
// yields the same tree, so callers may regenerate safely.
49+
Enumerate(ctx context.Context, batchID string, deps []entity.Batch) (entity.SpeculationTree, error)
50+
}
51+
52+
// Config carries the per-queue identity handed to a Factory. The system knows
53+
// only the queue name; everything an implementation needs (including behavioral
54+
// knobs such as speculation depth) is injected at construction by the integrator.
55+
type Config struct {
56+
// QueueName identifies the queue this Enumerator serves.
57+
QueueName string
58+
}
59+
60+
// Factory builds the Enumerator for a queue. Implementations are provided by
61+
// integrators (and tests) and inject whatever they need at construction.
62+
type Factory interface {
63+
// For returns the Enumerator for the given queue.
64+
For(cfg Config) (Enumerator, error)
65+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "mock",
5+
srcs = ["enumerator_mock.go"],
6+
importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/enumerator/mock",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//submitqueue/entity",
10+
"//submitqueue/extension/speculation/enumerator",
11+
"@org_uber_go_mock//gomock",
12+
],
13+
)

submitqueue/extension/speculation/enumerator/mock/enumerator_mock.go

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "selector",
5+
srcs = ["selector.go"],
6+
importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/selector",
7+
visibility = ["//visibility:public"],
8+
deps = ["//submitqueue/entity"],
9+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Speculation Path Selector
2+
3+
Vendor-agnostic interface for deciding what the orchestrator should do with each path in a batch's enumerated speculation tree.
4+
5+
See the [Speculation RFC](../../../../doc/rfc/submitqueue/speculation.md) for the end-to-end design and how selection fits into the orchestrator pipeline.
6+
7+
## Selector
8+
9+
A selector is the **policy** — the part that decides how aggressively to spend build resources. *Given the candidate paths in a tree and their current status, what should we do with each, right now?* It consumes the tree produced by an [enumerator](../enumerator) and returns an **action** per path — `Build` 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.
10+
11+
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.
12+
13+
The selector's only output is actions; it **never** writes status. The controller owns every status write into the store — it reconciles each path's status (candidate, building, passed, failed, cancelled) from the latest builds and dependency states, then feeds the up-to-date tree back in. So the tree is the selector's **complete input**: it never reads storage, builds, or scores directly. This keeps it a pure, deterministic policy that is trivial to test against a literal tree.
14+
15+
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.
16+
17+
## Factory
18+
19+
`Factory.For(Config) (Selector, error)` returns the selector for a queue, following the repo's extension contract (`conflict.Analyzer` is the reference shape). `Config` carries only the queue identity (`QueueName`); the system hands the factory 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`. `Select` itself stays config-free.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "mock",
5+
srcs = ["selector_mock.go"],
6+
importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/selector/mock",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//submitqueue/entity",
10+
"//submitqueue/extension/speculation/selector",
11+
"@org_uber_go_mock//gomock",
12+
],
13+
)

submitqueue/extension/speculation/selector/mock/selector_mock.go

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)