Skip to content

feat!: adapt tasks to TES versions of backends - #403

Merged
uniqueg merged 2 commits into
feat/tes-1.1from
feat/tes-adapters
Nov 3, 2026
Merged

uniqueg merged 2 commits into
feat/tes-1.1from
feat/tes-adapters

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Refs #394 (closed by the final PR from feat/tes-1.1 into dev, with the other children of #241).

Summary

proTES now adapts tasks to the TES version of each backend, with a chain of adapters in pro_tes/ga4gh/tes/versions.py (a 1.1 to 1.0 adapter for now).

  • Before routing: eligible_backends removes backends that can't run a task unchanged: ignore_error: true, strict backend_parameters and wildcards in output paths can't be expressed in TES 1.0. If none is left: 400 Bad Request, nothing stored; also if the client's selection leaves only such backends. If backends didn't answer so far: 503, as retrying may help.
  • At the relay: relayed_task downgrades the task per backend, after the forward phase and credential stripping. Fields that TES 1.0 can drop are dropped (streamable, path_prefix, non-strict backend_parameters, ignore_error: false). The stored task keeps them; tes_endpoint.tes_version records the version it was relayed in.
  • Reading tasks: TesClient.get_task upgrades them, so the tracker needs no adapters and a live relay (proTES 0.6.0) can share this.
  • Service info: tesResources_backend_parameters is the union of what was read so far, from the cache only (no network on the public endpoint). A configured value wins.
  • Plugins get tasks in TES 1.1 and rank only eligible backends. A proTES as a backend of another proTES works: it reports TES 1.1, and if its 400 comes, the next backend is tried.

Docs: docs/tes-versions.md (new), docs/api.md, docs/configuration.md, docs/upgrading.md.

Operators: Funnel needs the label tes.version: "1.1", as it reports its own version; registries with both versions need one entry per version, with a label.

Verification

  • ruff check, ruff format --check, mypy, ast-grep scan: pass.
  • coverage run -m pytest without the chart tests: 1281 passed, 11 skipped (need a real MongoDB or Docker), 2 deselected; coverage 100%. After the last fix (wildcards), only test_versions.py and test_backend_versions.py ran again here.
  • ci.yml doesn't run on PRs into feat/tes-1.1, so these checks ran locally; the chart, docs, smoke and image jobs run on the final PR into dev.
  • adversarial-reviewer (2 rounds) and quality-reviewer. Fixed: a failed re-read replaced a known version (high); valid tasks got 400 if backends were cold or unreachable (now 503); an unavailable backend could keep others from being read; get_task read the service info; a failure could undo a concurrent read; answers without a version lost their parameters; tasks with an unknown outcome lacked tes_version.

