fix(bazel): identify bazel query context timeouts via sentinel error - #246
Open
yushan8 wants to merge 6 commits into
Open
fix(bazel): identify bazel query context timeouts via sentinel error#246yushan8 wants to merge 6 commits into
yushan8 wants to merge 6 commits into
Conversation
Intent: - A bazel query killed for exceeding its configured timeout was previously wrapped as a plain error, falling through to the ErrorInfra default in tangoerrors.GetErrorCode. A query timeout can be transient (a loaded machine, a cold repo cache) and is worth retrying, unlike a genuine query/config failure. Changes: - Add bazel.ErrQueryTimeout, wrapped in executeQueryInternal when cmd.Wait() fails and the query's own context (not a parent cancellation) has hit its deadline. - Add orchestrator.classifyComputeError, classifying ErrQueryTimeout as tangoerrors.ErrorInfraRetryable and everything else as tangoerrors.ErrorInfra; wired into nativeOrchestrator's compute step. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
waitErr and streamErr are two independent consumers of cmdCtx: if the bazel process exits cleanly right at the deadline, waitErr can be nil while the stream-reading goroutines are still canceled mid-read via gCtx, surfacing as streamErr instead. That path wasn't wrapped with ErrQueryTimeout, so it fell through to the non-retryable default even though it's the same timeout condition. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
yushan8
marked this pull request as draft
July 28, 2026 18:37
bazel.ErrQueryTimeout exists to let callers distinguish a service-side query timeout (ctx.Err() == DeadlineExceeded on the query's own timeout) from a client-initiated cancellation via errors.Is, not to drive automatic retries. Drop classifyComputeError and go back to plain error wrapping in GetTargetGraph; the sentinel is still reachable through the %w chain from core/bazel/query.go. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Update the doc comment left over from when this sentinel drove retryable classification; it now exists purely so callers can tell a service-side query timeout apart from a client cancellation via errors.Is. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
yushan8
marked this pull request as ready for review
July 28, 2026 22:52
Both call sites needed the same two-line "if timedOut { wrap with
ErrQueryTimeout }" before calling wrapQueryFailure. Pass timedOut
through instead so the wrapping happens once, in one place.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Let wrapQueryFailure check ctx.Err() == context.DeadlineExceeded itself rather than having the caller precompute a timedOut bool and thread it through. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
| // live, so it's omitted. | ||
| func (b *BazelClient) wrapQueryFailure(msg string, cause error, stderrBuf *bytes.Buffer) error { | ||
| func (b *BazelClient) wrapQueryFailure(ctx context.Context, msg string, cause error, stderrBuf *bytes.Buffer) error { | ||
| if ctx.Err() == context.DeadlineExceeded { |
Contributor
There was a problem hiding this comment.
we should do this check, but a sentinel seems overkill since we're not handling it anywhere. A plain fmt.Errorf achieves the same result. Unless we plan to do something with it right now, I'd prefer just making it a plain error until we specifically want to handle this.
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
Intent:
wrapped as a plain error with no way to distinguish it from any other
compute failure. Services consuming Tango need to be able to tell a
service-side query timeout (the query's own context, not a parent
cancellation, hit its deadline) apart from a client disconnecting, so
they can handle/log it distinctly.
Changes:
query's own context (not a parent cancellation) has hit its deadline —
whether that surfaces via cmd.Wait() failing or via the stream-reading
goroutines being canceled mid-read.
through the %w chain, but GetTargetGraph does not classify it as
retryable — it falls through to the default ErrorInfra like any other
compute failure.
Follow-up to #236, which classified bazelisk download network failures as
retryable (a different case: that one is a genuine transient failure
before any query even starts).
Test Plan
now wraps bazel.ErrQueryTimeout.
plain wait failure (no context deadline) is not misclassified as a
timeout.
a timeout surfacing only via the stream-reading goroutines is still
wrapped with ErrQueryTimeout.
Revert Plan
Revert this PR; the sentinel and its detection are removed, with no
change to runtime classification behavior.