Skip to content

feat: retry requests to remote WES instances - #201

Merged
uniqueg merged 4 commits into
devfrom
feat/52-retry-remote-wes
Nov 21, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/52-retry-remote-wes

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Requests to remote WES instances are now tried again, and new runs fail over to the next WES instance, following proTES: a run goes elsewhere only if the current WES instance certainly did not get it, never if it may have.

  • Retries (custom.wes.retry): attempts (default 3, 1 to 100), backoff (1 s, doubled per try) and max_backoff (10 s). Reads (GET) are tried again after connection errors, timeouts, lost connections and 502/503/504. Requests that change something (new runs, cancellations) are tried again only after EngineRequestNotSent, which FOCA's guarded client raises only when no byte of the request was sent. They are never tried again after a timeout or any answer, including 5xx. Failures that another try wouldn't change (not_public, invalid URL, local errors such as an unreadable CA bundle, redirects, responses that are too large, other statuses) are not tried again. Service-info probes stay single tries, because their failures are cached.
  • Failover of POST /runs: if the stored WES instance certainly did not get the run after all its tries, the run goes to the next WES instance that can run it (select_backend(exclude=...)), in that instance's WES version. The new target is stored before the run is sent there. custom.post_runs.forward_timeout (default 30 s) bounds the tries and failovers: no further try or WES instance starts after it, but the first try always runs.
  • Docs: configuration reference (settings table, new "Retries" section), operations guide ("Failed requests"), deployment guide (new "Request timeouts" section on proxy timeouts and the Gunicorn gracefulTimeout), commented chart annotations in deployment/values.yaml, upgrading notes for 0.20.0, and pro_wes/config.yaml.

proWES keeps no new state: retries and failover happen within the request (decision: stateless like proTES).

Closes #52

