Repository navigation
feat(conflict): Add the Tango conflict analyzer #885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
manjari25
merged 5 commits into
manjari/tango-analyzer-request
from
manjari/tango-analyzer-core
Oct 20, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
197aa29
feat(conflict): Add the Tango conflict analyzer
manjari25 2c6fd8e
docs(conflict): Note that new dependency edges are not yet in signatures
manjari25 0fa8a4c
refactor(conflict): Drop the injected clock from the Tango analyzer
manjari25 a3c2a59
docs(conflict): Point the Tango overlap check at the new-edge TODO
manjari25 ce2e132
docs(conflict): Document the Tango analyzer's new-edge limit
manjari25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Tango conflict analyzer | ||
|
behinddwalls marked this conversation as resolved.
|
||
|
|
||
| A `conflict.Analyzer` that decides whether two batches conflict by comparing the build targets each one affects, as reported by a Tango build graph. Two batches conflict when their target sets share an ID, which catches a change that touches code another batch's targets depend on, even when the changed files differ. It reports `ConflictTypeTargetOverlap`. | ||
|
|
||
| ## Signatures | ||
|
|
||
| A batch's signature is the sorted set of its affected targets, each as a 64-bit ID (the first 8 bytes of the SHA-256 of the target label) with its distance from the nearest directly changed source. It is created once, when the batch is first analyzed, and never recomputed: asking Tango again later would use a newer base and could give a different answer. A signature is durable in the signature store, and a byte-bounded in-memory cache in front of it can be dropped at any time at the cost of store reads. | ||
|
|
||
| ## Behaviour | ||
|
|
||
| - Only the batch being analyzed is ever sent to Tango, and only when it has no recorded signature. Redelivery finds the record the earlier attempt created and does not call Tango again. | ||
| - The new batch is signed even when nothing is in flight, so later batches find its record. | ||
| - An in-flight batch is read from the cache, then the store, and never from Tango. A missing record or a store error fails the analysis (`ErrNoSignature` for the missing record), because a signature computed later could differ from the one the batch was admitted with. | ||
| - The analyzer fails closed on any error. | ||
| - A queue must have no in-flight batches when it is switched to this analyzer, because batches admitted earlier have no signature. | ||
|
|
||
| ## Limits | ||
|
|
||
| Each signature is computed against trunk at its own analysis time, without the other in-flight batches applied. If one batch adds a dependency on a target that another batch changes, no overlap is reported, the same kind of miss that path overlap has. Adding the destination of each new dependency edge to the signature would close it. | ||
|
|
||
| ## Injected pieces | ||
|
|
||
| The analyzer owns no connection. A deployment supplies the Tango client adapter, which collects the response and resolves each target's label, and a function that returns the commit SHA of the target branch tip a new batch is analyzed against. The changes of a batch come from the changeset resolver, the signature store is bound to one queue, and one signature cache can be shared by every queue's analyzer. The MySQL implementations of the signature and dictionary stores are in `mysql/`. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Copyright (c) 2026 Uber Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package tango | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/uber/submitqueue/submitqueue/core/changeset" | ||
| "github.com/uber/submitqueue/submitqueue/entity" | ||
| "github.com/uber/submitqueue/submitqueue/extension/conflict" | ||
| "github.com/uber/submitqueue/submitqueue/extension/storage" | ||
| ) | ||
|
|
||
| // ErrNoSignature means an in-flight batch has no recorded signature. Tango is | ||
| // never asked for it: a signature computed later could differ from the one the | ||
| // batch was admitted with. | ||
| var ErrNoSignature = errors.New("no target signature recorded for in-flight batch") | ||
|
|
||
| // Params are the dependencies of one queue's Analyzer. | ||
| type Params struct { | ||
| // Signatures persists signatures. It must be bound to the queue the | ||
| // analyzer serves. | ||
| Signatures SignatureStore | ||
|
|
||
| // Cache holds recently used signatures and may be shared across queues. | ||
| Cache *SignatureCache | ||
|
|
||
| // Client returns the targets a set of changes affects. | ||
| Client ChangedTargetsClient | ||
|
|
||
| // BaseRevision returns the full commit SHA of the target branch tip that a | ||
| // new batch of the named queue is analyzed against. | ||
| BaseRevision func(ctx context.Context, queue string) (string, error) | ||
|
behinddwalls marked this conversation as resolved.
|
||
|
|
||
| // Changes resolves a batch into the changes it contains. | ||
| Changes changeset.Resolver | ||
| } | ||
|
|
||
| type analyzer struct { | ||
| Params | ||
| } | ||
|
|
||
| // New returns a conflict.Analyzer that reports an in-flight batch as a | ||
| // ConflictTypeTargetOverlap conflict when its signature shares a target ID with | ||
| // the analyzed batch's. It fails closed: any signature it cannot obtain fails | ||
| // the analysis. | ||
| func New(params Params) conflict.Analyzer { | ||
| return &analyzer{Params: params} | ||
| } | ||
|
|
||
| // Analyze signs batch, which is the only step that can call Tango, and compares | ||
| // it with the recorded signature of each in-flight batch. The new batch is | ||
| // signed even when nothing is in flight, so later batches find its record. | ||
| func (a *analyzer) Analyze(ctx context.Context, batch entity.Batch, inFlight []entity.Batch) ([]entity.Conflict, error) { | ||
| mine, err := a.signNewBatch(ctx, batch) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to sign batch %s: %w", batch.ID, err) | ||
| } | ||
|
|
||
| // TODO(tango): read the in-flight signatures concurrently with a bound. | ||
| // New dependency edges are not in the signatures yet; see the TODO in signNewBatch. | ||
| var conflicts []entity.Conflict | ||
| for _, other := range inFlight { | ||
| theirs, found, err := a.recordedSignature(ctx, other.Queue, other.ID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read the signature of in-flight batch %s: %w", other.ID, err) | ||
| } | ||
| if !found { | ||
| return nil, fmt.Errorf("in-flight batch %s: %w", other.ID, ErrNoSignature) | ||
| } | ||
| if sharesTarget(mine.Targets, theirs.Targets) { | ||
| conflicts = append(conflicts, entity.Conflict{BatchID: other.ID, Type: entity.ConflictTypeTargetOverlap}) | ||
|
behinddwalls marked this conversation as resolved.
|
||
| } | ||
| } | ||
| return conflicts, nil | ||
| } | ||
|
|
||
| func (a *analyzer) recordedSignature(ctx context.Context, queue, batchID string) (TargetSignature, bool, error) { | ||
| if signature, found := a.Cache.get(queue, batchID); found { | ||
| return signature, true, nil | ||
| } | ||
| signature, found, err := a.Signatures.Get(ctx, batchID) | ||
| if err != nil || !found { | ||
| return TargetSignature{}, false, err | ||
|
behinddwalls marked this conversation as resolved.
|
||
| } | ||
| a.Cache.put(signature) | ||
| return signature, true, nil | ||
| } | ||
|
|
||
| // signNewBatch returns the batch's own record if an earlier attempt created | ||
| // one; otherwise it creates the signature first, so racing attempts agree. | ||
| func (a *analyzer) signNewBatch(ctx context.Context, batch entity.Batch) (TargetSignature, error) { | ||
| signature, found, err := a.recordedSignature(ctx, batch.Queue, batch.ID) | ||
| if err != nil || found { | ||
| return signature, err | ||
| } | ||
|
|
||
| changes, err := a.Changes.ChangesForBatch(ctx, batch) | ||
| if err != nil { | ||
| return TargetSignature{}, fmt.Errorf("failed to resolve the changes: %w", err) | ||
| } | ||
| baseRevision, err := a.BaseRevision(ctx, batch.Queue) | ||
| if err != nil { | ||
| return TargetSignature{}, fmt.Errorf("failed to resolve the base revision of queue %s: %w", batch.Queue, err) | ||
| } | ||
| affected, err := a.Client.ChangedTargets(ctx, changedTargetsRequestFor(baseRevision, changes)) | ||
| if err != nil { | ||
| return TargetSignature{}, fmt.Errorf("failed to get the changed targets: %w", err) | ||
| } | ||
|
|
||
| // TODO(tango): record the labels in the target dictionary before creating the signature. | ||
| // TODO(tango): add the destination of each new dependency edge to the signature, the RFC's known gap. The adapter must return direct dependencies first. | ||
| targets, _ := toSignatureTargets(affected) | ||
| signature = TargetSignature{ | ||
| Queue: batch.Queue, | ||
| BatchID: batch.ID, | ||
| BaseRevision: baseRevision, | ||
| Targets: targets, | ||
| CreatedAt: time.Now().UnixMilli(), | ||
| } | ||
|
|
||
| if err := a.Signatures.Create(ctx, signature); err != nil { | ||
| if !errors.Is(err, storage.ErrAlreadyExists) { | ||
| return TargetSignature{}, fmt.Errorf("failed to create the signature: %w", err) | ||
| } | ||
| signature, found, err = a.Signatures.Get(ctx, batch.ID) | ||
| if err != nil { | ||
| return TargetSignature{}, fmt.Errorf("failed to read the existing signature: %w", err) | ||
| } | ||
| if !found { | ||
| return TargetSignature{}, fmt.Errorf("signature reported as existing but not found") | ||
| } | ||
| } | ||
| a.Cache.put(signature) | ||
| return signature, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.