Skip to content

feat(orchestrator): re-plan the queue from the Speculator each run - #506

Merged
behinddwalls merged 1 commit into
mainfrom
preetam/speculation-run
Aug 7, 2026
Merged

feat(orchestrator): re-plan the queue from the Speculator each run#506
behinddwalls merged 1 commit into
mainfrom
preetam/speculation-run

Conversation

@behinddwalls

@behinddwalls behinddwalls commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Why?

The speculate controller had no speculation in it: it advanced one batch at a time along a single hard-coded chain — every dependency assumed to pass — and nothing ever called the Speculator, the Generator, or the Allocator that had been built for it. This wires that machinery into the pipeline: a queue's paths are chosen by a swappable extension within a build budget, and each is built against only the dependencies it assumes will succeed.

What?

Every message is a dirty signal naming a batch; the controller re-plans that batch's whole queue from a single read: read the state, cancel paths whose assumptions a finished dependency has proven wrong, ask the Speculator, filter its proposals, dispatch what survives. Nothing carries over between runs, so duplicated or reordered signals are harmless and a later run repairs whatever an earlier one left half-done. doc.go explains the model in plain terms — no vocabulary section, every term is defined where it is used.

The path set keeps exactly one writer — this run. The build stages record what CI did on per-build records; the run folds those into the set and alone decides each path's status. Pending paths are re-dispatched every run until their build is seen running, dispatches partition by batch so heads proceed in parallel, and cancelling paths need no dispatch at all: the poll loop reads the stop off the set and enacts it.

Speculation lands inert. The wiring layer passes a placeholder Speculator that proposes nothing, so the run executes end to end but funds no paths; composing real per-queue speculators and turning the feature on is the wiring change at the top of this stack. Batch outcomes still come from the legacy per-batch finalizer, which waits on every dependency — strictly stricter than path-aware finalization, so the system stays correct until the next commit replaces it.

Test Plan

bazel test //submitqueue/orchestrator/controller/speculate/... — assumption checks and proposal filtering are table-driven; run tests cover funding a first path, re-dispatching pending paths, broken-path cancellation, build results recorded onto paths, lost CAS races skipped rather than failed, and Speculator errors abandoning the run.

make fmt, make gazelle

Issues

@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 8bd6b25 to f9ddb16 Compare August 4, 2026 04:46
@behinddwalls
behinddwalls marked this pull request as ready for review August 4, 2026 04:47
@behinddwalls
behinddwalls requested review from a team and sbalabanov as code owners August 4, 2026 04:47
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from f2e6633 to dda3dd3 Compare August 4, 2026 05:11
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from f9ddb16 to 55134c7 Compare August 4, 2026 05:11
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from dda3dd3 to 96feaf5 Compare August 5, 2026 03:15
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 55134c7 to 344901c Compare August 5, 2026 03:15
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from 96feaf5 to d450509 Compare August 5, 2026 03:26
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 344901c to 40fe38a Compare August 5, 2026 03:26
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from d450509 to 9227c40 Compare August 5, 2026 03:38
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 40fe38a to 2bd693a Compare August 5, 2026 03:38
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from 9227c40 to dbd61ed Compare August 5, 2026 03:44
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 2bd693a to a7b44df Compare August 5, 2026 03:44
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from dbd61ed to baf15bf Compare August 5, 2026 04:11
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from a7b44df to 329e026 Compare August 5, 2026 04:12
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from baf15bf to 82985ad Compare August 5, 2026 04:57
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 329e026 to 2d5e6e8 Compare August 5, 2026 04:57
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from 64f7e91 to d51250d Compare August 6, 2026 02:15
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 110416b to fd31568 Compare August 6, 2026 02:15
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from d51250d to 650a0d2 Compare August 6, 2026 02:34
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch 2 times, most recently from 99a2c76 to dcf9b20 Compare August 6, 2026 03:04
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch 2 times, most recently from a351b6b to 04e65c5 Compare August 6, 2026 03:17
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from dcf9b20 to 1087b03 Compare August 6, 2026 03:17
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from 04e65c5 to c167e22 Compare August 6, 2026 03:32
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 1087b03 to b9f222a Compare August 6, 2026 03:32
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from c167e22 to b2e22cc Compare August 7, 2026 03:15
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from b9f222a to 8c9e75e Compare August 7, 2026 03:15
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from b2e22cc to 10ac3fc Compare August 7, 2026 03:30
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 8c9e75e to d549bd7 Compare August 7, 2026 03:30

@mnoah1 mnoah1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few things but nothing major if you want to take a look later (other than the publishBatchID one).

Comment thread submitqueue/orchestrator/controller/speculate/dispatch.go Outdated
Comment thread submitqueue/orchestrator/controller/speculate/speculate.go Outdated
Comment thread submitqueue/orchestrator/controller/speculate/check.go
Comment thread submitqueue/orchestrator/controller/speculate/check.go
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from 10ac3fc to fc33bc5 Compare August 7, 2026 19:48
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from d549bd7 to a6ab892 Compare August 7, 2026 19:48
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from fc33bc5 to b8131db Compare August 7, 2026 19:54
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from a6ab892 to 0cb75fb Compare August 7, 2026 19:54
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from b8131db to 17bbf48 Compare August 7, 2026 20:13
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 0cb75fb to 830ba89 Compare August 7, 2026 20:13
@behinddwalls
behinddwalls force-pushed the preetam/speculation-cancel-msgid branch from 17bbf48 to 288ee84 Compare August 7, 2026 20:14
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 830ba89 to 8d5a6c2 Compare August 7, 2026 20:15
@behinddwalls
behinddwalls changed the base branch from preetam/speculation-cancel-msgid to main August 7, 2026 20:23
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from 8d5a6c2 to d346213 Compare August 7, 2026 20:23
## Summary

