Skip to content

feat!: configure WES backends - #173

Merged
uniqueg merged 9 commits into
devfrom
feat/118-wes-backends
Nov 18, 2026
Merged

uniqueg merged 9 commits into
devfrom
feat/118-wes-backends

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Runs go to the WES instances of custom.wes.backends instead of a hard-coded WES:

  • Backend list: a typed backend list of FOCA (foca.plugins.backends, as custom.tes.backends in proTES): WES instances (type: ga4gh-wes: url, optional api_path, id, labels, location, url_schemes) and service registries whose verified WES instances are used (type: ga4gh-service-registry, read by FOCA with its guarded HTTP client: no token, https, public addresses, no redirects, timeouts, per-process cache). Invalid entries, unknown keys and duplicate ids stop the app on startup.
  • Selection: new runs go to the first backend of the list (plugins choosing and ordering backends come with feat: run new runs through FOCA plugins #121). Without any, POST /runs is refused with 503 Service Unavailable (declared in the served spec as problem details) before anything is stored. The WES instance is stored with each run, so tracking and cancelling are unchanged.
  • No self-forwarding: backends at or below server.public_url (the root URL, as FOCA defines it) are never used; the app refuses to start if a configured one is (also its url + api_path), and refuses registry entries without server.public_url (as FOCA's gateways do).
  • Credentials: auth must be none for now; the client's token is never passed on to WES instances (with authentication off, there was none). Credentials per WES instance come with feat: authenticate clients and backends #120.
  • FOCA 0.22 gap: its backend lists know TES only, so proWES registers the WES API type in API_TYPES (setdefault, so a later FOCA one wins) and subclasses FOCA's entries and BackendList, until FOCA's backend lists support WES (FOCA issue drafted for the maintainer).
  • API path /: WesClient no longer builds host//runs for an empty base path.
  • Smoke test: the fake WES is the configured WES instance (https://fake-wes, TLS with its own CA), not an alias of the former hard-coded host.
  • Docs: configuration.md ("WES instances", "Discovery in a service registry"), deployment.md (chart: config.custom.wes.backends, no new values key; server.public_url), upgrading.md (breaking: configure backends; how to keep the former WES; no token forwarding), getting-started.md (Compose overlay), api.md (503), index.md, development.md, reference.md, commented example in deployment/values.yaml.

Not in this PR: requests to the WES instances themselves still use requests (TLS verification on, configured timeouts); moving them to FOCA's guarded client rewrites client_wes.py and changes the timeout settings, so it is split into its own issue (drafted for the maintainer).

Verification

  • coverage run -m pytest (mongomock, Helm 3.22.1 with helm dependency build deployment): 471 passed; coverage report: 100%.
  • pre-commit run --all-files (ruff, ruff format, mypy, semgrep and its rule tests, ast-grep and its rule tests, uv lock check, file checks): passed; gitleaks and actionlint skipped locally (Go toolchain download fails in the sandbox), run in CI.
  • mkdocs build --strict: passed.
  • Smoke test (Docker Compose) and the chart installation on kind: not run locally (no Docker in this environment); CI runs both.
  • Reviews: two rounds of adversarial and quality reviewer subagents. Fixed: public_url documented with the API path (disabled the self-check), registry entries without public_url, api_path ignored by the self-check, client token passed on, upgrade note, test assertions per invalid case, a regression test for token forwarding, comments on FOCA internals, docs wording.
  • CI: all checks passed on 9184ffa (Lint, Test, Docs, Chart, Chart install, Smoke test, codecov; image push skipped on PRs as intended).
  • Sourcery: 6 threads; fixed 2 (no redirects followed by WES clients; tracking task ignores client tokens of tasks queued by earlier versions), answered 4 (self-check without public_url, guarded client for WES requests (split), credentials (feat: authenticate clients and backends #120), plugin selection (feat: run new runs through FOCA plugins #121)); all resolved.

Declined review findings

  • Optionally map 401/403 of a WES instance to 502 (round 2, suggestion): changes the existing error mapping of forwarded runs; belongs with authentication (feat: authenticate clients and backends #120).
  • The unused jwt argument of the tracking task (pro_wes/tasks/track_run_progress.py) stays (low): it is always None now; feat: authenticate clients and backends #120 replaces it with credentials per WES instance, and the module was being changed by another PR.

Open questions

None.

Closes #118

🤖 Generated with Claude Code

uniqueg and others added 8 commits November 18, 2026 12:15
Runs go to the WES instances of `custom.wes.backends`, a typed backend
list of FOCA (`foca.plugins.backends`): WES instances (`type:
ga4gh-wes`, with an optional `api_path`) and service registries whose
verified WES instances are used (`type: ga4gh-service-registry`). New
runs go to the first backend; without any, `POST /runs` is refused with
`503 Service Unavailable` before anything is stored. The hard-coded WES
is gone, and the app refuses to start with a configured WES instance at
or below its public URL.

FOCA 0.22 knows the backends of TES gateways only: the API type of WES
is registered in `API_TYPES` (unless FOCA has one), and the entries of
proWES subclass FOCA's, with `auth: none` only until #120.

BREAKING CHANGE: deployments must configure their WES instances.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fake WES is the WES instance of the smoke test's config overlay, at
its Compose service name, instead of taking the host name of the former
hard-coded WES.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Configuration, deployment (chart values `config.custom.wes.backends`),
upgrade note, getting started, API and reference; a chart test checks
that the backends reach the config overlay as the app reads them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes: `server.public_url` is the root URL (docs said with the
API path, which disabled the check); backend lists with registry
entries need it; the startup check also covers `url` with `api_path`;
the client's token is never passed on to WES instances (`auth: none`).
Tests assert the reason of each invalid config; comments explain the
reliance on FOCA 0.22 internals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round-2 review fixes: a regression test that no WES instance gets the
client's token (runs, cancellations, tracking); the upgrade note says
so; the docs explain public URLs of WES instances on the same host.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The response for runs without a WES instance, as the problem details
of the other error responses (#170), with a test and the docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Schema and migrations

Persist the selected WES endpoint with each run so later tracking and cancellation continue using that instance.

  • pro_wes/ga4gh/wes/workflow_runs.py L135-138

Data structures

Define and validate the ordered WES backend configuration, including instance and registry entry types, API paths, authentication constraints, and unique identifiers.

  • pro_wes/config.yaml L193-204
  • pro_wes/config_models.py L4-12, L19-145 (+3 small edits)

API

Declare the 503 problem-details response for POST /runs when no WES backend is available.

  • pro_wes/api/additions.openapi.yaml L66-74

Expose backend selection failures as a service-unavailable exception and register its response mapping.

  • pro_wes/exceptions.py L58-65, L252-256 (+2 small edits)

Uses of the API

Choose an available backend before storing a run, persist its endpoint, and stop forwarding the client's token to WES instances for submission, tracking, and cancellation.

  • pro_wes/ga4gh/wes/workflow_runs.py L114-117 (+5 small edits)
  • pro_wes/tasks/track_run_progress.py L57-58, L98-100

Implementation

Register the WES backend API type and adapt FOCA's backend list to expand configured or discovered instances, filter self-references, and select the first available endpoint.

  • pro_wes/ga4gh/wes/backends.py L1-169

Run the backend self-forwarding and registry-public-URL checks during application startup.

  • pro_wes/app.py L16-75 (5 small edits)

Build valid WES API URLs for empty base paths and reject redirects from WES instances.

  • pro_wes/ga4gh/wes/client_wes.py L48-58

Configuration

Provide Helm values examples and deployment instructions for setting backend lists and the public URL.

  • deployment/values.yaml L26-35

Configure the smoke-test fake WES as a backend and remove the alias for the former hard-coded destination.

  • tests/smoke/compose.yaml L11-15, L72 (removed lines)
  • tests/smoke/config.yaml L2-13

Documentation

Document backend configuration, registry discovery, the 503 behavior, deployment setup, upgrading, and the updated development and reference guidance.

  • docs/api.md L24, L74-76, L153
  • docs/configuration.md L23, L31-134
  • docs/deployment.md L142-168
  • docs/development.md L136-139, L245-250
  • docs/getting-started.md L27-54
  • docs/index.md L48-51
  • docs/reference.md L30-32
  • docs/upgrading.md L34-61

Tests

Exercise backend configuration, discovery, selection, startup safeguards, no-backend errors, persisted endpoints, and token handling.

  • tests/conftest.py L4-9, L50-52, L92-95
  • tests/ga4gh/wes/test_backends.py L1-468
  • tests/ga4gh/wes/test_client_wes.py L13, L240-242, L250-260
  • tests/ga4gh/wes/test_error_responses.py L289-297
  • tests/ga4gh/wes/test_spec.py L129-131
  • tests/tasks/test_track_run_progress.py L170-195
  • tests/test_chart.py L23, L267-281

Update smoke-test fixture documentation and certificates to match the configured fake WES hostname.

  • tests/smoke/fake_wes.py L14-22, L55-57

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

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2e13a3f) to head (9184ffa).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #173   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        19    +1     
  Lines          861       942   +81     
=========================================
+ Hits           861       942   +81     

☔ 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 18, 2026 14:57
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 9184ffa

#118 feat: configure WES backends · 3 of 6 met

# Requirement Status Notes
1 Configure WES backends by URL and API path, with service-registry discovery and an optional credentials reference. 🟡 Partly met Configured WES instances and service registries are supported, but authentication is restricted to auth: none; there is no credentials-reference option.
2 Use the first available backend without plugins, and let the plugin pipeline choose and order backends when present. 🟡 Partly met Runs go to the first expanded backend; plugin selection and ordering are deferred to #121.
3 Remove the hard-coded WES, default to no backend, and refuse runs with a clear error when none is available. ✅ Met The default backend list is empty, and POST /runs returns a declared 503 before storing a run when no backend is available.
4 Use FOCA's guarded HTTP client for outbound requests, with TLS verification and timeouts. 🟡 Partly met Registry discovery uses FOCA's guarded client, but requests to WES instances still use requests; TLS verification and timeouts are configured, but the guarded client is deferred.
5 Test configuration validation, discovery, and selection, and use a configured fake WES in the smoke test. ✅ Met The PR adds backend validation, discovery, and selection tests and configures the smoke-test fake WES as a backend.
6 Document backends in configuration and provide an upgrade note for operators. ✅ Met The configuration guide describes backend setup and discovery, and the upgrade guide explains the breaking configuration change.

@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/backends.py" line_range="107-113" />
<code_context>
+    """
+    backend_list = get_backend_list()
+    public_url = backend_list.public_url
+    if public_url is None:
+        if backend_list.has_registries():
+            raise ValueError(
+                "Backend lists with registry entries need the public URL of"
+                " proWES (`server.public_url`)"
+            )
+        return
+    for entry in backend_list.entries:
+        if not isinstance(entry, WesServiceEntry):
</code_context>
<issue_to_address>
**Runs recursively target proWES**

When `server.public_url` is unset and a configured WES URL points to this proWES deployment, `check_backends` returns before checking the configured WES instance, so `select_backend` can select proWES itself; forwarded `POST /runs` requests create more runs and forward them again, exhausting app resources.

Check configured WES instances even when `server.public_url` is unset, and reject endpoints that point back to this deployment.
</issue_to_address>

### Comment 2
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="234" />
<code_context>
             None,
             {
-                "jwt": kwargs.get("jwt"),
+                "jwt": None,
                 "remote_host": updated_document_stored.wes_endpoint.host,
                 "remote_base_path": updated_document_stored.wes_endpoint.base_path,
</code_context>
<issue_to_address>
**Client tokens reach remote WES**

When a progress task queued by the previous version with a nonempty client JWT is consumed by a new worker, `task__track_run_progress` passes its serialized `jwt` argument to `WesClient`, which sends it as an Authorization header to the stored WES endpoint, disclosing the client token after upgrade.

Make `task__track_run_progress` ignore the queued client JWT and never forward it to the stored WES endpoint.
</issue_to_address>

### Comment 3
<location path="pro_wes/ga4gh/wes/backends.py" line_range="169" />
<code_context>
+            "No WES instance available; configure `custom.wes.backends`"
+        )
+    backend = backends[0]
+    return backend.url, api_path(backend, backend_list)
</code_context>
<issue_to_address>
**Redirects reach private services**

When a registry-listed WES endpoint responds with a 307 or 308 redirect to an internal URL, `select_backend` returns the registry-listed endpoint, and `WesClient`'s default-following `requests.Session.post` repeats the run request after a 307/308 redirect. The remote service can therefore make proWES issue requests to private services.

Disable redirects for WES requests, or validate every redirect target with the same address and redirect protections used for registry requests.
</issue_to_address>

### Comment 4
<location path="pro_wes/ga4gh/wes/client_wes.py" line_range="48-51" />
<code_context>
     ) -> None:
         """Class constructor."""
-        self.url = f"{host.rstrip('/')}/{base_path.strip('/')}"
+        # without the separator for an empty base path (the API at `host`)
+        self.url = "/".join(
+            part for part in (host.rstrip("/"), base_path.strip("/")) if part
+        )
         self.set_token(token)
         self.session = requests.Session()
</code_context>
<issue_to_address>
**WES calls bypass guarded client**

The issue asks to use FOCA's guarded HTTP client for outbound requests. Registry discovery does so, but WES API calls continue through `requests`.
</issue_to_address>

### Comment 5
<location path="pro_wes/config_models.py" line_range="54" />
<code_context>
+    # Narrower than the fields of FOCA's entry (TES instances, credentials);
+    # the type is that of the API type of `pro_wes.ga4gh.wes.backends.WES_API`
+    type: Literal["ga4gh-wes"]  # type: ignore[assignment]
+    auth: Literal["none"] = "none"
+    api_path: str = DEFAULT_API_PATH
+
</code_context>
<issue_to_address>
**Credentials reference unsupported**

The issue asks for an optional credentials reference on WES backends. The change restricts `auth` to `none`, so deployments cannot configure a reference.
</issue_to_address>

### Comment 6
<location path="pro_wes/ga4gh/wes/backends.py" line_range="163-168" />
<code_context>
+            none is configured, or the registries list none (yet).
+    """
+    backend_list = get_backend_list()
+    backends = backend_list.expand()
+    if not backends:
+        raise NoBackendAvailable(
+            "No WES instance available; configure `custom.wes.backends`"
+        )
+    backend = backends[0]
+    return backend.url, api_path(backend, backend_list)
</code_context>
<issue_to_address>
**Plugin backend selection absent**

The issue asks for plugins to choose and order backends when the plugin pipeline is used. The change always selects the first expanded backend instead.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 6 findings to address first, and if a configured backend or registry resolves to an unintended WES, run requests and workflow attachments can be sent there; reverting stops future forwarding but cannot recall data already disclosed. The change also stops forwarding client tokens, which changes how authenticated requests reach WES instances.

Blocking findings: pro_wes/ga4gh/wes/backends.py:113, pro_wes/ga4gh/wes/workflow_runs.py:234, pro_wes/ga4gh/wes/backends.py:169, pro_wes/ga4gh/wes/client_wes.py:51, pro_wes/config_models.py:54, and 1 more


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

Comment thread pro_wes/ga4gh/wes/backends.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/backends.py Resolved
Comment thread pro_wes/ga4gh/wes/client_wes.py Resolved
Comment thread pro_wes/config_models.py Resolved
Comment thread pro_wes/ga4gh/wes/backends.py Resolved
Sourcery review fixes: WES clients don't follow redirects (e.g., of a
discovered WES instance to an internal service), and the tracking task
ignores client tokens of tasks queued by earlier versions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg mentioned this pull request Nov 18, 2026
3 tasks
@uniqueg
uniqueg merged commit f4a99d9 into dev Nov 18, 2026
30 checks passed
@uniqueg
uniqueg deleted the feat/118-wes-backends branch November 18, 2026 16:09
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: configure WES backends

1 participant