Skip to content

fix(optimizer): report Failed when every Trial of an OptimizationJob failed - #1006

Open
debojyoti-dev wants to merge 1 commit into
kubeflow:mainfrom
debojyoti-dev:fix/optimizer-failed-trials-status
Open

debojyoti-dev wants to merge 1 commit into
kubeflow:mainfrom
debojyoti-dev:fix/optimizer-failed-trials-status

Conversation

@debojyoti-dev

@debojyoti-dev debojyoti-dev commented Nov 29, 2026 •

Copy link
Copy Markdown

What this PR does / why we need it:

Without max_failed_trials, Katib leaves maxFailedTrialCount unset and marks the Experiment Succeeded (reason ExperimentMaxTrialsReached) once it reaches maxTrialCount, even when every Trial failed. The SDK mapped that to Complete, so wait_for_job_status() returned normally for a search where nothing ran, and get_best_results() returned None. I reproduced this on kind (Kubernetes 1.34.11, Trainer v2.4.0, Katib v0.19.0) with a training function that raises: both Trials Failed, OptimizationJob Complete.

__get_optimization_job_from_cr now reports Failed when the Experiment is Succeeded but its status counts failed Trials and no succeeded or early-stopped ones. I used the Experiment's Trial counts rather than currentOptimalTrial (option 1 in the issue). That keeps the check to the case the issue describes, so a Succeeded Experiment with at least one succeeded or early-stopped Trial still reports Complete. With max_failed_trials set, Katib already fails the Experiment itself, and that path is unchanged.

Tests:

  • test_get_job_status_conditions: new cases for every Trial failed (Failed), some Trials failed (Complete), and early-stopped plus failed Trials (Complete).
  • test_wait_for_job_status: a new case where waiting for Complete on a job whose Trials all failed raises RuntimeError.
  • create_experiment_cr takes optional Trial counts.
  • The two all-failed cases fail on main and pass with this change. The full unit suite, ruff check/format, ty and pre-commit pass locally.

Related: #893 also edits the status mapping in __get_optimization_job_from_cr (the Running condition). The two changes touch different branches of the same loop, so at most a small rebase is needed whichever lands first.

AI disclosure: I used Claude Code to help with this change. I reviewed and tested every line, per the Kubeflow AI policy.

Which issue(s) this PR fixes (optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged):

Fixes #999

Checklist:

  • Docs included if any changes are user facing (bug fix only, no docs change needed)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Kubernetes optimization jobs are now reported as failed when an Experiment finishes with failed trials and no successful or early-stopped trials. This prevents fully unsuccessful runs from being shown as complete.
    • Experiments with a mix of failed and successful or early-stopped trials continue to be reported as complete.

…failed

Without maxFailedTrialCount, Katib marks the Experiment Succeeded once it
reaches maxTrialCount, even if every Trial failed. The SDK mapped that to
Complete, so wait_for_job_status() returned normally for a search where
no Trial ran successfully.

Report Failed when the Experiment is Succeeded but its status counts
failed Trials and no succeeded or early-stopped ones.

Fixes kubeflow#999

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Debojyoti Banerjee <debojyoti30dev@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 astefanutti 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 Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Kubernetes backend now maps a succeeded Experiment to a failed OptimizationJob when it reports failed trials and no succeeded or early-stopped trials. Tests cover all-failed and mixed trial outcomes, including the error raised when waiting for completion.

Changes: Optimization job status

Layer / File(s) Summary
Map Experiment outcomes to job status
kubeflow/optimizer/backends/kubernetes/backend.py, kubeflow/optimizer/backends/kubernetes/backend_test.py
The backend maps a succeeded Experiment with only failed trials to OPTIMIZATION_JOB_FAILED. Tests verify that mixed outcomes remain complete and that waiting for completion raises RuntimeError for the all-failed case.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: andreyvelich, szaher

Merge Risk: Minimal · up to 91236

An OptimizationJob whose trials all failed now reports Failed instead of Complete. Callers that waited for completion now get an error instead of returning normally. The change is small, tested, and shows no remaining merge risk.

Security architecture risk: Minimal · up to 91236

The SDK now reports failure when Katib reports a succeeded experiment with failed trials but no successful or early-stopped trials. This changes what callers see, not how jobs run, what the SDK can access, or what is stored in Kubernetes.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed output is limited to SDK callers already able to read the affected Experiments through the configured namespace. The mapping adds no cross-namespace lookup, resource mutation, or disclosure of the underlying counters.

Trust Boundaries and Controls

  • observed — Trial counters reach the new branch through the existing namespaced Kubernetes response. They affect the returned SDK status, not the client identity, namespace, or target of a privileged operation.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: an OptimizationJob is reported as Failed when every Trial failed. The changeset matches this. The status mapping in backend.py treats a Succeeded Experiment with only …
Linked Issues check Passed [#999] The issue asks that an OptimizationJob with no successful Trial not report Complete when max_failed_trials is unset. The PR changes KubernetesBackend.__get_optimization_job_from_cr in kubeflow/…
Out of Scope Changes check Passed The PR changes two files: backend.py (the status mapping for the Succeeded Experiment condition) and backend_test.py (tests and the create_experiment_cr helper, which gains an optional trial_counts pa…
Full details: Title check

Explanation

The title names the main change: an OptimizationJob is reported as Failed when every Trial failed. The changeset matches this. The status mapping in backend.py treats a Succeeded Experiment with only failed trials as failed, and the tests cover the all-failed case. The title follows the conventional commit style and is 75 characters long.

Full details: Linked Issues check

Explanation

[#999] The issue asks that an OptimizationJob with no successful Trial not report Complete when max_failed_trials is unset. The PR changes KubernetesBackend.__get_optimization_job_from_cr in kubeflow/optimizer/backends/kubernetes/backend.py. When the Experiment condition Succeeded is True, the code maps the job to OPTIMIZATION_JOB_FAILED if status.trials_failed is set and neither trials_succeeded nor trials_early_stopped is set. Otherwise it maps to OPTIMIZATION_JOB_COMPLETE. This covers the all-failed case from the issue. The Failed condition path is unchanged, so max_failed_trials=1 still reports Failed. Tests in backend_test.py cover the all-failed case (Failed), a mixed case (Complete), and an early-stopped plus failed case (Complete). A wait_for_job_status case expects RuntimeError for an all-failed job. The PR uses Experiment Trial counts instead of currentOptimalTrial, which the issue listed as option 1. The stated scope of the issue is the all-failed case, and the implementation meets that scope. Edge cases with zero Trial counts are not addressed, and the issue does not require them.

Full details: Out of Scope Changes check

Explanation

The PR changes two files: backend.py (the status mapping for the Succeeded Experiment condition) and backend_test.py (tests and the create_experiment_cr helper, which gains an optional trial_counts parameter). Both changes support the objective in #999. No unrelated refactoring or feature work appears in the reviewed diff. The PR notes that #893 touches a different branch of the same loop. That work is not included in this PR and is not assessed here.

Finishing Touches

Generate unit tests (beta)

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

Run configuration

  • Source mode: Auto
  • Repository: kubeflow/sdk
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 8961a45
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dc6b50a1-f2d5-434d-a0e0-5f47960b0dbe
Commits

Reviewing files that changed from the base of the PR and between 8961a45 and 9123699.

Files selected for processing: 2

  • kubeflow/optimizer/backends/kubernetes/backend.py
  • kubeflow/optimizer/backends/kubernetes/backend_test.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 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

Status: Ready to Merge

Development

Successfully merging this pull request may close these issues.

bug(optimizer): OptimizationJob reports Complete when every Trial failed

1 participant