Verification

  • coverage run -m pytest (without tests/test_chart.py; Helm isn't installed locally): 870 passed, 100% coverage. CI runs the chart tests.
  • New tests/ga4gh/wes/test_retries.py (configuration, read retries and non-retries, POST safety, backoff cap, deadline boundary with a scripted clock, single-try probes, failover end to end through POST /runs, including the WES version per instance and forward_timeout), plus test_select_excluded in tests/ga4gh/wes/test_routing.py. Waits are recorded rather than slept, and the test overlay sets backoff: 0.
  • ruff check, ruff format --check (0.17.5, as in pre-commit), mypy, ast-grep scan and ast-grep test, semgrep with .semgrep on the changed files, and mkdocs build --strict: all pass.
  • Reviews: adversarial and quality reviewers, two rounds.
  • CI: all checks pass on the latest commit, including Chart, Chart install, Integration, Smoke test, Test and Codecov.

Declined review findings

  • Set proxy timeout annotations in the chart by default (adversarial reviewer, medium): declined. The defaults depend on the cluster's router or ingress controller, and Helm chart defaults are a deployment decision. I documented them instead, with ready-to-use commented annotations in values.yaml. The risk is not new: timeout_post: 30 already exceeded the OpenShift router's 30 s.

  • Per-process cooldown for WES instances that just failed to connect (adversarial reviewer, round 2, medium): declined for this PR. It would add shared state per process, which is a design change beyond feat: retry connecting to remote WES #52. I documented the thread sizing instead (deployment guide, Request timeouts). It could be a follow-up issue if wanted.

  • Raise the chart default of gracefulTimeout (quality reviewer, round 2, medium): declined as a chart-default change. The comment in values.yaml and the deployment guide now say to raise it (e.g. to 70) and what happens otherwise.

  • Sourcery: one thread fixed (the deadline is checked again after waits and after choosing the next WES instance). Five were answered and resolved: deduplicating client resubmissions (no idempotency key in WES; out of scope), same-URL entries (FOCA lists each URL once), a failing MongoDB write during failover, storing the target before sending (deliberate), and single-try service-info probes (deliberate, failures are cached).

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 3 commits November 21, 2026 12:42
Try requests to WES instances again as `custom.wes.retry` says
(attempts 3, backoff 1 s doubling up to max_backoff 10 s): reads after
connection errors, timeouts, lost connections and 502/503/504; requests
that change something (new runs, cancellations) only if the WES
instance certainly didn't get them. Service info probes stay single
tries, as their failures are cached.

New runs that a WES instance certainly didn't get go to the next WES
instance that can run them, as in proTES, within
`custom.post_runs.forward_timeout` (30 s); the run is then stored with
that instance and its WES version.

Document the settings in the configuration reference, operations guide
and upgrading notes.

Closes #52

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Log why no further WES instance is tried after a failed forward.
- Keep the retry rules for statuses in one helper (`_retried_status`).
- Cap `custom.wes.retry.attempts` at 100 (the doubling overflowed for
  very large values).
- Test deadlines with a scripted clock instead of real time, the
  exclusion of WES instances in `select_backend()` directly, and the WES
  version of each WES instance on failover.
- Document proxy timeouts and the Gunicorn graceful timeout for the
  longer `POST /runs` (deployment guide, chart value comments,
  upgrading notes); one row per retry setting in the reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Requests that fail before anything is sent because of proWES itself
(e.g., an unreadable CA bundle) now have the reason `local_error` and
are not tried again, as another try can't change that.

Name the run in the failover logs, document the longer bound of
`POST /runs` (forward_timeout + timeout_post + 10 s), the Gunicorn
graceful timeout and threads, and that only new runs have an overall
limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define and validate the retry policy and run-forwarding deadline that the retry and failover paths depend on.

  • pro_wes/config_models.py L121-163, L266-271 (+4 small edits)

API

Add retry-aware WES client requests and deadline support to the run-submission interface.

  • pro_wes/ga4gh/wes/client_wes.py L28-45, L92-145, L634-736 (+13 small edits)

Uses of the API

Allow backend selection to omit instances that have already been tried, and keep service-info probes to one attempt.

  • pro_wes/ga4gh/wes/routing.py L237-242 (+7 small edits)

Forward new runs with a deadline, retry the stored backend safely, and fail over only when delivery was certainly not made.

  • pro_wes/ga4gh/wes/workflow_runs.py L229-241, L343-353, L392-521 (+7 small edits)

Configuration

Set default retry and forwarding-timeout values in application configuration and explain their operational effect.

  • pro_wes/config.yaml L211-215, L254-264

Add commented ingress and router timeout examples and guidance on allowing forwarded runs to finish during shutdown.

  • deployment/values.yaml L157-160, L203-205, L266-268

Documentation

Document the retry settings, safe retry and failover rules, forwarding deadline, and configuration example.

  • docs/configuration.md L33-36, L208-269

Explain proxy timeouts, worker capacity, and graceful shutdown requirements for longer run forwarding.

  • docs/deployment.md L359-381, L412-416

Update operational guidance for retried and failed remote WES requests.

  • docs/operations.md L41-47

Describe the retry and failover behavior and its timeout implications for upgrades.

  • docs/upgrading.md L115-124

Tests

Update the shared test configuration to avoid real retry delays.

  • tests/conftest.py L4-7, L164-166

Align the existing client error test with the new local-error classification.

  • tests/ga4gh/wes/test_client_wes.py L449

Cover retry policy validation, retry classifications, backoff and deadlines, single-attempt probes, and end-to-end run failover.

  • tests/ga4gh/wes/test_retries.py L1-783

Verify backend selection excludes previously tried WES instances.

  • tests/ga4gh/wes/test_routing.py L596-607

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proWES | 🛠️ Build #36065568 | 📁 Comparing efce822 against latest (6fa856f)

  🔍 Preview build  

6 files changed · ± 6 modified

± Modified

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6c2469f) to head (efce822).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #201   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         1359      1444   +85     
=========================================
+ Hits          1359      1444   +85     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 21, 2026 12:50
@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit efce822

#52 feat: retry connecting to remote WES · 1 of 2 met

# Requirement Status Notes
1 Implement retry options for all remote connections 🟡 Partly met Remote WES API operations use the retrying client, but routing service-info probes explicitly set attempts=1.
2 Add corresponding configuration options ✅ Met The change adds validated custom.wes.retry settings for attempts, backoff, and maximum backoff, with defaults.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 6 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pro_wes/ga4gh/wes/client_wes.py" line_range="723" />
<code_context>
+            attempt + 1,
+            self.retry.attempts,
+        )
+        _sleep(wait)
+        return True
+
</code_context>
<issue_to_address>
**Requests start after forwarding expires**

When a retry sleep resumes late or backend selection crosses the deadline, `_wait` returns after sleeping and `_next_backend` can return after a slow `select_backend`; `_send` and `_forward` then start the next POST without another deadline check, so requests run beyond `forward_timeout`.

Recheck the deadline after sleeping and backend selection, before starting each POST.

Also at `pro_wes/ga4gh/wes/workflow_runs.py:435`, `pro_wes/ga4gh/wes/workflow_runs.py:493-502`.
</issue_to_address>

