feat(storage): speculation path set store - #501
Open
behinddwalls wants to merge 1 commit into
Open
Conversation
behinddwalls
marked this pull request as ready for review
August 3, 2026 16:46
## Summary ### Why? The speculation RFC has the speculate controller read every materialized path set at the start of a run and persist the paths it funds at the end. `entity.SpeculationPathSet` has existed since the path entities landed, but nothing can store one: there is no interface, no schema, no implementation. This is the first of the pieces the controller integration needs, and it is useful to review on its own because the contract shape is the part worth arguing about. ### What? Adds `storage.SpeculationPathSetStore`, keyed on the head batch ID, with a MySQL implementation, schema, mocks, and contract tests. The mutation is a conditional whole-item put — `Update` takes the entity and replaces it, guarded on version — rather than the field-level `UpdateState`/`UpdateDependents` shape the other stores use. A set is replaced wholesale, so the entity is the unit of replacement, and a conditional put on a key is the primitive every backend offers directly: DynamoDB `PutItem` with a `ConditionExpression`, a conditional row write in Bigtable. A field-level update would be the one shape each non-SQL backend has to emulate with a read-modify-write. Version arguments come last, and the entity's own `Version` field is ignored — `oldVersion` guards and `newVersion` is written, so version arithmetic stays with the caller per the storage README. The table has no secondary index. Callers that want a queue's live sets enumerate the heads from the batch listing they already hold and read each set by key, which is the "domain state is already the index" branch of the storage README's decision path. One version per set is deliberate. Speculate, build, and buildsignal all mutate the same row, so each does read, modify, compare-and-swap, and a loser gets the retryable `ErrVersionMismatch` and re-reads on redelivery. ## Test Plan ✅ `bazel test //submitqueue/extension/storage/...` — sqlmock unit tests covering get/create/update, `ErrNotFound`, `ErrAlreadyExists`, `ErrVersionMismatch`, malformed stored JSON, and a test pinning that `Update` ignores the entity's `Version` field in favour of the explicit arguments. ✅ `bazel test //test/integration/submitqueue/extension/storage/mysql:go_default_test` — four new cases in the shared storage contract suite, run against real MySQL and confirmed executing under `-test.v`: round-trip (asserting each stored ID still equals the hash of its stored path, so an encoding that dropped or reordered assumptions would fail), missing head, duplicate create, and a compare-and-swap race where the loser must not restore the path the winner dropped. ✅ `make fmt`, `make gazelle`, `make mocks`
behinddwalls
force-pushed
the
preetam/speculation-path-store
branch
from
August 3, 2026 23:03
46e9005 to
c56ac02
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why?
The speculation RFC has the speculate controller read every materialized path set at the start of a run and persist the paths it funds at the end.
entity.SpeculationPathSethas existed since the path entities landed, but nothing can store one: there is no interface, no schema, no implementation. This is the first of the pieces the controller integration needs, and it is useful to review on its own because the contract shape is the part worth arguing about.What?
Adds
storage.SpeculationPathSetStore, keyed on the head batch ID, with a MySQL implementation, schema, mocks, and contract tests.The mutation is a conditional whole-item put —
Updatetakes the entity and replaces it, guarded on version — rather than the field-levelUpdateState/UpdateDependentsshape the other stores use. A set is replaced wholesale, so the entity is the unit of replacement, and a conditional put on a key is the primitive every backend offers directly: DynamoDBPutItemwith aConditionExpression, a conditional row write in Bigtable. A field-level update would be the one shape each non-SQL backend has to emulate with a read-modify-write. Version arguments come last, and the entity's ownVersionfield is ignored —oldVersionguards andnewVersionis written, so version arithmetic stays with the caller per the storage README.The table has no secondary index. Callers that want a queue's live sets enumerate the heads from the batch listing they already hold and read each set by key, which is the "domain state is already the index" branch of the storage README's decision path.
One version per set is deliberate. Speculate, build, and buildsignal all mutate the same row, so each does read, modify, compare-and-swap, and a loser gets the retryable
ErrVersionMismatchand re-reads on redelivery.Test Plan
✅
bazel test //submitqueue/extension/storage/...— sqlmock unit tests covering get/create/update,ErrNotFound,ErrAlreadyExists,ErrVersionMismatch, malformed stored JSON, and a test pinning thatUpdateignores the entity'sVersionfield in favour of the explicit arguments.✅
bazel test //test/integration/submitqueue/extension/storage/mysql:go_default_test— four new cases in the shared storage contract suite, run against real MySQL and confirmed executing under-test.v: round-trip (asserting each stored ID still equals the hash of its stored path, so an encoding that dropped or reordered assumptions would fail), missing head, duplicate create, and a compare-and-swap race where the loser must not restore the path the winner dropped.✅
make fmt,make gazelle,make mocksIssues