Skip to content

feat(wes/routing): route runs by workflow type - #92

Merged
uniqueg merged 5 commits into
devfrom
feat/86-wes-routing-workflow-type
Nov 17, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/86-wes-routing-workflow-type

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the plugin wes.routing.workflow-type (foca-plugin-wes-routing-workflow-type, subgroup wes/routing), for WES gateways such as proWES (elixir-cloud-aai/prowes#121).

  • route: keeps the candidates whose service info lists the run's workflow_type (ignoring case) and workflow_type_version (exactly), and workflow_engine/workflow_engine_version if the run sets them (WES 1.1 objects and WES 1.0 version strings), in their order. Types or engines listed without versions support any version.
  • Service infos come through ctx.http (guarded: https, public addresses, no redirects, no credentials) from <Backend.url><service_info_path> (default /ga4gh/wes/v1/service-info), and are cached per process: cache_ttl 300 s, failures failure_ttl 30 s, cache_size 1000. No plugin store, so it works without a database, as proWES needs.
  • Time and size limits: each request gets request_timeout (2 s), and the step keeps RESERVE (0.25 s) before its deadline, because the engine discards results that arrive later. Requests cut short by the step's time are skipped, not cached. Service infos are capped at max_size (256 KiB) and at 256 types/engines and 1024 versions, so that neither parsing nor the cache grows with what a backend sends.
  • unreadable: keep | drop decides what happens to backends whose service info can't be read.
  • Runs that no readable candidate supports are rejected with 422; the detail names the fields, not their values. If candidates are missing only because unreadable ones were dropped, the route is empty instead, and the gateway answers 503.
  • Annotations are counts only: candidates, kept, unsupported, unreadable, skipped, fetched, cache_hits.
  • Requires foca>=0.22.1.dev0,<0.24, like the other wes plugins. FOCA 0.19–0.22 can't run WES requests through the engine: the test kit fails with Pass the tags of wes requests: start(tags=). The run request shape is the one of foca.plugins.wes (foca#782).
  • Docs: the plugin README (behaviour, cache, requests, configuration, FOCA versions) and CHANGELOG. Also updated: the repo README status, docs/installing.md, docs/writing-plugins.md, plugins/wes/README.md, and the root pyproject.toml comment.

Reuse across gateways: the matched fields exist only in WES service infos, so the plugin is WES-specific; TES service infos list no workflow types. If a TES router by service info comes along, service_info.py (fetch and TTL cache) could become a shared module (tests/test_shared_modules.py).

Verification

  • Plugin tests: coverage run --source plugins/wes/routing/workflow-type/src -m pytest plugins/wes/routing/workflow-type → 110 passed, coverage 100 %. This includes FOCA's contract checks, harness and PluginHost tests, a test that loads the README configuration, and an engine test with a slow local backend that checks the route stands before the step's deadline.
  • ruff check, ruff format --check, ast-grep scan, python -m scripts.packages mypy → clean.
  • pre-commit run --all-files → all hooks pass except actionlint. It fails locally only because the local shellcheck shim has no version set; no workflow is changed.
  • Repo tests: coverage run --source scripts,docs -m pytest tests → 152 passed, 100 %.
  • mkdocs build --strict → builds, and the catalogue lists the plugin. uv build --all-packages plus python -m scripts.checks dist dist → pass. uv lock → up to date.
  • Reviews: two rounds of the adversarial and quality reviewers. Their findings were fixed:
    • the step deadline vs. the engine discarding late results;
    • unbounded parsing and cache size;
    • fetched counting;
    • dot segments in service_info_path;
    • doc wording.
  • Sourcery review: fixed in 72ce882 (version strings only for engines, null version lists skipped, too deeply nested JSON unreadable, tighter caps and cache_size at most 10000). All 7 threads are answered and resolved.
  • CI (72ce882): all 135 checks passed, including CI passed, the plugin's test matrix (Python 3.11/3.13/3.15; the FOCA release entries skip, as the plugin requires FOCA dev), Codecov and Read the Docs.

Declined review findings

  • Split the parser and cache tests into tests/test_service_info.py (low, optional). All tests are in one module, as in generic.routing.random; I can split if preferred.
  • Inject the cache clock instead of setting plugin.runtime.cache._clock in two tests (low). It's a test-only seam on an internal object; adding a constructor option only for tests isn't worth it.
  • A test that the guarded client refuses http:// and private-address backends (low). That is FOCA's guarantee (GuardedClient), tested in FOCA; the plugin only documents it.
  • Sourcery: parse an array-of-objects version format (high). The WES spec defines both version fields as objects keyed by type or engine, and that is what is parsed.
  • Sourcery: keep an older in-flight fetch from overwriting a newer cache entry (medium). Both results are equally fresh within the cache's TTL window.
  • Sourcery: treat workflow_engine_versions: null as unreadable (medium). It means the same as the missing optional field (no engine), so engine-specific runs aren't sent to backends that name no engine.

Open questions

None.

Closes #86

🤖 Generated with Claude Code

uniqueg and others added 3 commits November 17, 2026 20:25
Add the plugin `wes.routing.workflow-type`: in the `route` phase, keep
the candidate backends whose WES service info lists the run's
`workflow_type` and `workflow_type_version`, and its `workflow_engine`
and `workflow_engine_version` if the run sets them, in their order.

Service infos are fetched with `ctx.http` and cached per process, with
TTLs for supports and for failures; no plugin store, so the plugin
works in gateways without a database (proWES). Backends whose service
info can't be read are kept or dropped (`unreadable`). Runs that no
readable candidate supports are rejected with 422.

Needs FOCA's WES run requests, so it requires FOCA's `dev` branch like
the other `wes` plugins.

Closes #86

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review findings on `wes.routing.workflow-type`:

- Bound each service info request by `request_timeout` (default 2 s)
  and stop 0.25 s (`RESERVE`) before the step's deadline, as the engine
  discards results that come later. Timeouts cut short by the step's
  time skip the backend without caching it; a test runs a slow local
  backend through the engine.
- Count `fetched` only for requests that were answered or failed.
- Treat service infos with more than 256 types or engines, or more
  than 1024 versions, as unreadable; leave out names and versions over
  256 characters, so that no backend makes the cache large.
- Refuse `.` and `..` segments in `service_info_path`.
- Document the HTTP client requirement and name the example plugins in
  the docs on unreleased FOCA features.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address the second review round of `wes.routing.workflow-type`:

- Refuse service infos larger than `max_size` (default 256 KiB, at
  most the gateway's limit) before parsing, so that parsing can't take
  up the step's time and make the engine discard the route.
- Cache timeouts as failures when the request had at least half of
  `request_timeout`, so that a step shorter than `request_timeout`
  doesn't retry a backend that never answers on every run.
- Export `RESERVE`, clarify the version limit per field, and drop the
  wall-clock assertion of the engine test.

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

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the run requirements, parsed backend support model, bounded service-info parsing, and per-process TTL/LRU cache that routing depends on.

  • plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py L1-347

API

Expose the WES-only routing plugin, its validated configuration, route hook, annotations, failure handling, and packaging entry point.

  • plugins/wes/routing/workflow-type/pyproject.toml L1-67
  • plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/__init__.py L1-325

Configuration

Point the workspace dependency resolution at FOCA dev for the new WES plugin’s unreleased run-request API.

  • pyproject.toml L23-29

Documentation

Document plugin behavior, limits, cache, HTTP requirements, configuration, compatibility, and release status across the plugin and repository guides.

  • README.md L48-49
  • docs/installing.md L37-39
  • docs/writing-plugins.md L159-160
  • plugins/wes/README.md L11-13
  • plugins/wes/routing/workflow-type/CHANGELOG.md L1-15
  • plugins/wes/routing/workflow-type/README.md L1-191

Tests

Verify parsing, matching, cache and timeout behavior, plugin contracts, engine routing, and documented configuration.

  • plugins/wes/routing/workflow-type/tests/test_workflow_type.py L1-1052

Lock files and vendored code

Record the new plugin’s resolved dependencies in the workspace lockfile.

  • uv.lock L15, L1342-1356

Other changes

Files not grouped.

  • plugins/wes/routing/workflow-type/LICENSE L1-201

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 17, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 foca-plugins | 🛠️ Build #35970271 | 📁 Comparing 72ce882 against latest (200b5fe)

  🔍 Preview build  

4 files changed
± index.html
± catalogue/index.html
± installing/index.html
± writing-plugins/index.html

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (200b5fe) to head (72ce882).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev       #92    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           18        20     +2     
  Lines         1552      1793   +241     
  Branches       209       245    +36     
==========================================
+ Hits          1552      1793   +241     
Flag Coverage Δ
foca-plugin-generic-example-noop 100.00% <ø> (ø)
foca-plugin-generic-routing-random 100.00% <ø> (ø)
foca-plugin-tes-data-crypt4gh 100.00% <ø> (ø)
foca-plugin-tes-routing-distance 100.00% <ø> (ø)
foca-plugin-wes-routing-workflow-type 100.00% <100.00%> (?)
foca-plugin-wes-workflow-git 100.00% <ø> (ø)
foca-plugin-wes-workflow-trs 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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 17, 2026 23:03
@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 72ce882

#86 feat(wes/routing): route runs by workflow type · 4 of 4 met

# Requirement Status Notes
1 In the route phase, keep candidates supporting the run's workflow type and version, and its engine and engine version if set, in candidate order. ✅ Met The route hook parses the submitted run, matches workflow type and engine names case-insensitively and versions exactly, and preserves candidate order.
2 Cache service info per backend with a TTL. ✅ Met Support is cached by service-info URL with configurable success and failure TTLs.
3 Let configuration decide whether a backend with unreadable service info is kept or dropped. ✅ Met The unreadable setting supports keep and drop; both behaviors are tested.
4 Add the plugin under wes/routing, with tests for the filtering cases and unreadable service info, and a README documenting configuration. ✅ Met The plugin is registered as wes.routing.workflow-type; its tests cover filtering, engines, unreadable service info, and its README documents configuration.

@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 7 issues

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

## Individual Comments

### Comment 1
<location path="plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py" line_range="142" />
<code_context>
+            :py:data:`MAX_ENTRIES` entries or :py:data:`MAX_VERSIONS`
+            versions in all, so that no backend makes the cache large.
+    """
+    if not isinstance(entries, Mapping):
+        raise ServiceInfoError(f"{field}: no object")
+    if len(entries) > MAX_ENTRIES:
</code_context>
<issue_to_address>
**Conforming backends are treated as unreadable**

When a WES backend returns version fields in the standard array-of-objects format, `_versions` rejects those arrays, so `parse_support` treats conforming backends as unreadable. With `unreadable: keep`, they pass through without filtering; with `drop`, supported backends are removed and the route can be empty.

Parse the standard array-of-objects version format instead of rejecting it.

Also at `plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py:253`.
</issue_to_address>

### Comment 2
<location path="plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py" line_range="277" />
<code_context>
+        raise ServiceInfoError(f"status {response.status}")
+    try:
+        info = response.json()
+    except ValueError:
+        raise ServiceInfoError("no valid JSON") from None
+    return parse_support(info)
</code_context>
<issue_to_address>
**Deeply nested responses fail routing**

When a backend returns JSON nested deeply enough to exceed Python's decoder recursion limit while remaining within the response-size limit, `response.json()` raises `RecursionError`, which `fetch_support` does not translate to `ServiceInfoError`; `_support` catches only `HttpError` and `ServiceInfoError`, so the exception escapes instead of applying the unreadable behavior and the route fails.

Catch `RecursionError` from `response.json()` and translate it to `ServiceInfoError`.
</issue_to_address>

### Comment 3
<location path="plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/__init__.py" line_range="278" />
<code_context>
+            _failed(backend, url, exc, runtime, ctx, counts)
+        else:
+            counts.fetched += 1
+            runtime.cache.put(url, support, settings.cache_ttl)
+    if support is None:
+        counts.unreadable += 1
</code_context>
<issue_to_address>
**Stale results overwrite newer support**

When two route calls miss the same backend URL concurrently and the earlier fetch finishes after the later fetch, `SupportCache.put` serializes assignments but not fetch order, so the late write overwrites the newer result; subsequent runs use stale capabilities or treat a readable backend as unreadable.

Prevent an older in-flight fetch from overwriting a newer cache result.

Also at `plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py:337`.
</issue_to_address>

### Comment 4
<location path="plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py" line_range="153-154" />
<code_context>
+        if not isinstance(name, str) or len(name) > MAX_LENGTH:
+            continue
+        listed: Versions
+        if isinstance(entry, str):
+            values: object = [entry]
+        elif isinstance(entry, Mapping):
+            values = entry.get(key)
</code_context>
<issue_to_address>
**Malformed entries are accepted as support**

When a backend returns a string-valued `workflow_type_versions` entry, `_versions` converts the string into a version list, so `parse_support` caches the malformed entry as support and the router can send a matching run to a backend whose type entry has an unsupported shape.

Reject string entries instead of treating them as version lists.
</issue_to_address>

### Comment 5
<location path="plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py" line_range="249-252" />
<code_context>
+        raise ServiceInfoError(f"{TYPE_VERSIONS}: missing")
+    types = _versions(info[TYPE_VERSIONS], "workflow_type_version", TYPE_VERSIONS)
+    engines_field = info.get(ENGINE_VERSIONS)
+    engines = (
+        {}
+        if engines_field is None
+        else _versions(engines_field, "workflow_engine_version", ENGINE_VERSIONS)
+    )
+    return Support(types=types, engines=engines)
</code_context>
<issue_to_address>
**Null engine fields reject runs**

When a backend returns `workflow_engine_versions: null` and a run specifies a workflow engine, `parse_support` treats the explicit null as an absent field, so `Support.supports` marks the run unsupported instead of applying the configured unreadable behavior; with `unreadable: keep`, the gateway can reject the run with 422.

Treat an explicit null engine-version field as unreadable rather than as an absent field.
</issue_to_address>

### Comment 6
<location path="plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py" line_range="159-160" />
<code_context>
+            values = entry.get(key)
+        else:
+            continue
+        if values is None or values == []:
+            listed = None
+        elif isinstance(values, list):
+            total += len(values)
</code_context>
<issue_to_address>
**Malformed version lists allow unsupported runs**

When a backend returns `{"workflow_type_versions":{"CWL":{"workflow_type_version":null}}}` and a run requests a CWL version, a service-info entry has a version field explicitly set to JSON `null`, so `_versions` treats it as an omitted version list and `Support.supports` accepts any version for that type or engine; the run is routed to a backend whose service info did not list that support.

Treat an explicitly null version field as an invalid entry, while retaining wildcard behavior only for a missing field or an empty list.
</issue_to_address>

### Comment 7
<location path="plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/__init__.py" line_range="86" />
<code_context>
+    unreadable: Literal["keep", "drop"] = "keep"
+    cache_ttl: int = Field(default=300, ge=0, le=86400)
+    failure_ttl: int = Field(default=30, ge=0, le=86400)
+    cache_size: int = Field(default=1000, ge=0, le=100_000)
+    request_timeout: float = Field(default=2.0, gt=0, le=60)
+    max_size: int = Field(default=256 * 1024, ge=1024, le=16 * 1024 * 1024)
</code_context>
<issue_to_address>
**Valid cache settings exhaust memory**

When an operator configures large cache and response-size limits and many backends return service infos near the parser's entry and version limits, `cache_size` and `max_size` can both be configured near their allowed maxima, while each cached support entry retains parsed names and versions and the LRU limit counts entries rather than bytes. A sufficiently large cache of full-sized service infos exhausts process memory and takes down the gateway.

Enforce an aggregate cache memory budget or tighten the accepted cache and per-entry limits to keep the maximum retained memory practical.

Also at `plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/__init__.py:88`, `plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py:339`.
</issue_to_address>

Sourcery assessment

Approval pending. 7 findings to address first.

Blocking findings: plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py:142, plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py:277, plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/__init__.py:278, plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py:154, plugins/wes/routing/workflow-type/src/foca_plugins/wes/routing/workflow_type/service_info.py:252, and 2 more


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

Address the Sourcery review of #92:

- Version strings count only for engines (WES 1.0), not for workflow
  types; a version list set to null is skipped, not a wildcard.
- JSON nested too deeply counts as unreadable instead of failing the
  route.
- Lower the caps (256 versions, 64 characters) and the maximum
  cache_size (10000), so that a cached backend holds at most about
  64 KiB of names and versions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 174a8f0 into dev Nov 17, 2026
361 checks passed
@uniqueg
uniqueg deleted the feat/86-wes-routing-workflow-type branch November 17, 2026 23:41
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(wes/routing): route runs by workflow type

1 participant