Repository navigation
feat!: serve TES 1.1, relay to 1.0 and 1.1 - #405
Conversation
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Reviewer's GuideproTES now serves TES 1.1 as its canonical API and transparently relays tasks across TES 1.0 and 1.1 backends through version detection, eligibility-aware routing, payload adapters, and response normalization, with updated cancellation semantics, filtering, documentation, and mixed-version test coverage. Sequence diagram for version-aware task routing and relaysequenceDiagram
participant Client
participant ProTES
participant VersionCache
participant TES10
participant TES11
Client->>ProTES: POST /tasks with TES 1.1 task
ProTES->>VersionCache: backend_version(backend)
VersionCache->>TES10: GET /ga4gh/tes/v1/service-info
TES10-->>VersionCache: TES 1.0
VersionCache->>TES11: GET /ga4gh/tes/v1/service-info
TES11-->>VersionCache: TES 1.1
ProTES->>ProTES: eligible_backends(task, backends)
ProTES->>TES10: POST /tasks with downgraded task
TES10-->>ProTES: accepted task
ProTES-->>Client: TES 1.1 task identifier
Sequence diagram for cancellation through CANCELINGsequenceDiagram
participant Client
participant ProTES
participant Backend
participant Tracker
Client->>ProTES: POST /tasks/{id}:cancel
ProTES->>Backend: POST /tasks/{remote_id}:cancel
Backend-->>ProTES: Cancellation accepted
ProTES->>ProTES: Store state CANCELING
ProTES-->>Client: Task state CANCELING
Tracker->>Backend: GET /tasks/{remote_id}
alt Backend reports final state
Backend-->>Tracker: Final task state
Tracker->>ProTES: Store final state
else Backend returns 404
Backend-->>Tracker: 404 Not Found
Tracker->>ProTES: Store CANCELED
else Backend unavailable
Backend-->>Tracker: Request failure
Tracker->>ProTES: Keep CANCELING
end
Flow diagram for TES task adaptation and eligibilityflowchart TD
Start[Canonical TES 1.1 task] --> Check{Backend can express task?}
Check -->|No| Reject[Exclude backend]
Check -->|Yes, TES 1.1| Keep[Relay unchanged]
Check -->|Yes, TES 1.0| Downgrade[downgrade_task]
Downgrade --> Relay[Relay TES 1.0 payload]
Reject --> Remaining{Eligible backend remains?}
Remaining -->|No| BadRequest[400 Bad Request]
Remaining -->|Yes| Keep
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Refs #395 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #405 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 23 24 +1
Lines 2238 2479 +241
==========================================
+ Hits 2238 2479 +241 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 10 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pro_tes/ga4gh/tes/versions.py" line_range="27" />
<code_context>
+
+_VERSION = re.compile(r"v?(\d+)\.(\d+)(?:[.\-+].*)?", re.IGNORECASE)
+# Wildcards of output paths in TES 1.1 (POSIX, IEEE Std 1003.1-2017, 2.13)
+_WILDCARDS = re.compile(r"[*?]|\[[^\]]+\]")
+
+
</code_context>
<issue_to_address>
**TES 1.0 selects wrong outputs**
When an output path contains a POSIX bracket expression whose first member is `]`, such as `[]]` or `[]a]`, `_WILDCARDS` does not recognize the expression, so `incompatibilities` treats the path as compatible with TES 1.0 and `downgrade_task` relays it unchanged; the backend treats it literally instead of selecting the intended outputs.
Update `_WILDCARDS` to recognize POSIX bracket expressions that have `]` as their first member.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="907-908" />
<code_context>
if db_connector.update_task_state(
- state="CANCELED",
- if_state=States.TO_CANCEL + States.CANCELING,
+ state=TesState.CANCELING.value,
+ if_state=States.TO_CANCEL,
):
logger.info(
</code_context>
<issue_to_address>
**Missing backend tasks stay unfinished**
When the task is unfinished and the backend answers the cancel request with 404 because it no longer has the task, `cancel_task` propagates a 404 from the backend before updating the stored state to `CANCELING`. Tracking only converts a poll’s 404 to `CANCELED` when the stored state is already `CANCELING`, so the task instead remains unfinished and eventually becomes `UNKNOWN`.
Handle a definitive 404 from the cancel request by conditionally transitioning the task to `CANCELED` (or otherwise ensuring tracking can make that transition).
</issue_to_address>
### Comment 3
<location path="pro_tes/ga4gh/tes/backends.py" line_range="1108-1109" />
<code_context>
+ return version
+ cached = self._cache.get(backend.url)
+ if probe and (cached is None or time.monotonic() >= cached.expires_at):
+ cached = self._probe(backend)
+ self._cache[backend.url] = cached
+ return (cached.version if cached is not None else None) or OLDEST
+
</code_context>
<issue_to_address>
**Healthy backend is rejected**
When two requests probe the same backend concurrently and a failed probe stores its result after a successful probe has updated the cache, `BackendVersions.get` unconditionally stores the failed probe’s earlier cache snapshot over the successful version, so requests treat the healthy backend as old or unconfirmed and reject TES 1.1 tasks with `400` or `503`.
Synchronize probe cache updates or prevent a probe from overwriting a newer cache entry.
</issue_to_address>
### Comment 4
<location path="pro_tes/tasks/track_task_progress.py" line_range="249" />
<code_context>
+ {"worker_id": worker_id, "task.state": TesState.CANCELING.value},
+ {"$set": {"task.state": TesState.CANCELED.value}},
+ )
+ if not result.modified_count:
+ return False
+ logger.info("[%s] %s: deleted by its backend", worker_id, TesState.CANCELED.value)
</code_context>
<issue_to_address>
**Canceled tasks keep polling after redelivery**
When duplicate or redelivered poll messages for a task receive 404 after one delivery has changed its state from `CANCELING` to `CANCELED`, the 404 handler returns `False` once another delivery has already changed the state to `CANCELED`. `_poll` then treats the 404 as an ordinary failed poll and schedules a successor, so duplicate or redelivered messages keep polling a task that is already terminal.
Treat an already-`CANCELED` task as terminal on the 404 path, and prevent duplicate deliveries from scheduling polls for terminal tasks.
</issue_to_address>
### Comment 5
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="368" />
<code_context>
+ if (
+ not candidates
+ and len(eligible) < len(backends)
+ and all(backend_versions.confirmed(backend) for backend in backends)
+ ):
+ run.final_reason = "no_eligible_backend"
</code_context>
<issue_to_address>
**Unavailable unselected backend masks rejection**
When a request selects only a confirmed incompatible backend while another configured but unselected backend has not answered its version probe, `all(backend_versions.confirmed(backend) for backend in backends)` includes backends the caller did not select. If the caller selects only a confirmed TES 1.0 backend that cannot run the task, an unselected backend that has not answered makes this condition false and the request returns `503` instead of the definitive `400` for the selected backend.
Determine whether any backend the caller selected could run the task, and return `400` when none can, independently of unselected backends.
</issue_to_address>
### Comment 6
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="365-368" />
<code_context>
+ if not isinstance(service_type, dict):
+ return None
+ group, artifact = service_type.get("group"), service_type.get("artifact")
+ if (
+ not isinstance(group, str)
+ or not isinstance(artifact, str)
</code_context>
<issue_to_address>
**Routing failure reported as incompatibility**
When the route phase returns no candidates while at least one backend is compatible and another is incompatible, the condition raises `NoEligibleBackend` even though `eligible` contains a compatible backend, so the request returns `400` with task incompatibilities instead of reporting that routing selected no backend.
Raise `NoEligibleBackend` for task incompatibilities only when no compatible backend exists.
</issue_to_address>
### Comment 7
<location path="pro_tes/ga4gh/tes/models.py" line_range="250-257" />
<code_context>
+ " several outputs at once."
+ ),
+ )
+ path_prefix: str | None = Field(
+ default=None,
+ description=(
+ "Prefix to be removed from matching outputs if `path` contains"
+ " wildcards; output URLs are constructed by appending pruned paths"
+ " to the directory specified in `url`. Required if `path` contains"
+ " wildcards, ignored otherwise."
),
)
type: TesFileType | None = TesFileType.FILE
</code_context>
<issue_to_address>
**Wildcard outputs accept missing prefixes**
When a task has a wildcard in `outputs[].path` but omits `outputs[].path_prefix`, `TesOutput` permits `path_prefix=None`, and `validate_task` only constructs the Pydantic and py-tes models; neither checks the wildcard condition. proTES accepts and relays a TES 1.1 task that violates the specification’s requirement, leaving the backend to reject it or misconstruct output URLs.
Reject wildcard outputs without `path_prefix` during task validation, including after plugins modify the task.
</issue_to_address>
### Comment 8
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="122-128" />
<code_context>
+ raise BadRequest("Invalid tag filter: null character")
+ conditions: list[dict[str, Any]] = []
+ for key, value in zip_longest(keys, values, fillvalue=""):
+ tag = {"$getField": {"field": {"$literal": key}, "input": "$task.tags"}}
+ conditions.append(
+ {"$eq": [tag, {"$literal": value}]}
+ if value
+ else {"$eq": [{"$type": tag}, "string"]}
+ )
+ return {"$expr": {"$and": conditions}} if conditions else {}
+
+
</code_context>
<issue_to_address>
**Tag filters scan owned tasks**
When a caller filters a large history by tags, `tags_filter` expresses each arbitrary tag-key lookup with `$getField` inside `$expr`, so MongoDB cannot use a tag-key index to narrow the results; filtering large task histories therefore evaluates the expression across the caller's owned tasks and slows list requests.
Consider a query/index strategy that supports tag filtering at scale, or document and test the expected cost for large task histories.
</issue_to_address>
### Comment 9
<location path="pro_tes/ga4gh/tes/backends.py" line_range="1176-1180" />
<code_context>
+ else None
+ )
+ except Exception as exc:
+ logger.warning(
+ "Service info of TES backend %s not available: %s",
+ backend.url,
+ type(exc).__name__,
+ )
+ # as it is now: other threads may have read it meanwhile
+ previous = self._cache.get(backend.url)
</code_context>
<issue_to_address>
**Name label on probe failure**
The failed-probe warning says the service info was unavailable but does not tell operators to set the tes.version label, unlike the warning for an unsupported reported version.
</issue_to_address>
### Comment 10
<location path="docs/upgrading.md" line_range="67-79" />
<code_context>
+**TES 1.1 (clients):** proTES serves [TES
</code_context>
<issue_to_address>
**Add a release note**
The issue asks for the change to be mentioned in release notes. The diff adds upgrade guidance but no release note.
</issue_to_address>Linked issues
#241 feat(api): implement TES 1.1 · 5 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Serve the official TES 1.1.0 specification and remove the unused old specifications. | ✅ Met | The vendored specification is updated to the pinned 1.1 file; only that TES specification remains in pro_tes/api alongside the proTES additions and security schemes. |
| 2 | Detect backend TES versions and adapt tasks and responses per backend. | ✅ Met | Backend versions are read from labels or service info; tasks are downgraded for relay and fetched tasks are upgraded. |
| 3 | Keep tasks with semantics TES 1.0 cannot express away from TES 1.0 backends. | ✅ Met | Eligibility checks cover ignore_error, strict backend parameters, and wildcard output paths, and routing receives only eligible backends. |
| 4 | Use extensible, registered adapters between adjacent versions and document how to add a version. | ✅ Met | versions.py registers adapters and chains conversions; the development and TES versions docs describe adding one. |
| 5 | Store and relay new fields, implement list filters and service-info fields, and test the new behavior. | ✅ Met | The diff adds the TES 1.1 models, filtering, service-info backend parameters, contract tests, and adaptation tests. |
| 6 | Document supported versions, TES 1.0 task handling, and the change in release notes. | 🟡 Partly met | The version and upgrade documentation is present, but the diff adds no release note. |
#392 feat(api)!: serve TES 1.1.0 · 5 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Vendor the pinned TES 1.1 specification and remove the TES 1.0 specification. | ✅ Met | The new vendored file is configured as the served specification. |
| 2 | Report TES 1.1.0 in service info and add the TES 1.1 output model field. | ✅ Met | The service-info version and TesOutput.path_prefix are updated. |
| 3 | Implement state, tag_key, and tag_value filters with the specification's semantics. | ✅ Met | The implementation handles zipped tag filters and literal tag keys, with filter tests. |
| 4 | Store CANCELING after cancellation until tracking records the backend's final state. | ✅ Met | Cancellation and tracking behavior are updated, including the backend-404 case. |
| 5 | Add contract tests and update the API, development, and upgrade documentation. | ✅ Met | The diff adds contract tests and updates the requested documentation. |
#393 feat: detect the TES versions of backends · 2 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Prefer the tes.version label; otherwise probe and cache service info, treating unsupported versions as the oldest supported version. | ✅ Met | The label takes precedence, and service-info probe results are cached per process. |
| 2 | Treat failed probes as the oldest supported version and warn operators, naming the label they can set. | 🟡 Partly met | A failed probe falls back to the oldest version and logs a warning, but that warning does not name tes.version; the warning for an answered-but-unsupported version does. |
| 3 | Document that Funnel needs the tes.version label and keep detection independent of the Celery tracker. | ✅ Met | The configuration and TES-version docs explain the label; version detection is implemented in the backend layer. |
#394 feat!: adapt tasks to TES versions of backends · 6 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Register adjacent-version adapters and chain conversions for future TES versions. | ✅ Met | The adapter registry, version chain, and chain tests are added. |
| 2 | For TES 1.0, drop fields that do not change task behavior and declare fields it cannot safely express. | ✅ Met | The 1.1-to-1.0 adapter drops optional fields and rejects tasks with the specified incompatibilities. |
| 3 | Filter backends before routing and reject tasks with no eligible backend before storing them. | ✅ Met | Eligibility filtering precedes route-phase plugins, and confirmed ineligible selections produce a 400 before task storage. |
| 4 | Downgrade after the forward phase and upgrade tasks fetched from backends. | ✅ Met | The relay adapts each attempt after forward-phase changes; TesClient upgrades fetched task bodies. |
| 5 | Support a backend that is itself proTES and expose tesResources_backend_parameters. | ✅ Met | The adapter flow is shared for backend calls, and the service-info field is supplied from known backend parameters. |
| 6 | Document routing, supported versions, adding versions, and upgrade implications. | ✅ Met | These topics are covered in tes-versions.md, development.md, and upgrading.md. |
#395 test: relay to TES 1.0 and 1.1 fake backends · 3 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Provide fake TES 1.0 and 1.1 backends, with the TES 1.0 mode rejecting unknown fields. | ✅ Met | The fake backend supports both modes and validates the TES 1.0 fields. |
| 2 | Add the second backend to the smoke stack. | ✅ Met | The Compose configuration includes and health-checks the TES 1.0 backend. |
| 3 | Exercise version-aware routing, adaptation, ineligible-task rejection, list filters, and states in the smoke test. | ✅ Met | check.sh covers those cases, including the 1.0 backend receiving an adapted plain task. |
Sourcery assessment
Needs a human reviewer. 8 findings to address first, and if the version adapter or eligibility check is wrong, proTES can send a task to a TES 1.0 backend after dropping or changing fields, and that backend may execute it with different behavior and write outputs. Reverting stops future adapted requests but does not undo jobs already launched or their outputs.
Blocking findings: pro_tes/ga4gh/tes/versions.py:27, pro_tes/ga4gh/tes/task_runs.py:908, pro_tes/ga4gh/tes/backends.py:1109, pro_tes/tasks/track_task_progress.py:249, pro_tes/ga4gh/tes/task_runs.py:368, and 3 more
A poll delivered twice gets 404 for a task that is CANCELED by then, which ends its tracking now. Bracket expressions may start with a closing bracket, and such output paths need TES 1.1. Refs #392 Refs #394 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Closes #241
Closes #392
Closes #393
Closes #394
Closes #395
Summary
proTES serves TES 1.1.0, and relays tasks to TES instances of TES 1.0 and 1.1. This brings the integration branch
feat/tes-1.1intodev; each part was reviewed in its own PR:GET /tasksfiltersstate,tag_key,tag_value,CANCELING, new fields).tes.version, else its service info, cached per process).Docs:
docs/tes-versions.md(new),docs/api.md,docs/configuration.md,docs/operations.md,docs/development.md,docs/upgrading.md.Operators: Funnel needs the label
tes.version: "1.1"; tag filters need MongoDB 5.0 or later (the chart and Compose use 7.0); clients on py-tes before 1.1 don't know the new states.Verification
Local checks ran on each child PR:
ruff,mypy,ast-grep,pytestwith 100% coverage.CI on this PR: all jobs pass, including Lint, Test (mongomock), Test (MongoDB 7.0, with the tag filters), Chart, Docs, Smoke test (fake TES 1.0 and 1.1 backends, first run here), Scan image, Release readiness and CodeQL; codecov patch and project pass.
Not verified: against real TES instances. TESK, Funnel and Poiesis were not part of any test here, only fakes modelled on what they report; the conformance suite stays out (blocked upstream).
The first run failed on two points, fixed here:
tests/test_app.pyexpected one backend in the smoke config, andmypyontests/smoke/fake_tes.py; neither ran on the PR that changed these files.Declined review findings
Listed in #400, #402 and #403. On this PR (Sourcery): a
404to a cancel request stays as before; the remaining race of failed probes takes microseconds; a cold unselected backend turns400into503; plugins that empty the route get400; wildcards withoutpath_prefixare left to the TES instance; tag filters can't use an index; the wording of a warning; release notes come with the release. Fixed: bracket expressions starting with], and redelivered polls of canceled tasks.Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG