Skip to content

feat: find API paths of discovered TES instances - #451

Merged
uniqueg merged 4 commits into
devfrom
feat/discovered-api-path
Nov 7, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/discovered-api-path

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

As decided in #438: discovered TES instances use the URL that their service registry lists as the base of the TES API; /ga4gh/tes/v1 is appended only if the service info isn't found at that URL.

  • TesClient.api_path is now a property; for discovered TES instances it is read on first use (ApiPaths): GET <url>/service-info through FOCA's guarded client, within PROBE_TIMEOUT (5 s), without credentials unless custom.tes.probe_with_token is set.
  • Answers, as implemented:
    • a TES service info (org.ga4gh tes, any version): the API is at the URL itself, cached for custom.tes.version_cache_ttl;
    • 404/410, or the service info of another GA4GH service: the default path, cached the same;
    • 401/403: the default path (as before), with a hint in the logs, asked again after 60 s;
    • anything else (redirects, 405, 408, 429, 5xx, non-JSON or JSON that isn't a service info, request errors, timeouts, too large): unknown.
  • While the path is unknown, a path settled before is kept, and asked again every 60 s; without one, no request is sent (BackendRequestNotSent, so forwarding tries the next TES instance, tracking retries), and nothing is cached. No path is guessed, as a request to a wrong path could take a task for gone (404 after a cancel).
  • Reading the path while forwarding is bounded by, and takes from, the time left to forward (not at all without time left); the version probe of a discovered TES instance reads below the path found, so its first read takes two requests (documented, tested).
  • FOCA removes /ga4gh/tes/v1 from the URLs that registries list, so for a TES instance listed with it, proTES first tries <host>/service-info, then uses the default path; documented.
  • is_tes() is split out of reported_version(); TesClient.get_service_info() and token_hint() are shared with the version probe.
  • Configured TES instances are unchanged (their api_path, never read).

Docs: configuration reference (API paths, TES versions, discovery, request timing), upgrade notes (To version 0.6.0), access control (credentials of service-info reads), base config comments, config model docstrings, chart README and values.yaml comment. No new setting.

Closes #438

Verification

  • coverage run -m pytest (mongomock, Helm 3.22.1 for the chart tests): 1690 passed, 11 skipped; coverage 100%
  • pytest against MongoDB 7.0.34 (MONGODB_TEST_URI, own mongod --nounixsocket): 1700 passed, 1 skipped
  • ruff 0.17.3 check and format, mypy, ast-grep scan and test, semgrep (.semgrep): pass
  • mkdocs build --strict: pass
  • CI: all checks passed (CI passed, tests on mongomock and MongoDB 7.0, chart, smoke test, docs, image scan)

Review

Full review (adversarial + quality, 2 rounds). Fixed: answers that don't settle the path (redirects, 429, HTML or JSON maintenance pages, transient refusals) were cached as the default path for an hour, which could make tracking take a task for gone; the path read ignored the time left to forward; duplicated service-info request and hint logic; missing tests (403, hints with credentials, probe_with_token refusals and missing tokens, memoisation, retries); docs on TESP, timing and refusals; the log of a refusal named a path that a settled one may override.

Sourcery: fixed, the path read while forwarding is bounded by the time left (not only by PROBE_TIMEOUT); the refusal test with probe_with_token now sends a token; documented that workers of the earlier version can't track tasks at such TES instances during a rolling upgrade.

Lane: full review (request routing to discovered TES instances).

Declined review findings

  • Reusing the first service info for the version (it is read twice the first time per process and TTL): two caches with different lifetimes; documented and tested instead.
  • A short negative cache for unknown answers (every request to such a TES instance reads the service info again): each read is bounded by 5 s and replaces a request that would be sent anyway; caching a failure would delay recovery.
  • A version probe of a discovered TES instance can take two PROBE_TIMEOUTs on a cold cache: documented.
  • Unbounded growth of the path cache: bounded by the URLs the registries list, like the version cache.
  • Sourcery: storing the path per task for workers of the earlier version during a rolling upgrade (self-healing once upgraded workers poll; documented).
  • Sourcery: telling unsent cancels apart from unknown outcomes when the path is unknown (_cancel_at_backend reports every unreached TES instance as an unknown outcome already).

🤖 Generated with Claude Code

Summary by Sourcery

Resolve and safely cache the API paths of discovered TES instances before forwarding requests.

New Features:

  • Discover API paths for TES instances found through service registries, allowing APIs hosted at the registry-listed URL as well as the default TES path.

Bug Fixes:

  • Avoid sending requests to an unverified API path when service-info probing produces an inconclusive result, while preserving previously settled paths during transient failures.

Enhancements:

  • Share service-info handling across API-path and TES-version detection, including credential hints and bounded probe timing.
  • Keep configured TES backends unchanged while applying per-process caching, retries, and forwarding-time limits to discovered backend path detection.

Documentation:

  • Document discovered TES API-path detection, probing credentials, caching, timing, fallback behavior, and rolling-upgrade considerations.

Tests:

  • Add coverage for discovered API-path resolution, fallback and refusal behavior, caching and retries, credential handling, timing limits, version probing, and configured-backend compatibility.

uniqueg and others added 3 commits November 6, 2026 19:26
Take the URL that a registry lists as the base of the TES API if its
service info is there (GET <url>/service-info answers with that of a
TES service); otherwise append /ga4gh/tes/v1, as before. The service
info is read without credentials unless probe_with_token is set, and
cached per process for version_cache_ttl seconds. While it can't be
read, no request is sent and nothing is cached, so tasks go to other
TES instances and are not taken for gone at a wrong path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Take the default path only on 404/410 or another service info; read
again after a minute on 401/403; treat redirects, 429, other errors
and non-JSON pages as unknown, keeping a path settled before for a
minute. Read within PROBE_TIMEOUT and take the time from forwarding.
Share the service-info request and the probe_with_token hint with
the version probe. Document timing and the double first read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Take JSON that isn't a GA4GH service info (e.g., a maintenance page) as
unknown, not as the default path. Don't read the path when no time is
left to forward. Refusals no longer log the default path, which a
settled path may override. Document that refusals keep settled paths,
and extend the BackendRequestNotSent docstring; test refusal retries.

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

sourcery-ai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose the discovered-backend API path through TesClient.api_path and add the service-info request helper; document when path lookup can prevent a request from being sent.

  • pro_tes/exceptions.py L49-52
  • pro_tes/ga4gh/tes/backends.py L651-656, L668-685, L818-843 (+2 small edits)

Implementation

Implement path discovery, caching, answer classification, credential hints, and time-bounded forwarding for discovered TES backends, while retaining the existing version-probe behavior.

  • pro_tes/ga4gh/tes/backends.py L726-740, L1221-1249, L1432-1603 (+5 small edits)

Configuration

Update configuration descriptions to clarify that the existing cache-TTL and credential-probe settings also govern API-path discovery.

  • deployment/values.yaml L60-61
  • pro_tes/config.yaml L345-350
  • pro_tes/config_models.py L378-384, L394-398

Documentation

Explain discovered API-path resolution, its timing, caching, credential behavior, and rolling-upgrade implications across the configuration, access-control, deployment, and upgrade documentation.

  • deployment/README.md L78-79
  • docs/access-control.md L301-302
  • docs/configuration.md L172-180, L185-216 (+4 small edits)
  • docs/upgrading.md L79-93

Tests

Test discovered-path resolution, caching and retries, credentials, unknown answers, forwarding deadlines, version probing, and unchanged configured-backend paths.

  • tests/conftest.py L46, L230-234
  • tests/ga4gh/tes/test_backend_list.py L29-32, L441-448, L683-1095 (+7 small edits)

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

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35713465 | 📁 Comparing 77defc0 against latest (02c3493)

  🔍 Preview build  

5 files changed · ± 5 modified

± Modified

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (02c3493) to head (77defc0).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #451   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines         2719      2799   +80     
=========================================
+ Hits          2719      2799   +80     

☔ 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 7, 2026 03:56

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

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

## Individual Comments

### Comment 1
<location path="pro_tes/ga4gh/tes/backends.py" line_range="652-656" />
<code_context>
-            entry.api_path if isinstance(entry, TesServiceEntry) else DEFAULT_API_PATH
-        )
+        # discovered backends: read on first use
+        self._api_path: str | None = None
+        if isinstance(entry, TesServiceEntry):
+            self._api_path = entry.api_path
+        elif not isinstance(entry, RegistryEntry):
+            self._api_path = DEFAULT_API_PATH
         # discovered backends: each connection is checked
         self.guarded: GuardedClient | None = None
