← Back to Pull requests

OCPBUGS-128842: honor graph download context and status #1566

Open
unknown opened this pull request with 556 lines diff across 6 files
View on GitHub
unknown unknown commented on Oct 01, 2026 04:24 UTC
Author

OCPBUGS-128842

Repository: openshift/oc-mirror
Component: oc-mirror
Files: internal/pkg/release/graph.go, internal/pkg/release/graph_test.go
Fixes: https://redhat.atlassian.net/browse/OCPBUGS-128842
Status: pushed as single commit 60eead95; reviewer feedback addressed.

Summary

Make graph-image downloads context-aware and status-aware. Command cancellation can then stop a stalled graph request, and HTTP failures are reported before gzip/archive decoding.

Error

Before this change, CreateGraphImage accepted a context but used http.Get. A non-success response was read as graph data and later reported as a gzip/archive error.

Fix

The implementation mirrors the existing internal/pkg/cincinnati/download.go request pattern:

  • Build the request with http.NewRequestWithContext.

  • Derive the graph request timeout from the existing GlobalOptions.CommandTimeout, which is configured by --image-timeout and defaults to 10 minutes. Preserve the supplied caller context and do not impose an immediate timeout when the duration is zero.

  • Use client.Do(req.WithContext(timeoutCtx)) and wrap request/read errors with operation context.

  • Require resp.StatusCode == http.StatusOK and return unexpected HTTP status <status> before reading graph data.

  • Preserve the existing graph-image build and cache paths after a successful response.
  • Why this approach

    | Alternative | Decision | Reason |
    |---|---|---|
    | Keep http.Get | Rejected | It ignores the supplied context. |
    | Set http.Client.Timeout | Rejected | The repository's analogous download path derives a timeout context, which preserves caller cancellation/deadlines and provides the established error behavior. |
    | Accept every 2xx response | Rejected | The cited Cincinnati pattern requires exactly http.StatusOK; 204 and 206 are not graph archives. |
    | Decode before checking status | Rejected | It produces a misleading archive error. |
    | Context-bound request with exact status check | Chosen | Matches cincinnati/download.go and preserves successful graph handling. |

    Testing Results

    The fix-specific tests were added and run against the unmodified revision first. Baseline results were expected failures for status reporting, cancellation, and deadline handling; success, invalid-URL, and graph-disabled cases passed. Post-fix validation passed:

    $ go test -tags 'json1 exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp' -short -race -count=1 -timeout=5m ./internal/pkg/release/...
    ok  github.com/openshift/oc-mirror/v2/internal/pkg/release  24.123s
    
    $ bash 'testing tools/scripts/run-lane.sh' fix-validation investigations/OCPBUGS-128842-graph-fetch-context-status/intake-OCPBUGS-128842-pr1566.yaml
    ok  github.com/openshift/oc-mirror/v2/internal/pkg/release  21.915s
    RESULT: PASS (exit 0)
    

    make verify remains blocked by 232 pre-existing repository-wide lint findings, including the unchanged mockImageBuilder.ProcessImageIndex interface-return warning and existing graph.go findings outside the rework. Diff-scoped lint reports 0 new issues. The validation preflight classifies macOS Bash 3 and loopback listener failures as host/toolchain limitations. The mandatory make test-envtest-ocp target is not applicable because no API or CRD files changed.

    Backward compat

    Valid HTTP 200 gzip graph data and cached disk-to-mirror paths remain supported. Only stalled or non-successful HTTP responses change from misleading decode failures to actionable request errors. The change is a clean backport candidate for release-5.2 and release-5.1; both branches currently share the main base revision and no API or generated files changed.

    Workaround

    Use a reachable graph endpoint and wrap the command in an external timeout when endpoint behavior is uncertain.

    Related

  • Graph implementation PR: https://github.com/openshift/oc-mirror/pull/722

  • Coverage/refactoring PR: https://github.com/openshift/oc-mirror/pull/783

  • Jira: https://redhat.atlassian.net/browse/OCPBUGS-128842
  • Unit Test

    graph_test.go covers successful graph downloads in mirror-to-disk and mirror-to-mirror modes, the configured command timeout, zero-timeout success, HTTP 204/206/503 rejection before gzip parsing, context cancellation, context deadlines, invalid URL construction, and the graph-disabled collector path. Request-error tests also assert that the image builder is not invoked.

    Diff: 556 lines (+417 / -139) across 6 files Reviewer: chdeshpa-hue Review duration: 87514m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.55) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 556 lines diff across 6 files
    0.55
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    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.378
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1566"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% 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: 55.1% (MEDIUM) · Higher = larger blast radius
    55.1%
    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: 40.9% · Lower = rushed or shallow review
    40.9%
    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: 32.6% · Safe to merge
    32.6%