Skip to content

fix(trainer): keep pre_flight running when the Hugging Face lookup fails - #668

Open
shrxyas-246 wants to merge 1 commit into
kubeflow:mainfrom
shrxyas-246:fix/pre-flight-hub-offline
Open

shrxyas-246 wants to merge 1 commit into
kubeflow:mainfrom
shrxyas-246:fix/pre-flight-hub-offline

Conversation

@shrxyas-246

Copy link
Copy Markdown
Contributor

Description

pre_flight(model=...) fails with SDK_ERROR whenever Hugging Face can't give a size for the model: no network or an air-gapped cluster, HF_HUB_OFFLINE=1, a 429 or 5xx from the Hub, or a model with no parameter count in its metadata. Since #628, any failed check makes pre_flight return early, and that includes the estimate. SDK_ERROR also counts against the circuit breaker, so after 5 calls pre_flight is blocked for every caller with "K8s API may be degraded", even though the cluster is fine.

This keeps an SDK_ERROR from the estimate inside the report under estimate, as before #628. The compatibility, cluster and runtime checks still come back, and the breaker no longer counts it as a failure. A bad model ID or argument (VALIDATION_ERROR) still fails the whole call, and so does a failed cluster check.

Tests:

  • test_pre_flight_keeps_failed_hub_lookup: the report comes back with the estimate error, and runtimes are still listed.
  • test_pre_flight_hub_outage_does_not_open_breaker: through the server in full and progressive mode, with huggingface_hub.model_info raising a connection error, more calls than the breaker threshold and then pre_flight(). The breaker stays closed.
  • test_pre_flight_cluster_outage_still_opens_breaker: a failed cluster check still opens it.
  • test_pre_flight_propagates_failed_checks no longer covers an estimate SDK_ERROR. Its other cases are unchanged.

The first two fail on main.

Related Issue

Fixes #667

Checklist

  • I have read the CONTRIBUTING guide
  • Tests pass locally (make test-python)
  • Linting passes (make verify)
  • Documentation updated (if applicable)
  • My commits are signed off (git commit -s)

Testing

  • Unit tests
  • Integration tests
  • E2E tests
  • Manually tested (describe below)

make verify, make test-scripts and make test-python pass on Python 3.10, 3.11 and 3.12 (3223 passed), and make conformance passes.

End to end against a k3s cluster with the Trainer CRDs, over stdio and HTTP, main vs this branch:

Case main This branch
Hub unreachable (DNS fails) SDK_ERROR 5 times, then CIRCUIT_OPEN, also for pre_flight() Full report, estimate holds the error
HF_HUB_OFFLINE=1 Same lockout Full report
Hub answers 429 or 503 Same lockout Full report
Hub never answers SDK_ERROR after the 10 s timeout Full report after the 10 s timeout
Model without a parameter count in its metadata Same lockout Full report
Progressive mode (execute_tool) Same lockout Full report
HTTP, a second session after the first one's failures pre_flight() gets CIRCUIT_OPEN pre_flight() works
After the 30 s recovery timeout Next pre_flight(model=...) fails and reopens it No lockout
Valid model, Hub reachable Estimate returned Unchanged
Typo'd model (404), malformed ID, bad quantization or num_workers VALIDATION_ERROR Unchanged
Limited RBAC PERMISSION_DENIED Unchanged
estimate_resources called directly, Hub unreachable SDK_ERROR Unchanged

Same results with the uv.lock dependencies and with a plain pip install (huggingface-hub 2.5.0).

Since kubeflow#628, pre_flight returns early when any of its checks fails. That
includes the resource estimate, which only asks the Hugging Face Hub
for the model's size. When the Hub can't give one (no network or an
air-gapped cluster, HF_HUB_OFFLINE=1, a 429 or 5xx from the Hub, or a
model with no parameter count in its metadata), estimate_resources
returns SDK_ERROR and pre_flight(model=...) fails even though the
cluster is fine.

SDK_ERROR also counts against the circuit breaker. After five such
calls (the default threshold) the breaker for pre_flight opens, and
every pre_flight call, including ones without a model, gets "Circuit
breaker open for 'pre_flight' — K8s API may be degraded". The breaker
is shared by all sessions, so on an HTTP server this blocks every user.

An SDK_ERROR from the estimate now stays in the report under
"estimate", as it did before kubeflow#628, and the cluster and runtime checks
still run. A bad model ID or argument (VALIDATION_ERROR) still fails
the whole call, and so does a failed cluster check.

Assisted-by: AI coding assistants
Signed-off-by: DuskFall <shreyassrini2007@gmail.com>
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jaiakash for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Pre-flight checks now include Hugging Face lookup errors in the estimate and continue with other checks.
    • Invalid model IDs or arguments still stop the check and return a validation error.
    • Cluster outages continue to be reported as failures.