</code_context>
<issue_to_address>
**Old workers poll the wrong path**

When a rolling upgrade lets an old Celery worker poll a task submitted by the new version to a discovered TES instance that serves its API at the registry URL, an old Celery worker uses the previous default API path for a newly submitted discovered TES task whose API is at the registry URL. Its polls fail, and `_poll` stores `UNKNOWN` after the configured consecutive failures even though the remote task is running.

Drain or stop old workers before the new version submits tasks using discovered API paths, or persist the resolved path so old workers can use it.
</issue_to_address>

### Comment 2
<location path="pro_tes/ga4gh/tes/backends.py" line_range="682" />
<code_context>
+            pro_tes.exceptions.BackendAuthError: No credentials are
+                available to read it (`custom.tes.probe_with_token`).
+        """
+        if self._api_path is None:
+            self._api_path = api_paths.get(self)
+        return self._api_path
</code_context>
<issue_to_address>
**Unsent cancellations appear ambiguous**

When a discovered backend's API path cannot be determined during cancellation, `api_paths.get()` raises `BackendRequestNotSent` before `cancel_task` sends its POST, but `_cancel_at_backend` catches it as a generic `requests.RequestException` and raises `BackendOutcomeUnknown`, so callers are told a cancellation may have happened when no request was sent.

Handle `BackendRequestNotSent` separately in `_cancel_at_backend` before catching generic `requests.RequestException`.

Also at `pro_tes/ga4gh/tes/backends.py:683-684`.
</issue_to_address>

### Comment 3
<location path="pro_tes/ga4gh/tes/backends.py" line_range="1548" />
<code_context>
+            url=client.url,
+            backend=client.backend,
+            entry=client.entry,
+            timeout=PROBE_TIMEOUT,
+        )
+        try:
</code_context>
<issue_to_address>
**Path probe exceeds forwarding deadline**

When a discovered backend's API path is not cached and its service-info request takes longer than the time left to forward, `ApiPaths._read` gives its guarded request the full `PROBE_TIMEOUT` instead of the remaining `connect_timeout`, so a slow service-info read can keep forwarding blocked after its deadline; `forward` only checks the remaining time after the read completes.

Pass the remaining forwarding budget into the path probe and bound its guarded request by that budget.
</issue_to_address>

### Comment 4
<location path="tests/ga4gh/tes/test_backend_list.py" line_range="837-839" />
<code_context>
+    caplog: pytest.LogCaptureFixture,
+) -> None:
+    """Refusals of reads with credentials get no hint at reading without."""
+    config = get_custom_config(CustomConfig).tes
+    config.probe_with_token = True
+    discovering.add("a", "https://tes1.example.org")
+    fake_tes.answers["https://tes1.example.org/service-info"] = http.HttpResponse(
+        status=401
</code_context>
<issue_to_address>
**Credentialed refusal goes untested**

When the test is meant to cover a refused service-info read sent with credentials, `test_api_path_discovered_refused_with_token` sets `probe_with_token` but uses the `discovering` fixture's default `auth: none` backend, so the fake 401 is returned without credentials and the no-warning assertion passes without testing a credentialed refusal.

Configure client credentials and a token provider in this test, and assert the 401 request carried the token before checking the log.
</issue_to_address>

Linked issues

#438 feat: API path for discovered TES instances · 1 of 1 met

# Requirement Status Notes
1 Discovered TES instances can use a non-default API path, documented in the configuration reference. ✅ Met For discovered instances, ApiPaths checks <url>/service-info and uses the listed URL as the API base when it identifies a TES service; the configuration reference documents this behavior and its fallback.

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and with probe_with_token enabled, API-path discovery sends proTES’ token in a service-info request to discovered TES instances, including ones tasks may not be routed to. Reverting stops future probes, but cannot undo a token already exposed to an endpoint.

Blocking findings: pro_tes/ga4gh/tes/backends.py:656, pro_tes/ga4gh/tes/backends.py:682, pro_tes/ga4gh/tes/backends.py:1548, tests/ga4gh/tes/test_backend_list.py:839


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

Comment thread pro_tes/ga4gh/tes/backends.py Resolved
Comment thread pro_tes/ga4gh/tes/backends.py Resolved
Comment thread pro_tes/ga4gh/tes/backends.py Resolved
Comment thread tests/ga4gh/tes/test_backend_list.py Resolved
Bound the read of a discovered TES instance's API path while
forwarding by the time left, not only by PROBE_TIMEOUT. Test refusals
of reads with credentials with a token, and note rolling upgrades.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 74b88a6 into dev Nov 7, 2026
41 of 50 checks passed
@uniqueg
uniqueg deleted the feat/discovered-api-path branch November 7, 2026 04:37
@uniqueg uniqueg mentioned this pull request Nov 7, 2026
6 tasks done
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: API path for discovered TES instances

1 participant