Repository navigation
feat: retry requests to remote WES instances - #201
Conversation
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>
Reviewer's GuideData structuresDefine and validate the retry policy and run-forwarding deadline that the retry and failover paths depend on.
APIAdd retry-aware WES client requests and deadline support to the run-submission interface.
Uses of the APIAllow backend selection to omit instances that have already been tried, and keep service-info probes to one attempt.
Forward new runs with a deadline, retry the stored backend safely, and fail over only when delivery was certainly not made.
ConfigurationSet default retry and forwarding-timeout values in application configuration and explain their operational effect.
Add commented ingress and router timeout examples and guidance on allowing forwarded runs to finish during shutdown.
DocumentationDocument the retry settings, safe retry and failover rules, forwarding deadline, and configuration example.
Explain proxy timeouts, worker capacity, and graceful shutdown requirements for longer run forwarding.
Update operational guidance for retried and failed remote WES requests.
Describe the retry and failover behavior and its timeout implications for upgrades.
TestsUpdate the shared test configuration to avoid real retry delays.
Align the existing client error test with the new local-error classification.
Cover retry policy validation, retry classifications, backoff and deadlines, single-attempt probes, and end-to-end run failover.
Verify backend selection excludes previously tried WES instances.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit efce822 #52 feat: retry connecting to remote WES · 1 of 2 met
|
There was a problem hiding this comment.
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
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>
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.
custom.wes.retry):attempts(default 3, 1 to 100),backoff(1 s, doubled per try) andmax_backoff(10 s). Reads (GET) are tried again after connection errors, timeouts, lost connections and502/503/504. Requests that change something (new runs, cancellations) are tried again only afterEngineRequestNotSent, 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.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.gracefulTimeout), commented chart annotations indeployment/values.yaml, upgrading notes for 0.20.0, andpro_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(withouttests/test_chart.py; Helm isn't installed locally): 870 passed, 100% coverage. CI runs the chart tests.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 throughPOST /runs, including the WES version per instance andforward_timeout), plustest_select_excludedintests/ga4gh/wes/test_routing.py. Waits are recorded rather than slept, and the test overlay setsbackoff: 0.ruff check,ruff format --check(0.17.5, as in pre-commit),mypy,ast-grep scanandast-grep test, semgrep with.semgrepon the changed files, andmkdocs build --strict: all pass.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: 30already 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 invalues.yamland 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