← Back to Pull requests

[Test][History Server] Fix Build historyserver flaky unit test: TestShutdown_DrainsRetriedTasks #5245

Closed
unknown closed this pull request without merging on Sep 15, 2026 15:02 UTC
View on GitHub
unknown unknown commented on Sep 05, 2026 06:35 UTC
Author

<!-- Thank you for your contribution! -->

<!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. -->

Why are these changes needed?

After checking the log, I found that TestShutdown_DrainsRetriedTasks was flaky in the Build historyserver job. Before the fix, the test waited on !writer.failPending() before calling shutdown(). That flag becomes false inside the failed WriteFile, before retryProcess registers the backoff goroutine on consumerWG. If shutdown() closes stopProducers in that window, retryProcess logs Giving up on retrying ... during shutdown and never uploaded.
So I suggested driving the first failed attempt synchronously via processRotatedFile, ensuring the retry is registered with consumerWG before shutdown() is called. The test then starts the upload worker and runs the real shutdown path: closing stopProducers cuts the backoff short, and consumerWG waits for the final attempt. there is no longer a window where shutdown() can race with retry registration.

Related issue number


Closes #5243
<!-- For example: "Closes #1234" -->

Labels

<!-- Please add the appropriate labels to this PR. -->

  • If this PR has user-facing changes that require documentation updates at release time, I have added the doc-updates-required label.

  • If this PR contains breaking changes, I have added the breaking-change label.
  • Checks

  • [X] I've made sure the tests are passing.

  • Testing Strategy

  • - [ ] Unit tests
    - [X] Manual tests
    - [ ] This PR is not tested :(

    <!-- If you selected "Manual tests" above, please fill in the section below. Otherwise you can remove it. -->

    Manual test instructions

    I reproduced the CI failure locally by inserting a 50ms sleep between the failed WriteFile and retryProcess in historyserver/pkg/collector/eventcollector/eventcollector.go, which widens the same race. From historyserver/, I ran:
    go test -race -count=20 ./pkg/collector/eventcollector/ -run TestShutdown_DrainsRetriedTasks -v
    The original test then failed consistently (20/20 runs) with Giving up on retrying ... during shutdown and retried task never uploaded, matching the CI failure log.
    After the fix, the same command with the same sleep passed consistently (20/20 runs) because the retry is already registered before shutdown().

    Diff: 309 lines (+231 / -78) across 3 files Reviewer: machichima Review duration: 14907m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 309 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.343
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5245"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.9% · Safe to merge
    15.9%