Declined review findings

  • A plugin that empties the route after backends were filtered gets 400, not 503 (quality, medium): the same path serves the decided case of a client selection that leaves only ineligible backends; telling the two apart needs knowledge of what plugins do.

  • The probe in _forward uses the forward budget if backends are unreachable (adversarial, medium): a cold cache only, at most once a minute per process, and a healthy backend answers at once. Limiting it would silently drop fields for a healthy TES 1.1 backend, which is worse. Documented in docs/configuration.md.

  • tes_endpoint.tes_version has no reader (quality, medium): it's for operators who investigate tasks, as dropped fields aren't recorded per task.

  • Hard-coded URL of the problem type, reason codes not in the docs (quality, medium): no shared constant in pro_tes, and no reason code is documented so far.

  • A cold backend that the client didn't select turns a 400 into a 503 (adversarial, low): rare; the selection runs inside the route phase of the plugin engine, which this check can't see into.

  • backend_version wrapper, floats such as 1.10 parsed as 1.1 (quality, low): harmless today.

  • Sourcery: probes in the forward budget (see above); out-of-order successful probes (only within seconds, corrected by the next read); 5 seconds per phase, not in total (docs corrected); keys that a backend stops listing disappear (intended, docs corrected). Fixed: an unmatched [ isn't a wildcard.

Open questions

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG

Add version adapters with a 1.1 to 1.0 adapter. Filter backends before
routing, so tasks that TES 1.0 can't express go only to TES 1.1
backends (400 if none is left), and downgrade tasks per backend after
the forward phase. Fetched tasks are upgraded in TesClient.get_task, so
that the tracker and a later live relay share it.

Refs #394

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@uniqueg
uniqueg marked this pull request as ready for review November 3, 2026 07:30
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR makes proTES TES 1.1-canonical while adapting tasks per backend TES version through a chained adapter system, adding version-aware eligibility and routing, preserving canonical stored tasks, upgrading backend reads, recording relay versions, and documenting and testing the resulting behavior.

Sequence diagram for version-aware task submission

sequenceDiagram
    actor Client
    participant ProTES
    participant Versions as BackendVersions
    participant Plugin as Route plugins
    participant Backend as TES backend

    Client->>ProTES: POST /tasks
    ProTES->>Versions: eligible_backends(task, backends)
    Versions->>Backend: service_info()
    Backend-->>Versions: TES version
    Versions-->>ProTES: Eligible backends
    ProTES->>Plugin: route(eligible backends)
    Plugin-->>ProTES: Ranked backend
    ProTES->>ProTES: Store canonical TES 1.1 task
    ProTES->>ProTES: backend_version(backend)
    ProTES->>ProTES: relayed_task(payload, prefix, version)
    ProTES->>Backend: forward(downgraded task)
    Backend-->>ProTES: Accepted or rejected
    ProTES-->>Client: Task response
Loading

Flow diagram for TES backend eligibility and adaptation

flowchart TD
    Start[Canonical TES 1.1 task] --> Check["incompatibilities(task, backend version)"]
    Check -->|Incompatible| Eligible{Any eligible backend?}
    Check -->|Compatible| Route[Route among backend]
    Eligible -->|No, versions confirmed| BadRequest[400 Bad Request; task not stored]
    Eligible -->|Unknown or unavailable backend| Unavailable[503 Service Unavailable]
    Eligible -->|Yes| Route
    Route --> Relay["relayed_task(payload, prefix, version)"]
    Relay --> Downgrade["downgrade_task(task, version)"]
    Downgrade --> Forward[Forward backend-specific task]
    Forward --> Record[Record tes_endpoint.tes_version]
Loading

File-Level Changes

Change Details Files
Introduces a version-adapter framework that canonicalizes stored/client tasks as TES 1.1 while converting tasks for older backends.
  • Adds adjacent-version adapter abstractions and a TES 1.1-to-1.0 adapter chain.
  • Detects incompatible TES 1.1 features before routing and strips or defaults fields during downgrade.
  • Upgrades tasks read from older backends before returning them.
pro_tes/ga4gh/tes/versions.py
pro_tes/ga4gh/tes/backends.py
pro_tes/gateway.py
Makes backend discovery, routing, and forwarding TES-version aware.
  • Reads and caches backend TES versions and supported backend parameters, honoring explicit labels and preserving known data across probe failures.
  • Routes plugins only across eligible backends and distinguishes confirmed incompatibility with 400 from unavailable backends with 503.
  • Adapts each forwarded task after forward-phase changes and records the relay TES version in task provenance.
pro_tes/ga4gh/tes/backends.py
pro_tes/ga4gh/tes/task_runs.py
pro_tes/ga4gh/tes/models.py
pro_tes/exceptions.py
Documents TES-version behavior and operator configuration.
  • Documents eligibility rules, downgrade behavior, service-info parameter aggregation, adapter extension points, and error semantics.
  • Adds operator guidance for backend version labels, including Funnel, plus timeout and upgrade notes.
  • Adds the new TES versions page to the documentation navigation.
docs/tes-versions.md
docs/api.md
docs/configuration.md
docs/upgrading.md
mkdocs.yml
pro_tes/config.yaml
Adds coverage for adapter behavior, version probing, routing outcomes, task relay transformations, and service-info reporting.
  • Tests canonical downgrade/upgrade behavior and incompatible task features.
  • Tests bounded backend probing, cached version preservation, eligibility filtering, and 400/503 routing decisions.
  • Tests older-backend payloads, stored task preservation, provenance version recording, and aggregated backend parameters.
tests/ga4gh/tes/conftest.py
tests/ga4gh/tes/test_backend_list.py
tests/ga4gh/tes/test_backend_versions.py
tests/ga4gh/tes/test_backends.py
tests/ga4gh/tes/test_server.py
tests/ga4gh/tes/test_versions.py

Possibly linked issues

  • feat(api): implement TES 1.1 #241: The PR implements the issue’s requested version adapters, compatibility-based routing, per-backend downgrades, fetched-task upgrades, service-info parameters, and docs.

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

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35605308 | 📁 Comparing d6626de against latest (ed55e4c)

  🔍 Preview build  

7 files changed · + 1 added · ± 6 modified

+ Added

± Modified

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

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

## Individual Comments

### Comment 1
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="472" />
<code_context>
             db_document.tes_endpoint = TesEndpoint(host=tes_url)
-            # checked by `check_outbound` before the attempt
-            task = relayed_task(attempt.outbound.payload, prefix=prefix)
+            version = backend_version(attempt.backend)
             try:
+                # checked by `check_outbound` before the attempt, but not
</code_context>
<issue_to_address>
**Backend probes exceed request timeout**

When the version cache is cold or expired, a task needs no eligibility filtering, and multiple backends do not answer service-info requests, `backend_version` can spend the full service-info probe timeout before the attempt’s `try` block; the remaining-time limit is passed only later to `cli.forward`. For ordinary tasks, `eligible_backends` skips probing, so several unavailable backends can make the request exceed `forward_timeout` and the proxy timeout, leaving the caller with a timeout despite subsequent forwarding attempts.

Include service-info probes in the same overall forwarding deadline, or avoid blocking probes in the forwarding path.
</issue_to_address>

### Comment 2
<location path="pro_tes/ga4gh/tes/backends.py" line_range="1109" />
<code_context>
-        if probe and (cached is None or time.monotonic() >= cached[1]):
+        if probe and (cached is None or time.monotonic() >= cached.expires_at):
             cached = self._probe(backend)
             self._cache[backend.url] = cached
-        return (cached[0] if cached is not None else None) or OLDEST
+        return (cached.version if cached is not None else None) or OLDEST
</code_context>
<issue_to_address>
**Stale probes replace newer results**

When overlapping probes for the same backend URL complete out of order, the unconditional `_cache[backend.url]` assignment lets an older or failed probe replace a newer successful result, so later routing uses stale version or parameter data and can reject a runnable task, send it to an incapable backend, or report `503`.

Only store a probe result if the cache has not changed since that probe began.

Also at `pro_tes/ga4gh/tes/backends.py:1182`.
</issue_to_address>

### Comment 3
<location path="pro_tes/ga4gh/tes/versions.py" line_range="179" />
<code_context>
+                )
+            )
+        for index, output in _items(task, "outputs"):
+            if _WILDCARDS.search(str(output.get("path"))):
+                found.append(
+                    Incompatibility(
</code_context>
<issue_to_address>
**Valid literal paths get rejected**

When an output path contains an unmatched literal `[` and only TES 1.0 backends are eligible, `_WILDCARDS.search` treats the unmatched bracket as a wildcard, so `incompatibilities` excludes TES 1.0 backends and returns `400 Bad Request` for a task they can run.

Treat `[` as a wildcard only when it begins a valid bracket expression.
</issue_to_address>

### Comment 4
<location path="pro_tes/ga4gh/tes/backends.py" line_range="1168" />
<code_context>
         try:
-            version = reported_version(
-                client_for(backend, timeout=PROBE_TIMEOUT).service_info()
+            service_info = client_for(backend, timeout=PROBE_TIMEOUT).service_info()
+            version = reported_version(service_info)
+            listed: Any = (
</code_context>
<issue_to_address>
**Version probes exceed their timeout**

When a cold version probe to a configured backend spends close to the timeout connecting and then close to the timeout waiting for a response, `client_for` applies `PROBE_TIMEOUT` as both the connect and read timeout for configured backends, not as a total deadline. A probe can therefore take nearly 10 seconds, stalling task creation longer than the documented five-second probe limit.

Enforce a five-second end-to-end probe deadline, including both connection and response time.
</issue_to_address>

### Comment 5
<location path="pro_tes/ga4gh/tes/backends.py" line_range="1206" />
<code_context>
+        return _Probe(
+            version,
+            time.monotonic() + get_custom_config(CustomConfig).tes.version_cache_ttl,
+            parameters,
+        )

</code_context>
<issue_to_address>
**Previously listed parameters disappear**

When a backend's advertised parameter list changes between service-info probes, such as after a backend configuration change, a successful refresh replaces the cached parameter list with only the latest service-info response, and `parameters()` unions only the current cache entries. A key reported before the refresh therefore disappears from proTES service info, contrary to the documented union of keys read so far; clients can stop seeing a parameter that proTES previously advertised.

Accumulate previously observed parameter keys separately from the replaceable version-probe cache, or otherwise retain the documented historical union.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and a faulty compatibility check or downgrade could send a task to a TES 1.0 backend with different execution semantics—for example, treating a wildcard output path literally. If the backend runs it and produces side effects, reverting the code will not undo them.

Blocking findings: pro_tes/ga4gh/tes/task_runs.py:472, pro_tes/ga4gh/tes/backends.py:1109, pro_tes/ga4gh/tes/versions.py:179, pro_tes/ga4gh/tes/backends.py:1168, pro_tes/ga4gh/tes/backends.py:1206


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

Comment thread pro_tes/ga4gh/tes/task_runs.py Resolved
Comment thread pro_tes/ga4gh/tes/backends.py Resolved
Comment thread pro_tes/ga4gh/tes/versions.py Resolved
Comment thread pro_tes/ga4gh/tes/backends.py Resolved
Comment thread pro_tes/ga4gh/tes/backends.py Resolved
An unmatched bracket in an output path is literal, also for TES 1.1, so
such tasks can go to TES 1.0. Say in the docs what the timeouts of
service info requests are, and where the backend parameters come from.

Refs #394

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@uniqueg
uniqueg merged commit 54b9631 into feat/tes-1.1 Nov 3, 2026
2 checks passed
@uniqueg
uniqueg deleted the feat/tes-adapters branch November 3, 2026 07:37
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.

1 participant