### Why?

The speculate controller had no speculation in it: it advanced one batch at a time along a single hard-coded chain — every dependency assumed to pass — and nothing ever called the Speculator, the Generator, or the Allocator that had been built for it. This wires that machinery into the pipeline: a queue's paths are chosen by a swappable extension within a build budget, and each is built against only the dependencies it assumes will succeed.

### What?

Every message is a dirty signal naming a batch; the controller re-plans that batch's whole queue from a single read: read the state, cancel paths whose assumptions a finished dependency has proven wrong, ask the Speculator, filter its proposals, dispatch what survives. Nothing carries over between runs, so duplicated or reordered signals are harmless and a later run repairs whatever an earlier one left half-done. `doc.go` explains the model in plain terms — no vocabulary section, every term is defined where it is used.

The path set keeps exactly one writer — this run. The build stages record what CI did on per-build records; the run folds those into the set and alone decides each path's status. Pending paths are re-dispatched every run until their build is seen running, dispatches partition by batch so heads proceed in parallel, and cancelling paths need no dispatch at all: the poll loop reads the stop off the set and enacts it.

Speculation lands inert. The wiring layer passes a placeholder Speculator that proposes nothing, so the run executes end to end but funds no paths; composing real per-queue speculators and turning the feature on is the wiring change at the top of this stack. Batch outcomes still come from the legacy per-batch finalizer, which waits on every dependency — strictly stricter than path-aware finalization, so the system stays correct until the next commit replaces it.

## Test Plan

✅ `bazel test //submitqueue/orchestrator/controller/speculate/...` — assumption checks and proposal filtering are table-driven; run tests cover funding a first path, re-dispatching pending paths, broken-path cancellation, build results recorded onto paths, lost CAS races skipped rather than failed, and Speculator errors abandoning the run.

✅ `make fmt`, `make gazelle`

# Conflicts:
#	service/submitqueue/orchestrator/server/BUILD.bazel
#	service/submitqueue/orchestrator/server/main.go
#	submitqueue/orchestrator/controller/speculate/BUILD.bazel
#	submitqueue/orchestrator/controller/speculate/speculate.go
#	submitqueue/orchestrator/controller/speculate/speculate_test.go

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# interactive rebase in progress; onto 452922a9
# Last command done (1 command done):
#    pick b9f222a # feat(orchestrator): re-plan the queue from the Speculator each run
# No commands remaining.
# You are currently rebasing branch 'preetam/speculation-run' on '452922a9'.
#
# Changes to be committed:
#	modified:   service/submitqueue/orchestrator/server/BUILD.bazel
#	modified:   service/submitqueue/orchestrator/server/main.go
#	modified:   submitqueue/orchestrator/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/speculate/BUILD.bazel
#	new file:   submitqueue/orchestrator/controller/speculate/check.go
#	new file:   submitqueue/orchestrator/controller/speculate/check_test.go
#	new file:   submitqueue/orchestrator/controller/speculate/dispatch.go
#	new file:   submitqueue/orchestrator/controller/speculate/doc.go
#	new file:   submitqueue/orchestrator/controller/speculate/run.go
#	new file:   submitqueue/orchestrator/controller/speculate/run_test.go
#	new file:   submitqueue/orchestrator/controller/speculate/snapshot.go
#	new file:   submitqueue/orchestrator/controller/speculate/snapshot_test.go
#	modified:   submitqueue/orchestrator/controller/speculate/speculate.go
#	modified:   submitqueue/orchestrator/controller/speculate/speculate_test.go
#	modified:   submitqueue/orchestrator/pipeline.go
#

# Conflicts:
#	service/submitqueue/orchestrator/server/main.go

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# interactive rebase in progress; onto fc33bc5
# Last command done (1 command done):
#    pick d549bd7 # feat(orchestrator): re-plan the queue from the Speculator each run
# No commands remaining.
# You are currently rebasing branch 'preetam/speculation-run' on 'fc33bc54'.
#
# Changes to be committed:
#	modified:   service/submitqueue/orchestrator/server/BUILD.bazel
#	modified:   service/submitqueue/orchestrator/server/main.go
#	modified:   submitqueue/orchestrator/BUILD.bazel
#	modified:   submitqueue/orchestrator/controller/speculate/BUILD.bazel
#	new file:   submitqueue/orchestrator/controller/speculate/check.go
#	new file:   submitqueue/orchestrator/controller/speculate/check_test.go
#	new file:   submitqueue/orchestrator/controller/speculate/dispatch.go
#	new file:   submitqueue/orchestrator/controller/speculate/doc.go
#	new file:   submitqueue/orchestrator/controller/speculate/run.go
#	new file:   submitqueue/orchestrator/controller/speculate/run_test.go
#	new file:   submitqueue/orchestrator/controller/speculate/snapshot.go
#	new file:   submitqueue/orchestrator/controller/speculate/snapshot_test.go
#	modified:   submitqueue/orchestrator/controller/speculate/speculate.go
#	modified:   submitqueue/orchestrator/controller/speculate/speculate_test.go
#	modified:   submitqueue/orchestrator/pipeline.go
#
@behinddwalls
behinddwalls force-pushed the preetam/speculation-run branch from d346213 to 643005d Compare August 7, 2026 20:37
@behinddwalls
behinddwalls merged commit 6be3afe into main Aug 7, 2026
13 of 15 checks passed
@behinddwalls
behinddwalls deleted the preetam/speculation-run branch August 7, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants