Skip to content

test(provider): wait for warmup retirement before the idle check in the shape warmup retry test - #1581

Merged
Gajesh2007 merged 1 commit into
masterfrom
fix/flaky-shape-warmup-retry-test
Oct 23, 2026
Merged

Gajesh2007 merged 1 commit into
masterfrom
fix/flaky-shape-warmup-retry-test

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

ProductionModelCalibrationTests/shapeWarmupRetryResumesAfterFinishedCells fails intermittently at its idle check, engine.capacity().activeRequests == 0. This blocked provider v0.10.1 release qualification.

Root cause. EngineV2 serves capacity() from a gauge snapshot. The engine thread republishes that snapshot only at a step boundary (EngineLoopV2.publishGauges). That happens after finishRequest has handed the request's terminal to the detokenizer queue, and in the idle branch it also waits for releaseBoundRows and segment release. Meanwhile the bridge's pump, the calibration cell and the warmup session can all retire. awaitProductionCalibration() can then return while the engine still counts the last warmup request as active. A busy CI runner widens this window.

Fix (test-only). A private requireEngineIdle(_:budget:) helper polls engine.capacity().activeRequests == 0 && budget.serviceBudget.count == 0 every 10 ms for up to 10 s. If the engine never drains, it fails through #require and reports the active count and service charges. It replaces the immediate idle #expect in the target test and in each sibling test that has the same race. It also runs before any decode-row read, because decodeRowsTotal comes from the same lagging snapshot and could undercount. In the wider-width test it also runs before the baseline row read. The assertions, row bounds and test intent are unchanged. shapeWarmupBudgetIncludesPromptRender keeps its immediate check because it submits no request.

Before (test flow)

sequenceDiagram
    autonumber
    participant T as Test
    participant B as EngineV2Bridge
    participant E as EngineV2 thread
    T->>B: startShapeWarmupIfNeeded / awaitProductionCalibration
    B->>E: warmup cell requests
    E-->>B: .finished (detok queue)
    B-->>T: pump + service charge retired, session ends
    rect rgb(255, 220, 220)
    T->>E: capacity().activeRequests  (stale snapshot)
    E-->>T: 1 → Expectation failed (flaky)
    end
    E->>E: publishGauges() at step boundary (too late)
Loading

After (test flow)

sequenceDiagram
    autonumber
    participant T as Test
    participant B as EngineV2Bridge
    participant E as EngineV2 thread
    T->>B: startShapeWarmupIfNeeded / awaitProductionCalibration
    B->>E: warmup cell requests
    E-->>B: .finished (detok queue)
    B-->>T: pump + service charge retired, session ends
    rect rgb(215, 245, 215)
    loop requireEngineIdle (10 ms poll, 10 s bound)
        T->>E: capacity().activeRequests, serviceBudget.count
    end
    E->>E: publishGauges() → active 0
    T->>E: decodeRowsTotal / idle assertions (published snapshot)
    end
Loading

Evidence

CI failures (same commit passed on master CI):

  • PR CI "Provider Unit Tests" on Prepare provider 0.10.1 #1579
  • Provider v0.10.1 release qualification, "Qualify provider with SDK 27" → step "Test provider with release SDK" (.github/actions/provider-release-build)
ProductionModelCalibrationTests.swift:121
Expectation failed: engine.capacity().activeRequests == 0 && budget.serviceBudget.count == 0
↳ engine.capacity().activeRequests == 0 → false

Local validation on a Mac Studio with the Swift 6.4 debug test build, from provider-swift/:

  1. Deleted the staged metallibs, then ran swift build --build-tests.
  2. Ran scripts/stage-test-metallib.sh.
  3. With isolated DARKBLOOM_STATE_FILE, DARKBLOOM_LOADED_MODELS_FILE and DARKBLOOM_VERIFIED_WEIGHTS_FILE, ran ../scripts/run-nested-suite.sh 'ProductionModelCalibration' --no-parallel twice.
Check Result
"Production Qwen startup calibration" suite after the fix 2 of 2 runs passed (10 of 10 tests each, about 73 s per run)
make docs-impact-check BASE=origin/master OK, 1 changed file

Limitations. The owner asked for speed because this blocks the release, so the planned 20-iteration loop and the before-fix reproduction were skipped. Locally, 80 repetitions of the unmodified test passed: 40 idle and 40 under 40 yes CPU hogs. The race window is too narrow to hit on this 28-core machine. The evidence for the race is the two CI failures plus the SDK code path above.

Merge Danger

Two-way door, test-only. One test file changes. There is no production, SDK, protocol or docs change and no changelog fragment. Reverting is a single-file revert.

Refactor pass

The repository's dedicated refactor pass (AGENTS.md, "Required Refactor Pass") is pending. The coordinating parent session will run it.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…he shape warmup retry test

EngineV2 republishes its capacity gauges at the step boundary after a
request's terminal event, so the bridge can retire a finished warmup or
calibration request while engine.capacity() still counts it active.
The production calibration tests read those gauges immediately and failed
intermittently on CI. Poll for the idle engine (10 s bound, explicit
failure message) before the idle and decode-row assertions.
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Ready Ready Preview Oct 23, 2026 11:49pm UTC
d-inference-console-ui-dev Ready Ready Preview Oct 23, 2026 11:49pm UTC
d-inference-landing Ready Ready Preview Oct 23, 2026 11:49pm UTC
darkbloom-status Ready Ready Preview Oct 23, 2026 11:49pm UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 23, 2026 11:49pm UTC

Request Review

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head 1280da5a412e against base 56fd55aceb33.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Review in progress; coverage is not complete

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 4/4 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

Saved findings and earlier report · Historical findings are not confirmed resolved.

Bedrock: 1 request(s), 48635 uncached + 0 cache-read + 0 cache-write input / 650 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately.
Workload allowance: 2 native request(s), including one shared response repair; 500 emergency ceiling. Selected depth and integration rounds are admitted as their scope becomes known.

@Gajesh2007
Gajesh2007 merged commit 9034a5a into master Oct 23, 2026
23 checks passed
@Gajesh2007
Gajesh2007 deleted the fix/flaky-shape-warmup-retry-test branch October 23, 2026 23:49
@jonathan308

Copy link
Copy Markdown
Collaborator Author

Refactor pass (required gate): no must-fix changes.

  • Helper behavior is correct. publishGauges() publishes activeRequests and decodeRowsTotal together, so waiting before every decodeRowsTotal read is right, including the new baseline wait.
  • Timeout and message: fine.
  • Name and placement: they match the existing private requireIdle helpers, and there is no shared helper to reuse.
  • Untouched immediate checks are correct: the ones at lines 176, 197, 270 and 302 are right as they are.

Optional follow-up. budget.serviceBudget.count == 0 doesn't need to wait. Calibration cells release their charges before awaitProductionCalibration() returns (runModelCalibrationRequest waits for serviceBudget.waitForRelease). Checking it immediately and polling only engine.capacity().activeRequests would keep a late charge-release regression visible. As merged, the helper also waits on the budget, so the PR body's "assertions unchanged" is slightly broader than the code.

This branch was successfully deployed

5 active deployments
Preview – d-inference — 1280da5a Deployed Oct 23, 2026 by vercel[bot]
Preview – d-inference-landing — 1280da5a Deployed Oct 23, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 1280da5a Deployed Oct 23, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 1280da5a Deployed Oct 23, 2026 by vercel[bot]
Preview – darkbloom-status — 1280da5a Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants