Skip to content

Commit d89bfe4

Browse files
committed
feat(speculation): speculator extension contract
Add submitqueue/extension/speculation/speculator, the one controller-facing speculation extension. Speculate returns the build and cancel actions to take from a queue snapshot and can never express a verdict; Config/Factory carry per-queue wiring. Includes the generated mocks. Register the speculation packages with the mocks make target so `make mocks` regenerates them.
1 parent f905059 commit d89bfe4

6 files changed

Lines changed: 187 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ local-stovepipe-stop: ## Stop the Stovepipe service
366366

367367
mocks: ## Generate mock files using mockgen
368368
@echo "Generating mocks..."
369-
@$(BAZEL) run @rules_go//go -- generate ./submitqueue/extension/storage/... ./submitqueue/extension/buildrunner/... ./submitqueue/extension/changeprovider/... ./platform/extension/counter/... ./platform/extension/messagequeue/... ./submitqueue/extension/queueconfig/... ./submitqueue/extension/mergechecker/... ./submitqueue/extension/pusher/... ./submitqueue/extension/scorer/... ./submitqueue/extension/conflict/... ./submitqueue/extension/validator/... ./platform/consumer/... ./stovepipe/extension/storage/... ./stovepipe/extension/sourcecontrol/...
369+
@$(BAZEL) run @rules_go//go -- generate ./submitqueue/extension/storage/... ./submitqueue/extension/buildrunner/... ./submitqueue/extension/changeprovider/... ./platform/extension/counter/... ./platform/extension/messagequeue/... ./submitqueue/extension/queueconfig/... ./submitqueue/extension/mergechecker/... ./submitqueue/extension/pusher/... ./submitqueue/extension/scorer/... ./submitqueue/extension/conflict/... ./submitqueue/extension/speculation/... ./submitqueue/extension/validator/... ./platform/consumer/... ./stovepipe/extension/storage/... ./stovepipe/extension/sourcecontrol/...
370370
@echo "Mocks generated successfully!"
371371

372372
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 = "go_default_library",
5+
srcs = ["speculator.go"],
6+
importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/speculator",
7+
visibility = ["//visibility:public"],
8+
deps = ["//submitqueue/entity:go_default_library"],
9+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# speculator
2+
3+
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.
4+
5+
`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.
6+
7+
`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.
8+
9+
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.
10+
11+
## Adding a backend
12+
13+
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.
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 = "go_default_library",
5+
srcs = ["speculator_mock.go"],
6+
importpath = "github.com/uber/submitqueue/submitqueue/extension/speculation/speculator/mock",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//submitqueue/entity:go_default_library",
10+
"//submitqueue/extension/speculation/speculator:go_default_library",
11+
"@org_uber_go_mock//gomock:go_default_library",
12+
],
13+
)

submitqueue/extension/speculation/speculator/mock/speculator_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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 speculator
16+
17+
//go:generate mockgen -source=speculator.go -destination=mock/speculator_mock.go -package=mock
18+
19+
import (
20+
"context"
21+
22+
"github.com/uber/submitqueue/submitqueue/entity"
23+
)
24+
25+
// Speculator decides which speculation paths to build and which running ones to
26+
// cancel, within the queue's build budget. It is the only speculation extension the
27+
// speculate controller calls. It can never express a verdict: whether a batch
28+
// merges or fails is fixed by the facts and computed by the controller, so a
29+
// swapped-in Speculator changes which paths run, never a batch's outcome.
30+
type Speculator interface {
31+
// Speculate is handed the queue's in-flight batches plus any finalized
32+
// batches still referenced as dependencies (each with its dependency list and
33+
// state) and every path set for them — live and recently finished, so it will
34+
// not re-propose a path that already passed or failed. It returns the build
35+
// and cancel actions it proposes; a path it wants left as-is has no entry in
36+
// the result.
37+
Speculate(ctx context.Context, batches []entity.Batch, pathSets []entity.SpeculationPathSet) ([]entity.Speculation, error)
38+
}
39+
40+
// Config carries the per-queue identity handed to a Factory. The system knows
41+
// only the queue name; everything an implementation needs is injected at
42+
// construction by the integrator.
43+
type Config struct {
44+
// QueueName identifies the queue this Speculator serves.
45+
QueueName string
46+
}
47+
48+
// Factory builds the Speculator for a queue. Implementations are provided by
49+
// integrators (and tests) and inject whatever they need — budget, depth bound,
50+
// clock, and any extra data — at construction.
51+
type Factory interface {
52+
// For returns the Speculator for the given queue.
53+
For(cfg Config) (Speculator, error)
54+
}

0 commit comments

Comments
 (0)