Repository navigation
fix: address small findings of the 0.5.0 review - #421
Conversation
- Answer 200 to the cancel of a task that has finished, is being canceled or is gone at its TES instance, as the task read back says, and 502 to other failures and refusals, instead of 500. - Add further log entries of a backend instead of failing with an IndexError, which lost the logs and outputs of a task. - Reject outputs with wildcards without path_prefix, also if a plugin sets them. - Document the deployment on OpenShift and the state of canceled tasks during rolling upgrades. Closes #418 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR fixes cancellation error semantics by inspecting tracked backend tasks after refusals, preserves extra retry log entries during final-state storage, and enforces TES 1.1 wildcard output validation. It also adds focused regression coverage and documents OpenShift deployment, cancellation during rolling upgrades, and compatibility behavior. Sequence diagram for backend cancellation refusal handlingsequenceDiagram
participant Client
participant TaskRuns
participant TES as TES_backend
participant Tracker
Client->>TaskRuns: cancel_task(id)
TaskRuns->>TES: cancel_task(task_id)
alt cancel accepted
TES-->>TaskRuns: success
TaskRuns-->>Client: 200
else cancel refused
TaskRuns->>TES: get_task(task_id)
alt task finished
TES-->>TaskRuns: final state
TaskRuns->>Tracker: preserve final state
TaskRuns-->>Client: 200
else task canceling or gone
TES-->>TaskRuns: CANCELING or 404/410
TaskRuns-->>Client: 200
else task still active or untracked
TES-->>TaskRuns: non-final state or refusal
TaskRuns-->>Client: 502 BackendRefused
end
end
Flow diagram for wildcard output validationflowchart TD
A[Build TES task] --> B{Output path has wildcards?}
B -- No --> C[Accept task]
B -- Yes --> D{path_prefix is set?}
D -- Yes --> C
D -- No --> E[Reject with 400 Bad Request]
Flow diagram for preserving retry log entriesflowchart TD
A[Store final task state] --> B[Iterate backend log entries]
B --> C{Entry exceeds stored log count?}
C -- Yes --> D[Append log entry placeholder]
C -- No --> E[Update existing log entry]
D --> E
E --> F[Store logs and outputs]
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/ga4gh/tes/task_runs.py" line_range="242" />
<code_context>
+ # only if the refusal said so as well: a backend may also hide tasks
+ response = getattr(exc, "response", None)
+ if (
+ getattr(response, "status_code", None) == HTTPStatus.NOT_FOUND
+ and cause.response is not None
+ and cause.response.status_code in GONE
</code_context>
<issue_to_address>
**Gone tasks return cancellation errors**
When the backend refuses cancellation with 404 or 410, then returns 410 from the follow-up task read, `_after_refusal` accepts only a 404 from `get_task`, so the 410 raises `BackendRefused` and the caller receives 502 instead of the successful gone-task response. If a later poll also returns 410, tracking leaves the task CANCELING indefinitely.
Treat 410 from the follow-up read as evidence that the task is gone, and ensure tracking treats a later 410 poll as deleted.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="235" />
<code_context>
+ tracks it.
+ """
+ if not tracked:
+ raise BackendRefused(REFUSED) from cause
+ try:
+ state = cli.get_task(task_id=task_id).state
</code_context>
<issue_to_address>
**Untracked task refusals**
When the backend refuses a cancel for an untracked task, the code immediately raises BackendRefused without checking whether the task is finished or gone. The issue asks for final or gone tasks to succeed, so this case still returns 502.
</issue_to_address>
### Comment 3
<location path="pro_tes/gateway.py" line_range="219" />
<code_context>
if task.get("outputs") is not None:
task["outputs"] = [tes.models.Output(**item) for item in task["outputs"]]
+ for output in task["outputs"]:
+ if not output.path_prefix and has_wildcards(str(output.path)):
+ raise ValueError("Output with wildcards in its path has no path_prefix")
if task.get("resources") is not None:
</code_context>
<issue_to_address>
**Empty prefix rejects valid outputs**
When a client supplies an empty `path_prefix` for an output path containing wildcards, `output.path_prefix == ""` is treated as missing, so `validate_task` rejects the task with `ValueError` even though an empty string is a valid string-valued prefix and can be supplied by a TES client. The caller sees a `400` for an output that includes the required field.
Check whether `path_prefix is None` rather than whether it is falsey.
</issue_to_address>
### Comment 4
<location path="pro_tes/tasks/track_task_progress.py" line_range="403-410" />
<code_context>
+ if index == len(document.task.logs):
+ # e.g., of a retry; times are those of the backend, unlike in the
+ # entry of proTES
+ document.task.logs.append(
+ TesTaskLog(
+ logs=[],
+ outputs=[],
+ start_time=logs.start_time,
+ end_time=logs.end_time,
+ )
+ )
document.task.logs[index].logs = logs.logs
</code_context>
<issue_to_address>
**Retry log metadata disappears**
When a backend returns an additional task log entry with metadata, the appended `TesTaskLog` copies timestamps but not `logs.metadata`, while `TaskModelConverter.convert_logs` preserves backend log metadata for existing entries. Clients reading the stored task therefore lose metadata on each additional backend log entry.
Copy `logs.metadata` when creating the appended `TesTaskLog`, unless dropping backend metadata is an intentional documented contract.
</issue_to_address>
### Comment 5
<location path="tests/test_gateway.py" line_range="112" />
<code_context>
+ payload={"executors": [EXECUTOR], "outputs": [output]},
+ )
+ with pytest.raises(ValueError, match="path_prefix"):
+ gateway.check_outbound(outbound)
+
+
</code_context>
<issue_to_address>
**Outbound test lacks app context**
When the outbound wildcard test runs without an app context, when `test_wildcards_without_prefix_outbound` runs, `gateway.check_outbound` calls `sanitize_task`, which reads custom config; without an app context this raises before wildcard validation, so the expected `ValueError` is not raised and the test fails with the context error.
Give the test an `app` fixture and call `gateway.check_outbound` inside `app.app.app_context()`.
</issue_to_address>Linked issues
#418 Small findings of the 0.5.0 review · 6 of 7 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | A cancel of a task that is final or gone at its TES instance should succeed; other failures should be 502. | 🟡 Partly met | Tracked tasks reported as finished, already canceling, or absent via a 404 read are handled, and other failures map to 502; untracked tasks and reads returning 410 are still treated as refusals. |
| 2 | Add further backend log entries instead of losing the task's logs and outputs on IndexError. | ✅ Met | Additional entries are appended before their logs and outputs are stored. |
| 3 | Reject wildcard outputs without path_prefix with 400. | ✅ Met | Validation runs through tes_task for client tasks and outbound plugin tasks. |
| 4 | Document that disabling protes.ingress.enabled selects the OpenShift Route. | ✅ Met | |
| 5 | Document how to set the OpenShift router timeout. | ✅ Met | The README gives the haproxy.router.openshift.io/timeout annotation example. |
| 6 | Document which values to use for TESP. | ✅ Met | The README says to set apiPath in tes.backends when the TES API is served at another path. |
| 7 | Document that 0.4.0 workers can turn CANCELING back to RUNNING during rolling upgrades. | ✅ Met | The upgrade notes explain the state change and its consequences. |
Sourcery assessment
Needs a human reviewer. 5 findings to address first, and if both cancel and task-read requests receive 404s from a proxy rather than because the task is gone, proTES can treat the task as canceled while the backend job is still running. Reverting prevents this behavior for future requests but does not undo a task state already stored as canceled; that record is bounded and can be repaired.
Blocking findings: pro_tes/ga4gh/tes/task_runs.py:242, pro_tes/ga4gh/tes/task_runs.py:235, pro_tes/gateway.py:219, pro_tes/tasks/track_task_progress.py:410, tests/test_gateway.py:112
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #421 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 2642 2680 +38
=========================================
+ Hits 2642 2680 +38 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A backend may answer 410 to tasks it no longer has, also to polls. An empty path_prefix is a prefix for outputs with wildcards. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the review fixes #410, #412, #417, #419, #420, #421. The only conflict is in the module docstring of `pro_tes/ga4gh/tes/backends.py`: keeps this branch's removal of the FOCA 0.19 caveat about redirects, and the sentence of #419 about tasks in the view `FULL`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #418
Summary
Small findings of the pre-release review of 0.5.0:
200if it has finished (tracking stores the final state), is being canceled, or is gone (both requests answer404or410); otherwise502, with a newBackendRefused. Other failures are502as well, instead of500. Tasks of early versions, which nothing tracks, always get502on a refusal.IndexErrorthat lost the logs and outputs.path_prefixare rejected (400), also if a plugin sets them, as TES 1.1 requires the prefix.deployment/README.md, state of canceled tasks during rolling upgrades and the wildcard rule indocs/upgrading.md,docs/api.md,docs/tes-versions.md.Verification
python -m pytestwith real Helm: all passed.pre-commit run --from-ref origin/dev --to-ref HEAD: passed.helm template; the timeout of Rahti's router is unchecked).Declined review findings
404to both requests makes a task count as gone: tracking's handling of a404has this limit already, and is documented; requiring several answers would be a change of tracking, for 0.6.0 if wanted.except Exceptionin_after_refusal: any failure of the read leads to the same502, and only the type name is logged, as messages of py-tes errors contain the whole task./d/\*.txt) count as wildcards: TES 1.1 has no escapes; anypath_prefixsatisfies the check, and the upgrade notes say so.70sin the OpenShift example: it is an example, and the README refers to the derivation in the configuration docs.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Improve cancellation handling, backend log preservation, and TES wildcard validation while documenting the resulting behavior and deployment guidance.
Bug Fixes:
Enhancements:
Tests: