From f1176495103ccf01365ef7a789e5599ba8a23fed Mon Sep 17 00:00:00 2001 From: manjari Date: Tue, 24 Feb 2026 00:42:46 +0000 Subject: [PATCH 1/6] feat(entities) Adds speculation tree entity and sql schema --- entity/speculation_tree.go | 12 ++++++++++++ extension/storage/mysql/schema/speculation_tree.sql | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 entity/speculation_tree.go create mode 100644 extension/storage/mysql/schema/speculation_tree.sql diff --git a/entity/speculation_tree.go b/entity/speculation_tree.go new file mode 100644 index 00000000..02aa5007 --- /dev/null +++ b/entity/speculation_tree.go @@ -0,0 +1,12 @@ +package entity + +// SpeculationTree represents the set of speculation paths constructed for a batch based on its dependency graph. +type SpeculationTree struct { + // BatchID is the batch for which this speculation tree is constructed. + BatchID string + // Queue is the name of the queue processing the land request. Queue name is defined in the configuration and should be unique within the system. + Queue string + // Speculations is a list of speculation paths for this batch based on a graph of its + // dependents. + Speculations []map[string]string +} diff --git a/extension/storage/mysql/schema/speculation_tree.sql b/extension/storage/mysql/schema/speculation_tree.sql new file mode 100644 index 00000000..c03d2449 --- /dev/null +++ b/extension/storage/mysql/schema/speculation_tree.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS speculation_tree ( + batch_id VARCHAR(255) NOT NULL, + queue VARCHAR(255) NOT NULL, + speculations JSON NOT NULL, + PRIMARY KEY (batch_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; From 91fd64e311f73f354793392ecf43fc108a197e31 Mon Sep 17 00:00:00 2001 From: manjari Date: Tue, 24 Feb 2026 02:50:22 +0000 Subject: [PATCH 2/6] gazelle --- entity/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/entity/BUILD.bazel b/entity/BUILD.bazel index 0a562dbb..0bb84766 100644 --- a/entity/BUILD.bazel +++ b/entity/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "build.go", "change_provider.go", "request.go", + "speculation_tree.go", ], importpath = "github.com/uber/submitqueue/entity", visibility = ["//visibility:public"], From 9151ee0dd3bc7b97fd0fbfc91c7c1fcb82ae9fc1 Mon Sep 17 00:00:00 2001 From: manjari Date: Tue, 24 Feb 2026 17:30:07 +0000 Subject: [PATCH 3/6] add example for speculations --- entity/speculation_tree.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/entity/speculation_tree.go b/entity/speculation_tree.go index 02aa5007..5b0c7e16 100644 --- a/entity/speculation_tree.go +++ b/entity/speculation_tree.go @@ -8,5 +8,15 @@ type SpeculationTree struct { Queue string // Speculations is a list of speculation paths for this batch based on a graph of its // dependents. + // + // For e.g - Consider batches - queueA/batch/1, queueA/batch/2, queueA/batch/3 + // such that - queueA/batch/2 and queueA/batch/3 depend on queueA/batch/1 + // + // Speculations for queueA/batch/1 - [{"path": "queueA/batch/1", "state": "scheduled", "score": 0.1}] + // Speculations for queueA/batch/2 - [{"path": "queueA/batch/2", "state": "scheduled", "score": 0.9}, {"path": "queueA/batch/1//queueA/batch/2", "state": "scheduled", "score": 0.3}] + // Speculations for queueA/batch/3 - [{"path": "queueA/batch/3", "state": "scheduled", "score": 0.9}, {"path": "queueA/batch/1//queueA/batch/3", "state": "scheduled", "score": 0.3}] + // + // Note that the key value pairs within the map could have additional information about the speculation path if needed. + // Speculations []map[string]string } From e88964a8755d2b3b63b27d90a0764ab6a1f0ad91 Mon Sep 17 00:00:00 2001 From: manjari Date: Tue, 24 Feb 2026 19:49:05 +0000 Subject: [PATCH 4/6] remove queue from entity and make speculaitons an explicit type --- entity/speculation_tree.go | 19 +++++++++++-------- .../storage/mysql/schema/speculation_tree.sql | 1 - 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/entity/speculation_tree.go b/entity/speculation_tree.go index 5b0c7e16..33d7df4c 100644 --- a/entity/speculation_tree.go +++ b/entity/speculation_tree.go @@ -1,22 +1,25 @@ package entity +// SpeculationInfo represents metadata about a single speculation path, including the path through the dependency graph, its current state, and the predicted build score. +type SpeculationInfo struct { + Path string + State string + Score float32 +} + // SpeculationTree represents the set of speculation paths constructed for a batch based on its dependency graph. type SpeculationTree struct { // BatchID is the batch for which this speculation tree is constructed. BatchID string - // Queue is the name of the queue processing the land request. Queue name is defined in the configuration and should be unique within the system. - Queue string // Speculations is a list of speculation paths for this batch based on a graph of its // dependents. // // For e.g - Consider batches - queueA/batch/1, queueA/batch/2, queueA/batch/3 // such that - queueA/batch/2 and queueA/batch/3 depend on queueA/batch/1 // - // Speculations for queueA/batch/1 - [{"path": "queueA/batch/1", "state": "scheduled", "score": 0.1}] - // Speculations for queueA/batch/2 - [{"path": "queueA/batch/2", "state": "scheduled", "score": 0.9}, {"path": "queueA/batch/1//queueA/batch/2", "state": "scheduled", "score": 0.3}] - // Speculations for queueA/batch/3 - [{"path": "queueA/batch/3", "state": "scheduled", "score": 0.9}, {"path": "queueA/batch/1//queueA/batch/3", "state": "scheduled", "score": 0.3}] - // - // Note that the key value pairs within the map could have additional information about the speculation path if needed. + // Speculations for queueA/batch/1 - [{Path: "queueA/batch/1", State: "scheduled", Score: 0.1}] + // Speculations for queueA/batch/2 - [{Path: "queueA/batch/2", State: "scheduled", Score: 0.9}, {Path: "queueA/batch/1//queueA/batch/2", State: "scheduled", Score: 0.3}] + // Speculations for queueA/batch/3 - [{Path: "queueA/batch/3", State: "scheduled", Score: 0.9}, {Path: "queueA/batch/1//queueA/batch/3", State: "scheduled", Score: 0.3}] // - Speculations []map[string]string + Speculations []SpeculationInfo } diff --git a/extension/storage/mysql/schema/speculation_tree.sql b/extension/storage/mysql/schema/speculation_tree.sql index c03d2449..5b1d3a19 100644 --- a/extension/storage/mysql/schema/speculation_tree.sql +++ b/extension/storage/mysql/schema/speculation_tree.sql @@ -1,6 +1,5 @@ CREATE TABLE IF NOT EXISTS speculation_tree ( batch_id VARCHAR(255) NOT NULL, - queue VARCHAR(255) NOT NULL, speculations JSON NOT NULL, PRIMARY KEY (batch_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; From ccd3c35a4f2d555b8812a7f09533d38019a63a3b Mon Sep 17 00:00:00 2001 From: manjari Date: Tue, 24 Feb 2026 19:58:55 +0000 Subject: [PATCH 5/6] update state to action --- entity/speculation_tree.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/entity/speculation_tree.go b/entity/speculation_tree.go index 33d7df4c..995060a3 100644 --- a/entity/speculation_tree.go +++ b/entity/speculation_tree.go @@ -1,9 +1,21 @@ package entity +// SpeculationPathAction defines the possible actions for a speculation path. +type SpeculationPathAction string + +const ( + // SpeculationPathActionUnknown is the default zero value for SpeculationPathAction. + SpeculationPathActionUnknown SpeculationPathAction = "" + // TODO: Add comprehensive list of actions +) + // SpeculationInfo represents metadata about a single speculation path, including the path through the dependency graph, its current state, and the predicted build score. type SpeculationInfo struct { + // Path represents the speculation path. Path string - State string + // Action is a state that this path is in. + Action SpeculationPathAction + // Score is score for this speculation path. Score float32 } From 2e21de67b695c9801aff42547f9588b038842359 Mon Sep 17 00:00:00 2001 From: manjari Date: Tue, 24 Feb 2026 21:00:03 +0000 Subject: [PATCH 6/6] address comments --- entity/speculation_tree.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entity/speculation_tree.go b/entity/speculation_tree.go index 995060a3..f90a36f9 100644 --- a/entity/speculation_tree.go +++ b/entity/speculation_tree.go @@ -11,8 +11,8 @@ const ( // SpeculationInfo represents metadata about a single speculation path, including the path through the dependency graph, its current state, and the predicted build score. type SpeculationInfo struct { - // Path represents the speculation path. - Path string + // Path represents the speculation path; which is an ordered list of batches. + Path []string // Action is a state that this path is in. Action SpeculationPathAction // Score is score for this speculation path. @@ -29,9 +29,9 @@ type SpeculationTree struct { // For e.g - Consider batches - queueA/batch/1, queueA/batch/2, queueA/batch/3 // such that - queueA/batch/2 and queueA/batch/3 depend on queueA/batch/1 // - // Speculations for queueA/batch/1 - [{Path: "queueA/batch/1", State: "scheduled", Score: 0.1}] - // Speculations for queueA/batch/2 - [{Path: "queueA/batch/2", State: "scheduled", Score: 0.9}, {Path: "queueA/batch/1//queueA/batch/2", State: "scheduled", Score: 0.3}] - // Speculations for queueA/batch/3 - [{Path: "queueA/batch/3", State: "scheduled", Score: 0.9}, {Path: "queueA/batch/1//queueA/batch/3", State: "scheduled", Score: 0.3}] + // Speculations for queueA/batch/1 - [{Path: []string{"queueA/batch/1"}, State: "scheduled", Score: 0.1}] + // 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}] + // 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}] // Speculations []SpeculationInfo }