← Back to Pull requests

fix(diagnostics): cap section budget and wait by the remaining total timeout #8030

Merged
imDwAaY merged 3 files (92 lines) on Oct 26, 2026 05:57 UTC
View on GitHub
imDwAaY imDwAaY commented on Oct 23, 2026 06:19 UTC
Author

Fixes #8022.

Problem

DiagnosticBundleService.collect() computes a total deadline, but runCollector then hands each collector the full sectionTimeoutMs and waits for its result with the same full timeout. A section that starts just before the total deadline can therefore extend collection by another complete section timeout, so the advertised totalTimeoutMs is not enforced.

Fix

  • The per-collector budget is now min(sectionTimeoutMs, remaining total time), and the Future.get wait uses that same capped value.

  • A positive sub-millisecond remainder rounds up to 1 ms. Rounding down returns control slightly before the total deadline and misreports a section capped by the total budget as a plain section timeout.

  • TimeoutException now distinguishes total budget exhausted from section timeout, so consumers can tell which bound actually stopped collection. Sections that are never attempted are still reported as SKIPPED with total budget exhausted, and an active section is cancelled when the total deadline passes.

  • DiagnosticProperties.getTotalTimeoutMs() documents what the bound covers: it bounds starting and waiting for collectors, not manifest identity lookup or archive assembly.
  • Tests

    Added to DiagnosticBundleServiceTest:

  • totalBudgetCapsSectionWait — totalTimeoutMs=50, sectionTimeoutMs=5000, blocking collector: the section fails with total budget exhausted and collection returns in well under the full section timeout.

  • laterCollectorCannotRestartFullSectionAllowance — after the first section exhausts the total budget, the next collector is SKIPPED instead of receiving a fresh section allowance.
  • Local verification:

    ./mvnw -pl shenyu-web -am test -Dtest='Diagnostic*'   # 19 tests, 0 failures
    ./mvnw -pl shenyu-web checkstyle:check                # pass
    

    Note: the full shenyu-web suite has pre-existing Mockito inline-mock errors under JDK 25 on this machine; the diagnostics package has no Mockito dependency and passes.

    Diff: 92 lines (+84 / -8) across 3 files Reviewer: Aias00 Review duration: 4297m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.33) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.33 · 92 lines diff across 3 files
    0.33
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.80 · 2 substantive comment(s)
    0.80
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    81%
    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.271
    Real PR Conversation Timeline
    5 items
    Aias00 Aias00 commented on Oct 23, 2026 14:21 UTC
    Reviewer

    The rounding is what makes this correct, and it is the part most likely to be broken later, so the inline comment earns its place: budgetMs is rounded up against budgetNanos, which guarantees future.get(budgetMs) cannot return before the total deadline. That is exactly why timeoutReason can trust "deadline already passed" to mean "the total budget capped this section" instead of mislabelling it a plain section timeout.

    Consistent with the rest of the change:

  • DiagnosticBudget now receives the capped value, so the collector's own internal accounting stops at the same point the wait does — otherwise a section could report success after the wait had already given up.

  • Math.max(1L, budgetMs) keeps a positive sub-millisecond remainder usable instead of collapsing to 0, which would have meant an unbounded get(0, ...).
  • One small doc gap: with this change sectionTimeoutMs = 0 yields a 1 ms section budget rather than "no per-section limit". That is not a regression — get(0, MILLISECONDS) already timed out immediately before — but setSectionTimeoutMs is a natural place to say so, since the value now flows into two places (the budget and the wait) instead of one.

    Approving.

    Aias00 Aias00 commented on Oct 24, 2026 07:49 UTC
    Contributor

    @imDwAaY This PR is approved, but 7 checks are red: build (shenyu-integrated-test-http), build (shenyu-integrated-test-rewrite), build (shenyu-integrated-test-tracing), build (shenyu-integrated-test-https) (+3 more).

    I inspected these lanes today and they fail for infrastructure reasons rather than on the diff — the integrated-test jobs die while starting their containers (Elasticsearch /_cat/health returning 000 until the job is cancelled), and the http lane also hits the known CachePluginTest.testMemoryModle / testRedisModle flake. The same jobs are red on master and on unrelated PRs right now.

    Please rebase onto master and push (or ask for a re-run) so the checks execute again. If a case is still failing on a fresh run, paste the test name and I'll look properly.

    imDwAaY imDwAaY commented on Oct 24, 2026 10:52 UTC
    Author

    Rebased onto master (b7cea28e0) and force-pushed; the branch is now a single commit d05c93f45.

    Also addressed the doc gap you pointed out: setSectionTimeoutMs now documents that the value bounds both the collector budget and the wait for its result, and that values below one millisecond (including zero) still allow a one millisecond attempt rather than meaning "no per-section limit".

    Local verification after the rebase:

    ./mvnw -pl shenyu-web -am test -Dtest='Diagnostic*'   # 19 tests, 0 failures (JDK 17)
    ./mvnw -pl shenyu-web checkstyle:check                # pass
    

    Thanks for checking the integrated-test lanes — I'll keep an eye on this run and report back if anything fails on the new checks rather than on the known infrastructure/CachePluginTest flakes.

    Aias00 Aias00 approved these changes on Oct 26, 2026 05:26 UTC
    Approved Reviewer

    Approved. Capping each diagnostic section's wait to the remaining total deadline via sectionBudgetMs(deadlineNanos) prevents one slow section from over-running the overall timeout, and the rounding/boundary handling is sound. Tests cover the budget math. (The remaining 'shenyu-integrated-test-rewrite' failure is the known-flaky rewrite job, unrelated to this change.)

    Reviewers
    Assignees
    imDwAaY imDwAaY
    Labels
    risk: low confidence: 81.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: 33% (LOW) · Higher = larger blast radius
    33%
    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: 81.5% · Lower = rushed or shallow review
    81.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: 6.1% · Safe to merge
    6.1%
    Repository