Repository navigation
feat(api)!: serve TES 1.1.0 - #400
Conversation
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
Reviewer's GuideThis 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 trackingsequenceDiagram
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
Flow diagram for TES 1.1 task listing filtersflowchart 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]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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
Refs #392 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Part of the TES 1.1 integration branch (#241). Serves TES 1.1.0; relaying is unchanged, so backends get tasks as on
dev.v1.1(117cd92), service info1.1.0,path_prefix.typestays with its defaultFILEin 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 inadditions.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 forgateway.*tags).ListTasksreads the raw query: Connexion would otherwise apply the schema defaultUNKNOWNtostateand split tags at commas.CANCELING; tracking stores the final state; a404of the backend for aCANCELINGtask givesCANCELED.Closes #392
Verification
CI doesn't run on PRs into
feat/tes-1.1(ci.ymltriggers ondevonly), and the workflow stays as it is. Run locally on this branch:coverage run -m pytest(mongomock): 1206 passed, 100% coverage, withouttests/test_chart.pyand the chart examples (need the library chart). These and the docs build, smoke test and image jobs run on the PR fromfeat/tes-1.1intodev.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
CANCELEDafter failed polls was replaced after round 2.Sourcery (answered in the threads):
404naming the task proves deletion: TES defines no such body, and this is about tasks whose cancel the backend accepted.CANCELINGbefore the cancel request: a failed cancel must not report it.path_prefix: left to backends; Poiesis infers it.CANCELINGduring a rolling upgrade: short-lived, and the final state is recorded.🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG