|
14 | 14 |
|
15 | 15 | package entity |
16 | 16 |
|
17 | | -// SpeculationPathAction defines the possible actions for a speculation path. |
| 17 | +// SpeculationPath is a single speculation path: an assumed-good prefix of |
| 18 | +// predecessor batches (Base) on top of which the batch under verification |
| 19 | +// (Head) is built and validated. |
| 20 | +// |
| 21 | +// This is the unit the build stage consumes: Base maps to the build runner's |
| 22 | +// base changes (an assumed-good prefix to apply) and Head maps to the changes |
| 23 | +// being validated. |
| 24 | +type SpeculationPath struct { |
| 25 | + // Base is the ordered list of predecessor batch IDs assumed to have passed. |
| 26 | + // Empty means the path builds the head batch directly on the target branch. |
| 27 | + Base []string |
| 28 | + // Head is the batch ID being verified by this path. |
| 29 | + Head string |
| 30 | +} |
| 31 | + |
| 32 | +// SpeculationPathStatus is the observed lifecycle state of a speculation path. |
| 33 | +// It is written only by the orchestrator's speculate controller (into the |
| 34 | +// speculation tree store) and read by the path selector as input; enumerators |
| 35 | +// and selectors never write it. |
| 36 | +type SpeculationPathStatus string |
| 37 | + |
| 38 | +const ( |
| 39 | + // SpeculationPathStatusUnknown is the unreachable zero value, set by default |
| 40 | + // on init. A persisted path always carries a real status (candidate onward), |
| 41 | + // so this should never be seen in the store. |
| 42 | + SpeculationPathStatusUnknown SpeculationPathStatus = "" |
| 43 | + // SpeculationPathStatusCandidate is a freshly enumerated path the controller |
| 44 | + // has persisted but not yet sent to build. |
| 45 | + SpeculationPathStatusCandidate SpeculationPathStatus = "candidate" |
| 46 | + // SpeculationPathStatusSelected is a path the controller has sent to the build |
| 47 | + // controller (in response to a selector Build action) but for which no build |
| 48 | + // signal has arrived yet — the build system may not have started it |
| 49 | + // (resource-gated), so whether it is actually building is not yet known. |
| 50 | + SpeculationPathStatusSelected SpeculationPathStatus = "selected" |
| 51 | + // SpeculationPathStatusBuilding is a path a build signal has confirmed is in |
| 52 | + // flight; its BuildID is known. |
| 53 | + SpeculationPathStatusBuilding SpeculationPathStatus = "building" |
| 54 | + // SpeculationPathStatusPassed is a path whose build succeeded. |
| 55 | + SpeculationPathStatusPassed SpeculationPathStatus = "passed" |
| 56 | + // SpeculationPathStatusFailed is a path whose build failed. |
| 57 | + SpeculationPathStatusFailed SpeculationPathStatus = "failed" |
| 58 | + // SpeculationPathStatusCancelled is a path that is no longer pursued — its |
| 59 | + // base was invalidated, its build was cancelled, or the selector dropped it. |
| 60 | + SpeculationPathStatusCancelled SpeculationPathStatus = "cancelled" |
| 61 | +) |
| 62 | + |
| 63 | +// SpeculationPathAction is the action a path selector asks the controller to |
| 64 | +// take for a path. It is the selector's only output: ephemeral (recomputed |
| 65 | +// every time the selector runs) and never persisted. The controller enacts it |
| 66 | +// and records the resulting SpeculationPathStatus. |
18 | 67 | type SpeculationPathAction string |
19 | 68 |
|
20 | 69 | const ( |
21 | | - // SpeculationPathActionUnknown is the default zero value for SpeculationPathAction. |
| 70 | + // SpeculationPathActionUnknown is the unreachable zero value. A real decision |
| 71 | + // always carries Build or Cancel; the selector expresses "leave this path |
| 72 | + // as-is" by omitting it from its decisions, not by returning this. |
22 | 73 | SpeculationPathActionUnknown SpeculationPathAction = "" |
23 | | - // TODO: Add comprehensive list of actions |
| 74 | + // SpeculationPathActionBuild asks the controller to send this path to the |
| 75 | + // build controller (which triggers a build subject to resources). The path moves |
| 76 | + // to Selected on send, then Building once a build signal confirms it. |
| 77 | + SpeculationPathActionBuild SpeculationPathAction = "build" |
| 78 | + // SpeculationPathActionCancel asks the controller to drop this path and |
| 79 | + // cancel any build in flight for it. |
| 80 | + SpeculationPathActionCancel SpeculationPathAction = "cancel" |
24 | 81 | ) |
25 | 82 |
|
26 | | -// SpeculationInfo represents metadata about a single speculation path, including the path through the dependency graph, its current state, and the predicted build score. |
27 | | -type SpeculationInfo struct { |
28 | | - // Path represents the speculation path; which is an ordered list of batches. |
29 | | - Path []string |
30 | | - // Action is a state that this path is in. |
31 | | - Action SpeculationPathAction |
32 | | - // Score is score for this speculation path. |
| 83 | +// SpeculationPathInfo is the per-path entry in a speculation tree: a path, the |
| 84 | +// enumerator's predicted score for it, its controller-owned status, and a link |
| 85 | +// to the build dispatched for it (if any). |
| 86 | +type SpeculationPathInfo struct { |
| 87 | + // Path is the Base/Head split this entry covers. |
| 88 | + Path SpeculationPath |
| 89 | + // Score is the enumerator's predicted success score for this path. |
33 | 90 | Score float32 |
| 91 | + // Status is the observed lifecycle state of the path. Written only by the |
| 92 | + // controller; read by the selector. |
| 93 | + Status SpeculationPathStatus |
| 94 | + // BuildID links this path to its build. Empty until a build signal confirms |
| 95 | + // the build and the controller records it (Selected -> Building); the |
| 96 | + // controller never knows the ID at send time. |
| 97 | + BuildID string |
| 98 | +} |
| 99 | + |
| 100 | +// SpeculationPathDecision is a path selector's decision for a single path: the |
| 101 | +// action the controller should take for it. It is the selector's output and is |
| 102 | +// not persisted. |
| 103 | +type SpeculationPathDecision struct { |
| 104 | + // Path identifies the speculation path the action applies to. |
| 105 | + Path SpeculationPath |
| 106 | + // Action is what the controller should do for the path. |
| 107 | + Action SpeculationPathAction |
34 | 108 | } |
35 | 109 |
|
36 | | -// SpeculationTree represents the set of speculation paths constructed for a batch based on its dependency graph. |
| 110 | +// SpeculationTree is the set of candidate speculation paths for a batch, built |
| 111 | +// from its dependency graph. |
37 | 112 | type SpeculationTree struct { |
38 | 113 | // BatchID is the batch for which this speculation tree is constructed. |
39 | 114 | BatchID string |
40 | | - // Speculations is a list of speculation paths for this batch based on a graph of its |
41 | | - // dependents. |
| 115 | + // Paths is the candidate speculation paths for this batch, derived from a |
| 116 | + // graph of its dependencies. |
42 | 117 | // |
43 | 118 | // For e.g - Consider batches - queueA/batch/1, queueA/batch/2, queueA/batch/3 |
44 | 119 | // such that - queueA/batch/2 and queueA/batch/3 depend on queueA/batch/1 |
45 | 120 | // |
46 | | - // Speculations for queueA/batch/1 - [{Path: []string{"queueA/batch/1"}, State: "scheduled", Score: 0.1}] |
47 | | - // Speculations for queueA/batch/2 - [{Path: []string{"queueA/batch/2"}, State: "scheduled", Score: 0.9}, {Path: []string{"queueA/batch/1", "queueA/batch/2"}, State: "scheduled", Score: 0.3}] |
48 | | - // Speculations for queueA/batch/3 - [{Path: []string{"queueA/batch/3"}, State: "scheduled", Score: 0.9}, {Path: []string{"queueA/batch/1", "queueA/batch/3"}, State: "scheduled", Score: 0.3}] |
| 121 | + // Paths for queueA/batch/2 - [{Path: {Base: [], Head: "queueA/batch/2"}, Score: 0.9, Status: "candidate"}, {Path: {Base: ["queueA/batch/1"], Head: "queueA/batch/2"}, Score: 0.3, Status: "candidate"}] |
| 122 | + // Paths for queueA/batch/3 - [{Path: {Base: [], Head: "queueA/batch/3"}, Score: 0.9, Status: "candidate"}, {Path: {Base: ["queueA/batch/1"], Head: "queueA/batch/3"}, Score: 0.3, Status: "candidate"}] |
49 | 123 | // |
50 | | - Speculations []SpeculationInfo |
| 124 | + Paths []SpeculationPathInfo |
51 | 125 | } |
0 commit comments