← Back to Pull requests

RHOAIENG-96353: Implement job reads, logs, and terminal cleanup #8

Closed
unknown closed this pull request without merging on Nov 03, 2026 16:28 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 14:38 UTC
Author

Summary

Implements RHOAIENG-96353:
project-scoped training-job reads, driver logs, and safe terminal deletion.
Aligned with merged submission PR #7; this update consolidates the handlers
and backend code used by the deployed service and addresses review findings.

Implemented behavior

  • GET /api/v1/projects/{project}/training-jobs: compact summaries,

  • total_count, pagination, and optional status/queue filters. No status
    filter returns jobs across all statuses.
  • GET /api/v1/projects/{project}/training-jobs/{job_id}: available job

  • details, accepted submission, original submitter, node resources,
    created/started/finished timestamps, and failure information.
  • GET /api/v1/projects/{project}/training-jobs/{job_id}/logs:

  • driver-log snapshot by default; follow=true streams SSE events through
    CodeFlare SDK. Streams are bounded to five minutes and require reconnecting
    to reauthenticate. Logs are neither persisted nor aggregated across workers.
  • DELETE /api/v1/projects/{project}/training-jobs/{job_id}: terminal-only

  • foreground deletion of the RayJob resource and its exclusively owned
    dependents. 204 accepts asynchronous cleanup; GPUs become available after
    the owned pods terminate.

    Structure and submission alignment

  • One api_impl/training_jobs.py handler owns create/list/detail/delete;

  • removed the separate job-operations handler and per-operation dispatcher.
  • Consolidated submission and job operations in jobs.py behind an injectable

  • JobsBackend interface. API handlers do not interpret Ray resource formats.
  • observability.py owns the logs endpoint; logs.py provides backend-neutral

  • responses and the hardened CodeFlare/Ray log transport. Shared caller-scoped
    Kubernetes access is in kubernetes_client.py.
  • Submission and job operations use one configuration builder for Kubernetes

  • host, CA, verified TLS, and caller credentials, including the existing
    TRAINING_SERVICE_KUBERNETES_API_URL and
    TRAINING_SERVICE_KUBERNETES_CA_FILE overrides. Each client remains isolated;
    no global configuration changes or service-account token refresh hooks.
  • Generated routes and their templates use one registered handler per API

  • group and derive job authorization resources from the configured backend.
  • Preserve PR #7's caller-scoped CodeFlare submission, 202/Location,

  • metadata, resource mapping, and validation behavior.
  • Update the OpenAPI contract, generated sources, and architecture/operations

  • documentation to match the consolidated implementation.

    Security and cleanup

  • OpenShift TokenReview and project SubjectAccessReview run before backend

  • access. Workload operations use the verified caller's credentials, not
    elevated service-account workload privileges.
  • Known OpenShift invalid-token rejection errors return 401; unknown or

  • mixed authentication infrastructure failures remain 503.
  • Reject non-HTTPS or malformed Kubernetes API overrides before creating

  • workload clients or attaching caller credentials. Reject embedded credentials,
    query parameters, and fragments with sanitized 503 backend_unavailable.
  • Backend 401 responses include WWW-Authenticate: Bearer. The pinned Ray

  • SDK transport uses an HTTP response hook to preserve the original 401/403
    distinction before the SDK normalizes authentication errors.
  • Preserve HTTP statuses and symbolic error codes while making error messages

  • actionable. Missing-job reads, deletion (including concurrent disappearance),
    and initial log lookups identify the requested job and project. Project
    lookups and missing submission PVC/Secret references identify the actual
    resource; duplicate submissions identify the job and project. Missing Ray
    submissions remain distinct from missing RayJob resources. Messages use
    known request context, not raw backend response bodies or credentials, and
    do not use privileged existence probes after permission failures.
  • Driver logs use CodeFlare RayJobClient with verified TLS, bounded requests,

  • redirect rejection, trusted gateway routing, and verified cluster ownership;
    they do not use Kubernetes pods/log.
  • Log transport distinguishes startup readiness, missing submissions, and

  • infrastructure failures: before Ray registration, return 409 logs_not_ready
    even if KubeRay has already allocated IDs. If Ray reports an absent submission,
    return JSON 404 not_found without indefinite retry guidance, for both snapshot
    and follow requests. A removed registered cluster remains 410 ray_cluster_gone;
    version/gateway endpoint failures remain 503 logs_unavailable. Error responses
    do not expose gateway URLs, backend response bodies, or caller credentials.
  • Delete only execution states SUCCEEDED, FAILED, and STOPPED.

  • Active, retrying, shared, or unowned workloads are rejected with 409.
    UID/resource-version preconditions protect against concurrent changes.
  • Delete the RayJob instance, never the shared CRD. Do not force-remove

  • finalizers or directly delete user PVCs, Secrets, or outputs.

    Scope boundaries

  • The current backend is CodeFlare/Ray; this interface separation does not

  • implement Kubeflow Trainer support.
  • Submission retains the basic lora_sft parameters from PR #7:

  • learning_rate, num_epochs, effective_batch_size, and max_seq_len.
    Generic algorithm/runtime-schema support is not part of this PR.
  • Algorithm/queue discovery and estimation remain 501 Not Implemented.

  • No Helm chart/deployment manifest changes. E2E tests and their

  • README/Makefile hooks are intentionally excluded
    and remain local for a
    separate PR. Relevant unit and transport regression tests are included.

    Validation

  • make check: 209 unit tests passed; Ruff lint/format and mypy passed.

  • Regression tests reproduced the review findings before the fixes. Coverage

  • includes invalid Kubernetes URLs rejected before client creation, caller/token
    isolation, Bearer challenges for Kubernetes failures, real loopback HTTP tests
    through the pinned Ray SDK for 401/403, and missing-submission versus
    provisioning errors for both snapshot and follow requests. Startup does not
    misreport a not-yet-created RayCluster as gone.
  • Contextual-error regressions reproduced 13 focused failures before the fix.

  • Coverage includes missing jobs across GET/DELETE and both log follow modes,
    deletion races, missing projects, PVCs and HF/S3 Secret references, duplicate
    names, and sanitization. An absent job API is not mislabeled as a missing
    project after successful namespace lookup.
  • uv sync --locked --offline and uv build --offline: passed.

  • Generated API sources were previously verified with

  • make generate-server CONTAINER_RUNTIME=podman; unchanged by these fixes.
  • git diff --cached --check: passed.

  • The local-only E2E suite was updated: 36 cases collected, including

  • resource-context assertions and missing PVC/HF/S3 reference submissions.
    30 passed, 6 skipped against commit 97cc31a, deployed as Helm revision
    8 of training-service-pr8-integration in test-efazal. Verified ingress
    TLS, image digest, and deployed source hashes. Missing-job, missing-project,
    and missing PVC/HF/S3 reference checks passed; rejected submissions created
    no job. A real Qwen 0.5B LoRA training run without Kueue succeeded,
    including duplicate-name errors, details/listing, snapshot logs, and terminal
    deletion. An additional live check verified non-empty SSE log events.
  • Independently verified the E2E RayJob, RayCluster, and GPU pod were removed.

  • Other Helm releases were unchanged. Six fixture-dependent checks were skipped:
    two absent-Ray-submission cases, three deliberately invalid Kubernetes URL
    cases, and one caller-inaccessible-project check. Kueue-enabled submission
    was not exercised in this live run.
  • E2E files and their README/Makefile hooks remain uncommitted for a separate

  • follow-up PR. Timestamp assertions honor the documented optional execution
    timestamps and validate timezone/order whenever those values are supplied.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Added training-job listing with status and queue filters, pagination, job details, driver-log snapshots and live streaming, and deletion of eligible terminal jobs.
    Job deletion cleans up associated resources; shared resources and concurrent changes can prevent deletion.
    Bug Fixes
    Improved invalid-token handling and parsing of integer and boolean query parameters.
    Expanded error responses for conflicts, unavailable services and logs, and invalid pagination.
    Documentation
    Added guidance on job operations, authorization, logs, pagination, deletion, and errors.
    * Clarified that algorithm and queue discovery and job estimation remain unavailable.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    [RHOAIENG-96353]: https://redhat.atlassian.net/browse/RHOAIENG-96353?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Sridhar1030 Review duration: 17389m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%