Skip to content

feat(speculation): allocator contract and sticky impl - #450

Open
behinddwalls wants to merge 1 commit into
preetam/speculation-generatorfrom
preetam/speculation-allocator
Open

feat(speculation): allocator contract and sticky impl#450
behinddwalls wants to merge 1 commit into
preetam/speculation-generatorfrom
preetam/speculation-allocator

Conversation

@behinddwalls

@behinddwalls behinddwalls commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Add submitqueue/extension/speculation/allocator, the budget-spending composition point (Allocator) the standard Speculator hands its candidate stream to, plus the sticky implementation and mocks.

The Allocator owns terminal-path suppression: the generator enumerates the whole path space with no knowledge of the path sets, so paths whose builds already ran come back round as candidates. Allocate reconciles the stream against the path sets by path ID — an in-flight candidate stays funded rather than starting a new attempt, and a terminal one is skipped without spending a slot.

sticky fills only free budget slots and never preempts a running build, trading responsiveness for never discarding work already started; its policy counterpart is a preempting allocator. Tests cover a terminal path arriving as the top-ranked candidate for each terminal status (passed, failed, cancelled): it is skipped and the slot goes to the next eligible candidate.

Stack

  1. feat(entity): speculation path and run entities #444
  2. feat(speculation): speculator extension contract #445
  3. feat(speculation): generator contract and bestfirst impl #446
  4. @ feat(speculation): allocator contract and sticky impl #450
  5. feat(speculation): standard composed speculator #451

@sbalabanov sbalabanov 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.

critical comment about failing fast


Because cancellation is best-effort, an `Allocator` should not spend capacity it merely expects a cancel to release — a build cancelled to make room keeps charging the budget until its cancel reaches a terminal state, so the queue converges over successive runs rather than oversubscribing the hard cap on concurrent builds in a single pass.

## `sticky`

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.

move that into sticky/README.md instead


## `sticky`

The `sticky` `Allocator` fills only free budget slots and leaves every in-flight build running. Against the budget it counts the paths that still hold a build slot — `pending`, `building`, and `cancelling` (a cancel is a request, and the build keeps its slot until it actually stops). It then proposes a build for each new candidate, in order, until the budget fills; it never proposes a cancel.

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.

add that 'sticky' operates the "builds" as a build unit budget (so, it is quite coarse).
More interesting implementations may operate with more granular units, understanding the size of the build needed to be done (i.e. based on number of targets, historical data etc).

}

// New returns a sticky allocator.Allocator with the given concurrent-build
// budget.

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.

explain what unit of measure for the budget is

// data defect. Skip it rather than counting it: a status that
// never turns terminal would pin a build slot forever. That leaves
// the path free to be proposed again, which is self-correcting,
// but the malformed entry is worth knowing about.

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.

SQ default on data inconsistencies is to fail fast and hard

@behinddwalls
behinddwalls force-pushed the preetam/speculation-allocator branch 2 times, most recently from bf09ae6 to 6977b91 Compare July 29, 2026 18:24
@behinddwalls
behinddwalls force-pushed the preetam/speculation-allocator branch 2 times, most recently from d6f1dfe to af1efe4 Compare July 29, 2026 22:41
@behinddwalls
behinddwalls force-pushed the preetam/speculation-allocator branch 2 times, most recently from 2b3a122 to 32e21b9 Compare July 29, 2026 23:18
@behinddwalls
behinddwalls force-pushed the preetam/speculation-allocator branch from 32e21b9 to 00ca258 Compare July 29, 2026 23:18
Add submitqueue/extension/speculation/allocator, the budget-spending composition point (Allocator) the standard Speculator hands its candidate stream to, plus the sticky implementation and mocks.

The Allocator owns terminal-path suppression: the generator enumerates the whole path space with no knowledge of the path sets, so paths whose builds already ran come back round as candidates. Allocate reconciles the stream against the path sets by path ID — an in-flight candidate stays funded rather than starting a new attempt, and a terminal one is skipped without spending a slot.

The budget is measured in concurrent builds: one slot per path whose attempt is pending, building, or cancelling, whatever that build's size. That unit is deliberately coarse — an allocator that understands build size (target count, historical cost) could weight paths instead; the contract leaves the unit to the implementation.

sticky fills only free budget slots and never preempts a running build, trading responsiveness for never discarding work already started; its policy counterpart is a preempting allocator. A stored path with no status is corrupt data and sticky fails fast — Allocate returns an error rather than guessing whether the record holds a slot — which also removes its only logging dependency, so New takes just the budget.

Tests cover a terminal path arriving as the top-ranked candidate for each terminal status (passed, failed, cancelled): it is skipped and the slot goes to the next eligible candidate. Contract docs live in allocator/README.md; sticky's behavior is documented next to the code in sticky/README.md.
@behinddwalls
behinddwalls force-pushed the preetam/speculation-allocator branch from 00ca258 to 80c246f Compare July 30, 2026 01:19
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