← Back to Pull requests

fix(hermes-plugin): retry the health probe when a gateway redirects to its login page #5984

Open
unknown opened this pull request with 486 lines diff across 6 files
View on GitHub
unknown unknown commented on Oct 13, 2026 06:05 UTC
Author

What

The startup identity probe (GET /health) is anonymous-first on purpose — credentials must not reach an unknown host — and it only retried with credentials when the anonymous call came back 401/403. Gateways that answer a header-less request by redirecting to their own login page were not covered:

anonymous GET /health           → 302  Location: https://<team>.cloudflareaccess.com/cdn-cgi/access/login/<host>
same request + service token    → 200  {"status":"ok","healthy":true,"version":"v0.5.0","auth_mode":"api_key"}

_parse_response() turns the HTML login page of that 302 into {}, so _probe_openviking_identity() classified a perfectly reachable server as

Service at https://<host> responded, but its /health response is not valid OpenViking. OpenViking memory is temporarily unavailable …

and dropped the client — while every authenticated request (including the data API) worked fine. Deployments behind Cloudflare Access could therefore never use this provider, even with extra_headers configured correctly (#5884 made those headers reach the probe; this is the remaining step).

The change

  • _anonymous_json() surfaces a 3xx as an _OpenVikingHTTPError carrying the status instead of parsing the redirect body into an empty dict.

  • _probe_needs_credentials() keeps 401/403 as "the server itself wants credentials" and retries a 3xx only when the connection carries gateway headers (extra_headers / OPENVIKING_EXTRA_HEADERS). Those headers are the operator's declaration that an authenticating gateway fronts the endpoint. A redirect on a connection with none of them is an ordinary redirect from an endpoint that has not been shown to be OpenViking, which is not authorization to resend the API key: it fails once, as it did before, and no credential leaves the process.

  • openapi_payload() shares _anonymous_json(), and its caller already wraps the call in try/except Exception, so the stricter probe only changes what the redirect case reports.
  • Thanks @ehz0ah — the first revision retried any 3xx and so sent the key on ordinary redirects. Narrowed in ff99f26c; the reasoning and the test are below.

    Tests

  • _start_server() in tests/test_extra_headers.py models both sides: redirect_to= (a gateway that redirects header-less requests) and plain_redirect_to= (an endpoint that simply redirects).

  • test_startup_probe_retries_when_gateway_redirects_to_login() — with gateway headers configured the probe retries and the client is kept.

  • test_ordinary_redirect_receives_no_secrets() — with none configured, an ordinary 302 gets a single anonymous request and no retry: no X-API-Key, no Authorization, no X-OpenViking-Account, and the client is dropped. On afaa711 it fails with an ordinary redirect was answered with credentials: {… "X-API-Key": "test-key", "Authorization": "Bearer test-key"}; on ff99f26c it passes.

  • Suite on this machine under the same conditions before and after: afaa711 21 failed / 387 passed, ff99f26c 21 failed / 388 passed, failure list identical (21 test_quick_local_preflight.py cases that need a real host install this box doesn't have). CI's hermes-plugin-tests passes on ff99f26c.
  • How it was verified

    Against a real self-hosted OpenViking published through Cloudflare Access:

  • 302 without the service token, 200 with it, data API 200, MCP handshake 200.

  • Provider initialize() through the public hostname with OPENVIKING_EXTRA_HEADERS set: 3/3 stable passes (2.8–4.0 s), followed by a real GET /api/v1/fs/ls against the same client.

  • Same code over a local SSH tunnel: unchanged (no redirect, anonymous probe still 200 in ~0.1 s).
  • Follow-up to #5884 — the review there asked whether a gateway that protects every route including /health would really work; that question is what led to this.

    Diff: 486 lines (+364 / -122) across 6 files Reviewer: ehz0ah Review duration: 183m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 486 lines diff across 6 files
    0.47
    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%
    46%
    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.370
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #5984"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 47.3% (MEDIUM) · Higher = larger blast radius
    47.3%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 25.2% · Safe to merge
    25.2%