Pre-flight now continues its checks when the estimate step returns an SDK_ERROR and includes that error in the report. Other estimate errors still fail the call. Tests cover report contents and circuit-breaker behavior.

Changes: Pre-flight estimate handling

Layer / File(s) Summary
Handle estimate errors
kubeflow_mcp/trainer/api/planning.py
pre_flight continues after estimate errors with code SDK_ERROR and includes them in the report. Other estimate errors still return immediately. The documentation describes this distinction.
Validate reports and breaker behavior
kubeflow_mcp/trainer/api/planning_test.py
Tests verify that Hub lookup failures remain in successful reports and do not open the pre-flight breaker in full or progressive mode. Cluster-resource failures still open the breaker after repeated calls.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant pre_flight
  participant estimate_lookup
  participant cluster_checks
  participant report
  pre_flight->>estimate_lookup: request estimate
  estimate_lookup-->>pre_flight: SDK_ERROR
  pre_flight->>cluster_checks: continue checks
  cluster_checks-->>pre_flight: check results
  pre_flight->>report: include estimate error and check results
Loading

Possibly related issues

Suggested reviewers: abhijeet-dhumal, pratik-naik003

Merge Risk: Minimal · up to 6d06a

pre_flight now keeps returning compatibility, cluster, and runtime checks when the Hugging Face lookup fails, with the estimate error shown in the report. Invalid inputs and cluster failures still fail the call. Tests cover the new behavior, and no merge-blocking risk is visible.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: pre_flight keeps running when the Hugging Face lookup fails. The raw summary shows SDK_ERROR from the estimate now goes into the report instead of returning early, and…
Description check Passed The description covers the change in detail. It explains the Hugging Face failure modes, the circuit breaker impact, the retained VALIDATION_ERROR and cluster-failure behavior, and the new tests. It a…
Linked Issues check Passed [#667] Requirement: when the Hugging Face lookup cannot give a model size, pre_flight(model=...) must keep the compatibility, cluster, and runtime checks and place the estimate error under `estimate…
Out of Scope Changes check Passed The whole-PR diff against the merge base ce1dbcf changes only kubeflow_mcp/trainer/api/planning.py (the pre_flight early-return condition and its docstring) and `kubeflow_mcp/trainer/api/plannin…
Full details: Title check

Explanation

The title names the main change: pre_flight keeps running when the Hugging Face lookup fails. The raw summary shows SDK_ERROR from the estimate now goes into the report instead of returning early, and the PR objectives describe the same behavior. The title uses the conventional fix(trainer) prefix and is specific.

Full details: Description check

Explanation

The description covers the change in detail. It explains the Hugging Face failure modes, the circuit breaker impact, the retained VALIDATION_ERROR and cluster-failure behavior, and the new tests. It also links issue #667 and gives a manual test matrix. It matches the changeset in planning.py and planning_test.py.

Full details: Linked Issues check

Explanation

[#667] Requirement: when the Hugging Face lookup cannot give a model size, pre_flight(model=...) must keep the compatibility, cluster, and runtime checks and place the estimate error under estimate. Bad model IDs or arguments must still fail with VALIDATION_ERROR. The PR changes the early-return condition in kubeflow_mcp/trainer/api/planning.py from if estimate.get("error_code") to if estimate.get("error_code") not in (None, ErrorCode.SDK_ERROR). An SDK_ERROR from the estimate now falls through and is stored in result["estimate"]. Other error codes, including VALIDATION_ERROR, still return immediately. The cluster check still returns early on failure, as the issue requires. The PR tests cover the estimate error case with runtimes listed, the breaker staying closed in full and progressive mode, and cluster failures still opening the breaker. The issue's cases (offline, 429/5xx, no parameter count) all produce SDK_ERROR from the estimate, so they take the new path. Residual uncertainty: the comparison relies on error_code matching ErrorCode.SDK_ERROR; the PR reports passing tests that exercise this path, which supports the result.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base ce1dbcf changes only kubeflow_mcp/trainer/api/planning.py (the pre_flight early-return condition and its docstring) and kubeflow_mcp/trainer/api/planning_test.py (new tests, and removal of the SDK_ERROR estimate case from test_pre_flight_propagates_failed_checks). The docstring change documents the new behavior. The test changes support the new behavior and the regression coverage requested in #667. No unrelated code changes appear in the reviewed summary or the inspected diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ce1dbcf and 6d06aae.

Files selected for processing: 2

  • kubeflow_mcp/trainer/api/planning.py
  • kubeflow_mcp/trainer/api/planning_test.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(trainer): pre_flight(model=...) fails and opens its circuit breaker when the Hugging Face Hub is unreachable

1 participant