Skip to content

fix: address small findings of the 0.5.0 review - #421

Merged
uniqueg merged 2 commits into
devfrom
fix/review-lows
Nov 4, 2026
Merged

uniqueg merged 2 commits into
devfrom
fix/review-lows

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Closes #418

Summary

Small findings of the pre-release review of 0.5.0:

  • Cancel: a refusal of a TES instance reads the task once. 200 if it has finished (tracking stores the final state), is being canceled, or is gone (both requests answer 404 or 410); otherwise 502, with a new BackendRefused. Other failures are 502 as well, instead of 500. Tasks of early versions, which nothing tracks, always get 502 on a refusal.
  • Log entries: further log entries of a backend (e.g., of retries) are added, instead of an IndexError that lost the logs and outputs.
  • Wildcards: outputs with wildcards without path_prefix are rejected (400), also if a plugin sets them, as TES 1.1 requires the prefix.
  • Docs: deployment on OpenShift in deployment/README.md, state of canceled tasks during rolling upgrades and the wildcard rule in docs/upgrading.md, docs/api.md, docs/tes-versions.md.

Verification

  • python -m pytest with real Helm: all passed. pre-commit run --from-ref origin/dev --to-ref HEAD: passed.
  • Compose smoke test and docs build: run in CI only. Not run: a real TES instance refusing cancels, or an install on OpenShift (the Route was only rendered with helm template; the timeout of Rahti's router is unchecked).

Declined review findings

  • A proxy that answers 404 to both requests makes a task count as gone: tracking's handling of a 404 has this limit already, and is documented; requiring several answers would be a change of tracking, for 0.6.0 if wanted.
  • Narrowing except Exception in _after_refusal: any failure of the read leads to the same 502, and only the type name is logged, as messages of py-tes errors contain the whole task.
  • Paths with escaped wildcards (/d/\*.txt) count as wildcards: TES 1.1 has no escapes; any path_prefix satisfies the check, and the upgrade notes say so.
  • Hard-coded 70s in 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:

  • Handle TES cancel refusals by distinguishing completed, canceling, missing, and still-running tasks, returning appropriate success or 502 responses.
  • Preserve additional backend log entries and outputs, including those produced by retries.
  • Treat HTTP 410 responses like 404 responses when a canceled task is removed by its backend.

Enhancements:

  • Reject wildcard output paths without a path prefix consistently for client and plugin-generated tasks.
  • Document OpenShift deployment configuration, cancellation behavior during rolling upgrades, and the wildcard output requirement.

Tests:

  • Add coverage for cancel refusal outcomes, additional backend logs, wildcard validation, and 410 cancellation responses.

- 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]>
@uniqueg uniqueg added this to the v0.5.0 milestone Nov 4, 2026
@uniqueg
uniqueg marked this pull request as ready for review November 4, 2026 06:40
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 handling

sequenceDiagram
    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
Loading

Flow diagram for wildcard output validation

flowchart 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]
Loading

Flow diagram for preserving retry log entries

flowchart 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]
Loading

File-Level Changes

Change Details Files
Make cancellation refusals distinguishable from transport uncertainty and resolve backend task state before deciding the API response.
  • Added BackendRefused and mapped it to 502 Bad Gateway.
  • Added a cancel helper that treats 5xx/network failures as outcome-unknown, reads tracked tasks after refusal, and handles finished, canceling, gone, and still-running states separately.
  • Updated cancellation API documentation and expanded endpoint tests for refusal, missing-task, race, untracked-task, and error cases.
pro_tes/exceptions.py
pro_tes/ga4gh/tes/task_runs.py
docs/api.md
tests/ga4gh/tes/test_server.py
Preserve backend log entries that exceed the number already stored when final task state is recorded.
  • Append placeholder log records for additional backend entries before copying logs, outputs, timing, and system logs.
  • Added coverage for retry logs and output URL sanitization.
pro_tes/tasks/track_task_progress.py
tests/tasks/test_track_task_progress.py
Enforce the TES 1.1 requirement that wildcard output paths include a path prefix across inbound and plugin-generated tasks.
  • Validate wildcard outputs during task parsing and outbound request checking, rejecting invalid tasks with 400-level validation errors.
  • Added tests for *, ?, character-class wildcards, valid prefixes, ordinary paths, and plugin-produced outputs.
  • Documented the rule and its upgrade impact.
pro_tes/gateway.py
docs/api.md
docs/tes-versions.md
docs/upgrading.md
tests/test_gateway.py
Expand deployment and upgrade documentation for operational behavior introduced or clarified by the release.
  • Added OpenShift Route and router timeout deployment guidance, including alternate backend API paths.
  • Documented rolling-upgrade cancellation behavior and TES compatibility details.
deployment/README.md
docs/upgrading.md
docs/tes-versions.md

Possibly linked issues


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

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35634904 | 📁 Comparing 14c6896 against latest (2ef3770)

  🔍 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/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


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

Comment thread pro_tes/ga4gh/tes/task_runs.py Resolved
Comment thread pro_tes/ga4gh/tes/task_runs.py Resolved
Comment thread pro_tes/gateway.py Resolved
Comment thread pro_tes/tasks/track_task_progress.py Resolved
Comment thread tests/test_gateway.py Resolved
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2ef3770) to head (14c6896).
⚠️ Report is 1 commits behind head on dev.

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.
📢 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.

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]>
@uniqueg
uniqueg merged commit 5a866d8 into dev Nov 4, 2026
30 checks passed
@uniqueg
uniqueg deleted the fix/review-lows branch November 4, 2026 07:05
uniqueg added a commit that referenced this pull request Nov 4, 2026
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]>
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.

Small findings of the 0.5.0 review

1 participant