Skip to content

feat(api)!: serve TES 1.1.0 - #400

Merged
uniqueg merged 5 commits into
feat/tes-1.1from
feat/serve-tes-1.1
Nov 3, 2026
Merged

uniqueg merged 5 commits into
feat/tes-1.1from
feat/serve-tes-1.1

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Part of the TES 1.1 integration branch (#241). Serves TES 1.1.0; relaying is unchanged, so backends get tasks as on dev.

  • Vendored spec of tag v1.1 (117cd92), service info 1.1.0, path_prefix.
  • Less work than planned: type stays with its default FILE in the model, which the spec allows ("required that the server fill in the value"); the plan's "no forced default" isn't needed. The service info schemas stay in additions.openapi.yaml, so no extra vendored file.
  • GET /tasks: state, tag_key, tag_value, with literal keys via $getField (needs MongoDB 5.0; dots matter for gateway.* tags). ListTasks reads the raw query: Connexion would otherwise apply the schema default UNKNOWN to state and split tags at commas.
  • Cancel stores CANCELING; tracking stores the final state; a 404 of the backend for a CANCELING task gives CANCELED.

Closes #392

Verification

CI doesn't run on PRs into feat/tes-1.1 (ci.yml triggers on dev only), and the workflow stays as it is. Run locally on this branch:

  • coverage run -m pytest (mongomock): 1206 passed, 100% coverage, without tests/test_chart.py and the chart examples (need the library chart). These and the docs build, smoke test and image jobs run on the PR from feat/tes-1.1 into dev.
  • MONGODB_TEST_URI=... pytest tests/ga4gh/tes/test_server.py -k "list_tasks or tags_filter or cancel" against MongoDB 7.0: 68 passed, including the tag filters that mongomock can't run.
  • ruff, mypy, ast-grep: clean.

Declined review findings

Two rounds; an interim fix that set CANCELED after failed polls was replaced after round 2.

Sourcery (answered in the threads):

  • Only a 404 naming the task proves deletion: TES defines no such body, and this is about tasks whose cancel the backend accepted.
  • Store CANCELING before the cancel request: a failed cancel must not report it.
  • Reject wildcard outputs without path_prefix: left to backends; Poiesis infers it.
  • Old workers overwriting CANCELING during a rolling upgrade: short-lived, and the final state is recorded.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG

uniqueg and others added 4 commits November 3, 2026 06:52
Vendor the spec of tag v1.1 and report 1.1.0 in the service info.
Add the filters of GET /tasks (state, tag_key, tag_value), with literal
tag keys via $getField, and path_prefix in outputs. Canceled tasks are
CANCELING until the backend reports their final state.

Relaying is unchanged: backends still get tasks as on dev.

Refs #392

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Keep commas in tag filters: Connexion splits array values at commas,
which tags may contain. Let tasks leave CANCELING if their backend no
longer answers, e.g., because it deleted them. Document that tag
filters need MongoDB 5.0.

Refs #392

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Failed polls don't prove that a canceled task stopped: only a 404 of
the backend sets CANCELED, and ends the tracking.

Refs #392

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR upgrades proTES to serve TES 1.1.0 by vendoring and wiring the new contract, extending task models and metadata, adding state and literal tag filters, and changing cancellation tracking to retain CANCELING until the backend reaches a final state or returns 404.

Sequence diagram for TES 1.1 cancellation tracking

sequenceDiagram
    actor User
    participant API as proTES API
    participant Backend as TES Backend
    participant Tracker as Task Tracker
    participant DB as MongoDB

    User->>API: cancel_task
    API->>Backend: cli.cancel_task
    Backend-->>API: cancel accepted
    API->>DB: update_task_state(CANCELING)
    DB-->>API: state updated

    Tracker->>Backend: poll task
    alt Backend reports final state
        Backend-->>Tracker: final state
        Tracker->>DB: _store_state(final state)
    else Backend returns 404
        Backend-->>Tracker: HTTP 404
        Tracker->>DB: _deleted_after_cancel
        DB-->>Tracker: state CANCELED
    else Backend unavailable or still running
        Backend-->>Tracker: polling error or running state
        Tracker->>DB: keep CANCELING
    end
Loading

Flow diagram for TES 1.1 task listing filters

flowchart LR
    Request[GET /tasks] --> ListTasks[ListTasks]
    ListTasks --> State[state filter]
    ListTasks --> Tags[tags_filter]
    Tags --> Literal[$getField literal tag keys]
    State --> Query[MongoDB task query]
    Literal --> Query
    Query --> Response[Filtered task list]
Loading

File-Level Changes

Change Details Files
Upgrade the served API and data models to TES 1.1.0 while preserving backend relaying behavior.
  • Vendor the upstream v1.1 OpenAPI specification and configure it alongside proTES additions.
  • Expose TES 1.1 fields including output path prefixes, streamable inputs, backend parameters, executor error handling, and new task states.
  • Keep file type defaulting to FILE while allowing clients to omit it.
  • Update service metadata, model conversions, documentation, and upgrade guidance.
pro_tes/api/20221114.117cd92.task_execution_service.openapi.yaml
pro_tes/config.yaml
pro_tes/ga4gh/tes/models.py
pro_tes/utils/models.py
.pre-commit-config.yaml
docs/api.md
docs/development.md
docs/upgrading.md
tests/ga4gh/tes/test_contract.py
tests/test_app.py
Implement TES 1.1 task-list filtering with literal tag semantics and MongoDB aggregation support.
  • Add optional state filtering without applying the schema's UNKNOWN default when absent.
  • Read repeated tag query parameters directly to preserve commas and empty values.
  • Zip tag keys and values, validate malformed input, and use literal $getField expressions for dotted or dollar-prefixed keys.
  • Require MongoDB 5.0 or newer for tag filtering and add contract/integration coverage.
pro_tes/ga4gh/tes/server.py
pro_tes/ga4gh/tes/task_runs.py
tests/ga4gh/tes/test_server.py
docs/api.md
docs/upgrading.md
Model cancellation as an asynchronous CANCELING state until the backend reports a final result.
  • Store CANCELING after a successful cancellation request and preserve it across unavailable or non-final backend polls.
  • Continue tracking CANCELING tasks after worker recovery while retaining compatibility for previously stored CANCELED tasks.
  • Convert a backend 404 during cancellation to CANCELED and stop tracking, while leaving non-404 failures in CANCELING.
  • Update cancellation, tracking, operations documentation, and regression tests.
pro_tes/ga4gh/tes/task_runs.py
pro_tes/tasks/track_task_progress.py
tests/ga4gh/tes/test_server.py
tests/tasks/test_track_task_progress.py
docs/api.md
docs/operations.md
docs/upgrading.md

Possibly linked issues

  • feat(api)!: serve TES 1.1.0 #392: The PR implements the issue’s TES 1.1.0 spec, service version, models, filters, cancellation semantics, contract tests, and documentation.

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

@uniqueg
uniqueg marked this pull request as ready for review November 3, 2026 06:24
@read-the-docs-community

read-the-docs-community Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35604374 | 📁 Comparing a15f0b2 against latest (81f923a)

  🔍 Preview build  

5 files changed · ± 5 modified

± 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/tasks/track_task_progress.py" line_range="243" />
<code_context>
+        Whether the task was set to `CANCELED`, which ends its tracking.
+    """
+    response = exc.response if isinstance(exc, requests.HTTPError) else None
+    if response is None or response.status_code != HTTPStatus.NOT_FOUND:
+        return False
+    result = collection.update_one(
</code_context>
<issue_to_address>
**Misreported cancellation on HTTP 404**

When a backend or intermediary returns 404 for a `CANCELING` task for a reason other than that task being absent, `_deleted_after_cancel` treats every `HTTPError` with status 404 as proof that the task was deleted, then stores `CANCELED` and stops tracking. A 404 caused by a missing GET route or a proxy/backend routing error does not prove the task stopped, so the caller sees a canceled task while it may still be running.

Only treat a 404 as task deletion when the backend response identifies the requested task as not found, rather than relying on the status code alone.
</issue_to_address>

### Comment 2
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="872-874" />
<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(
-                    "Task '%s' with worker ID '%s' canceled.",
</code_context>
<issue_to_address>
**Canceled tasks remain untracked**

When the backend removes a task during cancellation but proTES does not receive a successful cancel response, `cancel_task` leaves the stored state unchanged, and `_deleted_after_cancel` handles 404s only for tasks already in `CANCELING`; tracking keeps retrying and eventually leaves the task `UNKNOWN`.

Store `CANCELING` before sending the cancel request, so a later 404 can end tracking even when the request does not return success.

Also at `pro_tes/tasks/track_task_progress.py:246-248`.
</issue_to_address>

### Comment 3
<location path="pro_tes/ga4gh/tes/models.py" line_range="250-256" />
<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."
         ),
     )
</code_context>
<issue_to_address>
**Wildcard outputs lack usable URLs**

When a submitted output path contains wildcards and omits `path_prefix`, `validate_task` accepts and relays the task without enough information to construct output URLs, leaving callers and backends with ambiguous or invalid output locations.

Enforce the conditional requirement that wildcard output paths include `path_prefix`.
</issue_to_address>

### Comment 4
<location path="pro_tes/tasks/track_task_progress.py" line_range="180-181" />
<code_context>
     query: dict[str, Any] = {"worker_id": worker_id}
     if keep_canceled:
-        query["task.state"] = {"$ne": TesState.CANCELED.value}
+        query["task.state"] = {
+            "$nin": [TesState.CANCELED.value, TesState.CANCELING.value]
+        }
     result = collection.update_one(query, {"$set": {"task.state": state}})
</code_context>
<issue_to_address>
**Cancellation state gets overwritten**

When an older tracking worker polls a task after a new API instance stores `CANCELING` during a rolling upgrade, the older worker's state update excludes only `CANCELED`, so it overwrites `CANCELING` with a stale backend response such as `RUNNING` or `UNKNOWN`; the task no longer appears to be canceling.

Ensure tracking state updates preserve `CANCELING`, including updates from workers running during a rolling upgrade.

Also at `pro_tes/ga4gh/tes/task_runs.py:872-873`.
</issue_to_address>

### Comment 5
<location path="tests/ga4gh/tes/test_contract.py" line_range="105-106" />
<code_context>
+    `MINIMAL` is left out: it doesn't match `tesTask.required` (cf.
+    https://github.com/ga4gh/task-execution-schemas/issues/136).
+    """
+    _validate(
+        client.get(f"{BASE_PATH}/tasks/{task_id}?view={view}").get_json(), "tesTask"
+    )
+    _validate(
+        client.get(f"{BASE_PATH}/tasks?view={view}").get_json(),
+        "tesListTasksResponse",
+    )
+
+
[email protected]("state", ["PREEMPTED", "CANCELING"])
+def test_new_states(
+    client: FlaskClient, task_id: str, state: str, mongo_client: Any
+) -> None:
+    """The states of TES 1.1 are served."""
+    set_state(mongo_client, task_id, state)
+    _validate(
+        client.get(f"{BASE_PATH}/tasks/{task_id}?view=BASIC").get_json(), "tesTask"
+    )
</code_context>
<issue_to_address>
**New states can be served incorrectly**

When the endpoint returns `UNKNOWN` for a stored `PREEMPTED` or `CANCELING` state, when the endpoint maps either new state to `UNKNOWN`, `test_new_states` only calls `_validate`; `UNKNOWN` is also valid under the TES schema, so the test passes without verifying that the requested state was served.

Assert that the returned task’s `state` equals the parameterized `state`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 5 findings to address first, and cancellation now persists CANCELING until tracking receives a final state or a backend 404, and the new state may remain in task records if the code is reverted. The impact is bounded to affected tasks and can be reconciled; reverting also restores the previous API behavior.

Blocking findings: pro_tes/tasks/track_task_progress.py:243, pro_tes/ga4gh/tes/task_runs.py:874, pro_tes/ga4gh/tes/models.py:256, pro_tes/tasks/track_task_progress.py:181, tests/ga4gh/tes/test_contract.py:106


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

Comment thread pro_tes/tasks/track_task_progress.py Resolved
Comment thread pro_tes/ga4gh/tes/task_runs.py Resolved
Comment thread pro_tes/ga4gh/tes/models.py Resolved
Comment thread pro_tes/tasks/track_task_progress.py Resolved
Comment thread tests/ga4gh/tes/test_contract.py Resolved
@uniqueg
uniqueg merged commit a1cb3a0 into feat/tes-1.1 Nov 3, 2026
2 checks passed
@uniqueg
uniqueg deleted the feat/serve-tes-1.1 branch November 3, 2026 06: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