### Comment 2
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="330" />
<code_context>
-            document_stored.run_log.run_id,
-            document_stored.task_id,
-            url,
+        # forward incoming WES request and validate response, to the next WES
+        # instance that can run it while they certainly don't get it
+        response = self._forward(
</code_context>
<issue_to_address>
**Retries create duplicate workflows**

When a proxy or caller times out while the original POST is still forwarding or has been accepted remotely, then resubmits, `POST /runs` creates a fresh run document and forwards a separate remote POST for each request, so the resubmission can start a second workflow and return a different run ID.

Deduplicate repeated submissions so a retry returns the original run instead of creating and forwarding another run.

Also at `pro_wes/config_models.py:309`.
</issue_to_address>

### Comment 3
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="441" />
<code_context>
+                    deadline=deadline,
+                )
+            except EngineRequestNotSent as exc:
+                tried.add(backend.url)
+                following = self._next_backend(run_id, form_fields, tried, deadline)
+                if following is None:
</code_context>
<issue_to_address>
**Failover skips distinct API endpoints**

When configured WES entries share a URL but have different API paths, and one needs failover, `_forward` adds only `backend.url` to `tried`, and `select_backend` excludes every entry with that URL, so failure at one endpoint skips the other distinct API endpoint and can mark the run failed.

Track and exclude individual WES endpoints rather than excluding every endpoint that shares a URL.

Also at `pro_wes/ga4gh/wes/routing.py:339-341`.
</issue_to_address>

### Comment 4
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="457" />
<code_context>
+                backend = following
+                # stored before it is sent, so that the run never points at
+                # a WES instance other than the last one it was sent to
+                db_connector.upsert_fields_in_root_object(
+                    root="wes_endpoint",
+                    host=backend.url,
</code_context>
<issue_to_address>
**Failover write leaves run stuck**

When the database write for the new endpoint fails after the prior WES instance certainly did not receive the run, `upsert_fields_in_root_object` can raise during a transient database write failure, and `_forward` does not handle that exception to set the run to `SYSTEM_ERROR`. The request fails before the next WES instance is sent the run, leaving the stored run in `UNKNOWN` with no tracking task queued.

Handle failover endpoint update failures so the run is marked `SYSTEM_ERROR` when possible and the failure is surfaced clearly.
</issue_to_address>

### Comment 5
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="457-461" />
<code_context>
+                backend = following
+                # stored before it is sent, so that the run never points at
+                # a WES instance other than the last one it was sent to
+                db_connector.upsert_fields_in_root_object(
+                    root="wes_endpoint",
+                    host=backend.url,
+                    base_path=backend.api_path,
+                    wes_version=str(backend.version),
+                )
+                continue
</code_context>
<issue_to_address>
**Failover records an unsent endpoint**

When the process stops after the endpoint update and before the next `POST /runs` is sent, the endpoint is written before the next `POST /runs` starts, so a process crash in that gap leaves the run associated with a WES instance that never received it. The stored endpoint no longer identifies the last instance contacted, and the run remains without a remote run ID or a recorded forwarding failure.

Represent the next endpoint as pending until forwarding outcome is known, or otherwise make interrupted forwarding recoverable without treating that target as contacted.
</issue_to_address>

### Comment 6
<location path="pro_wes/ga4gh/wes/routing.py" line_range="242" />
<code_context>
-        host=backend.url, base_path=api_path(backend, get_backend_list())
+        host=backend.url,
+        base_path=api_path(backend, get_backend_list()),
+        retry=Retry(attempts=1),
     )
     return client.read_service_info(timeout=timeout)
</code_context>
<issue_to_address>
**Service-info probe retries**

The issue asks for retries for all remote connections, but service-info probes are explicitly created with `attempts=1` instead of using the configured retry options.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 6 findings to address first, and if a POST /runs failure is incorrectly classified as definitely not sent, the retry or failover can submit the workflow again and launch duplicate remote runs. Reverting stops future retries, but cannot undo workflows the remote WES has already started.

Blocking findings: pro_wes/ga4gh/wes/client_wes.py:723, pro_wes/ga4gh/wes/workflow_runs.py:330, pro_wes/ga4gh/wes/workflow_runs.py:441, pro_wes/ga4gh/wes/workflow_runs.py:457, pro_wes/ga4gh/wes/workflow_runs.py:461, and 1 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pro_wes/ga4gh/wes/client_wes.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/routing.py Resolved
Check `custom.post_runs.forward_timeout` again after the wait between
two tries and after choosing the next WES instance (which may read
service infos), so that no try starts after the deadline, e.g., after
a sleep that ended late or a slow service info.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uniqueg
uniqueg merged commit 11c0377 into dev Nov 21, 2026
34 checks passed
@uniqueg
uniqueg deleted the feat/52-retry-remote-wes branch November 21, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: retry connecting to remote WES

1 participant