Repository navigation
feat(wes/routing): route runs by workflow type - #92
Conversation
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]>
Reviewer's GuideData structuresDefine the run requirements, parsed backend support model, bounded service-info parsing, and per-process TTL/LRU cache that routing depends on.
APIExpose the WES-only routing plugin, its validated configuration, route hook, annotations, failure handling, and packaging entry point.
ConfigurationPoint the workspace dependency resolution at FOCA dev for the new WES plugin’s unreleased run-request API.
DocumentationDocument plugin behavior, limits, cache, HTTP requirements, configuration, compatibility, and release status across the plugin and repository guides.
TestsVerify parsing, matching, cache and timeout behavior, plugin contracts, engine routing, and documented configuration.
Lock files and vendored codeRecord the new plugin’s resolved dependencies in the workspace lockfile.
Other changesFiles not grouped.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
4 files changed± index.html± catalogue/index.html± installing/index.html± writing-plugins/index.html |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Linked issuesChecked at commit 72ce882 #86 feat(wes/routing): route runs by workflow type · 4 of 4 met
|
There was a problem hiding this comment.
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
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]>
Summary
Adds the plugin
wes.routing.workflow-type(foca-plugin-wes-routing-workflow-type, subgroupwes/routing), for WES gateways such as proWES (elixir-cloud-aai/prowes#121).route: keeps the candidates whose service info lists the run'sworkflow_type(ignoring case) andworkflow_type_version(exactly), andworkflow_engine/workflow_engine_versionif 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.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_ttl300 s, failuresfailure_ttl30 s,cache_size1000. No plugin store, so it works without a database, as proWES needs.request_timeout(2 s), and the step keepsRESERVE(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 atmax_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 | dropdecides what happens to backends whose service info can't be read.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 answers503.candidates,kept,unsupported,unreadable,skipped,fetched,cache_hits.foca>=0.22.1.dev0,<0.24, like the otherwesplugins. FOCA 0.19–0.22 can't run WES requests through the engine: the test kit fails withPass the tags of wes requests: start(tags=). The run request shape is the one offoca.plugins.wes(foca#782).docs/installing.md,docs/writing-plugins.md,plugins/wes/README.md, and the rootpyproject.tomlcomment.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
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 andPluginHosttests, 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 exceptactionlint. It fails locally only because the localshellcheckshim has no version set; no workflow is changed.coverage run --source scripts,docs -m pytest tests→ 152 passed, 100 %.mkdocs build --strict→ builds, and the catalogue lists the plugin.uv build --all-packagespluspython -m scripts.checks dist dist→ pass.uv lock→ up to date.fetchedcounting;service_info_path;nullversion lists skipped, too deeply nested JSON unreadable, tighter caps andcache_sizeat most 10000). All 7 threads are answered and resolved.CI passed, the plugin's test matrix (Python 3.11/3.13/3.15; the FOCA release entries skip, as the plugin requires FOCAdev), Codecov and Read the Docs.Declined review findings
tests/test_service_info.py(low, optional). All tests are in one module, as ingeneric.routing.random; I can split if preferred.plugin.runtime.cache._clockin two tests (low). It's a test-only seam on an internal object; adding a constructor option only for tests isn't worth it.http://and private-address backends (low). That is FOCA's guarantee (GuardedClient), tested in FOCA; the plugin only documents it.workflow_engine_versions: nullas 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