Repository navigation
fix: task listing, timestamps and relay bugs - #238
Conversation
Mirror the package in `tests/` and replace the tests that could not be collected (`tests/unitTest`) and the integration tests against public TES instances (`tests/test_integration`): - conftest: real MongoDB via `MONGODB_TEST_URI` (databases dropped per test, refused if present), no network access except to it, no name resolution in the distance-based middleware - TES endpoints with fake backends: relay, fallback to the next backend, failures, Funnel, views, cancellation - task as received stored once and never changed (#142) - Celery task: states, polling, retries, failures (#149) - middleware handler and task distribution middlewares (#168) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run all tests in CI (no ignored directories), on Python 3.10 and 3.12, and against MongoDB 7.0 (`MONGODB_TEST_URI`), with a stable "Run tests" check, as in cloud-registry. Replace the integration tests against public TES instances with a Compose smoke test: a Compose override and config overlay (`tests/smoke/`) relay tasks to a fake TES backend, and the job checks that a task is relayed to it and tracked by the Celery worker until it is complete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes: the Compose smoke checks move from the workflow to `tests/smoke/check.sh`, which also runs locally; the network guard of the tests also covers `socket.connect_ex()`; the docs describe the test layout and the network guard, and require a standalone MongoDB for `MONGODB_TEST_URI`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The middlewares of the config are lists of alternatives; the Celery worker refused the flat list of the smoke test overlay. A test now validates the overlay with the app. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- GET /tasks: empty `next_page_token` on the last page and empty pages instead of errors (#165); `400` for invalid page tokens and page sizes; empty tokens list the first page; page sizes default to 256 and are capped at `max_page_size` (2047), as in the TES specification - `name_prefix` matched literally (`re.escape()`), not as a regular expression - relay: each backend gets the validated task, not a copy changed for another backend; credentials are stripped from input and output URLs field by field, keeping the objects and inputs with `content` - times in UTC, in RFC 3339 format; `creation_time` set by proTES - BASIC view without system logs and executor stdout/stderr (wrong projection paths) - remote task ID stored in `tes_endpoint.task_id`, so that tasks can be canceled with `storeLogs.execution_trace: False` (stored a dict that cancellation couldn't read); earlier tasks use their last forward Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use the default view of the spec when no view is given, simplify the list conversion, and test page size limits and the default view. Document the creation_time rejection in the API docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Don't relay the read-only creation_time to TES instances, cancel tasks stored without an execution trace by their remote_task_id, cancel tasks that were not forwarded locally, and reject name prefixes with null characters, which MongoDB refuses. Document the page size validation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cancelable states come only from the TES instance a task was forwarded to, so a cancelable task without a remote identifier is an error, not a task to cancel locally. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # docs/development.md # tests/conftest.py # tests/ga4gh/tes/test_server.py # tests/test_fixtures.py
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR fixes TES task listing and pagination edge cases, standardizes server-generated timestamps, isolates relay payload mutations with credential sanitization, and makes cancellation robust when execution tracing is disabled or records are from older versions. Configuration, API documentation, and extensive regression tests are updated to codify the new behavior. Sequence diagram for isolated task relay and timestamp assignmentsequenceDiagram
participant Client
participant ProTES
participant TES
Client->>ProTES: POST /tasks
ProTES->>ProTES: utc_now()
ProTES->>ProTES: TesTask validation
loop Each TES endpoint
ProTES->>ProTES: deepcopy(payload_marshalled)
alt Non-Funnel endpoint
ProTES->>ProTES: _strip_credentials(task_relayed)
end
ProTES->>TES: create_task(task_relayed)
TES-->>ProTES: remote_task_id
end
ProTES-->>Client: task identifier
Sequence diagram for cancellation with stored remote identifierssequenceDiagram
participant Client
participant ProTES
participant TES
Client->>ProTES: POST /tasks/{id}:cancel
ProTES->>ProTES: _remote_task_id(document, db_document)
alt Current record
ProTES->>ProTES: Read tes_endpoint.task_id
else Earlier record
ProTES->>ProTES: Read last forward or remote_task_id
end
ProTES->>TES: cancel_task(remote_task_id)
TES-->>ProTES: Cancellation result
ProTES-->>Client: Task response
Flow diagram for validated task listing paginationflowchart LR
Request[GET /tasks] --> Validate[_page_size]
Validate --> Filter[Literal name_prefix and page_token validation]
Filter --> Query[Query newest tasks]
Query --> Page[Return up to configured page size]
Page --> Token{More tasks?}
Token -->|Yes| Next[next_page_token = last returned task ID]
Token -->|No| Empty[next_page_token = empty]
File-Level Changes
Assessment against linked issues
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 2 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="599" />
<code_context>
"""
- time_now = datetime.now().strftime("%m-%d-%Y %H:%M:%S")
- tes_endpoint_dict: dict[str, Any] = {"host": tes_url, "base_path": ""}
+ time_now = utc_now()
+ tes_endpoint_dict: dict[str, Any] = {
+ "host": tes_url,
</code_context>
<issue_to_address>
**End time precedes task completion**
When a backend accepts a task that is still running, `_update_doc_in_db` runs as soon as a backend accepts the task and assigns `utc_now()` to every log’s `end_time`, before the task has completed. The task is therefore served with a completion timestamp while it is still running.
Set `end_time` only when the task reaches a terminal state, using the backend’s completion time when available.
</issue_to_address>
### Comment 2
<location path="pro_tes/config_models.py" line_range="112" />
<code_context>
- default_page_size: int = 5
+ default_page_size: PositiveInt = 256
+ max_page_size: PositiveInt = 2047
+
+ @model_validator(mode="after")
</code_context>
<issue_to_address>
**Oversized pages violate TES**
When an operator configures `max_page_size` above 2047 and a request has enough matching tasks, `_page_size` caps requests at `max_page_size`, so a configured value above 2047 lets `GET /tasks` return more tasks per page than the TES specification permits. Callers receive nonconforming pages.
Constrain `max_page_size` to at most 2047 during configuration validation.
Also at `pro_tes/ga4gh/tes/task_runs.py:685`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and when a non-Funnel backend rejects a task, the next Funnel backend now receives the original input and output URLs, including any embedded credentials; the previous relay path could leave those credentials stripped. Reverting stops future relays from doing this, but credentials already sent cannot be recalled.
Blocking findings: pro_tes/ga4gh/tes/task_runs.py:599, pro_tes/config_models.py:112
The TES specification allows pages of fewer than 2048 tasks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Fixes the bugs of task listing, timestamps and relaying found by the tests of #236.
Closes #208
Closes #165
contentare kept. The read-onlycreation_timeis no longer relayed.next_page_tokenis empty on the last page; before, it was the last task's identifier, so clients kept paging.400.custom.controllers.list_tasks.default_page_sizeandmax_page_size; validated, andmax_page_sizeis at most 2047). The default was 5.name_prefixis matched literally (re.escape), not as a regular expression.BASICview: it now leaves outtask.logs.system_logs,task.logs.logs.stdoutandtask.logs.logs.stderr. Before, it projected paths that don't exist. The fallback view isMINIMAL, as in the spec (connexion already applied the spec default).creation_time,start_time,end_timeandforward_timeare in UTC, in RFC 3339 format (utc_now()); they were local-time strings.creation_timeand rejects tasks that set it (400), as the spec marks it read-only.tes_endpoint.task_id, so tasks can be canceled withstoreLogs.execution_trace: Falsetoo. That setting no longer writes a metadata dict that cancellation couldn't read.remote_task_id.api.md,configuration.mdandupgrading.md, including the behaviour changes below.Behaviour changes
default_page_sizeexceedsmax_page_size.creation_timeare rejected with400.Verification
pytest: 148 tests pass with mongomock and with MongoDB 7 (MONGODB_TEST_URI). 23 of the new tests failed on the old code.ruff check,ruff format --check,mypy pro_tes tests,ast-grep scan,semgrep --config=.semgrepandmkdocs build --strictare clean.Declined review findings
BASICtoMINIMAL(breaking): it doesn't change. Connexion applies the spec default (MINIMAL), so the oldBASICfallback in the code was never used. A test now pins the default.init_app()builds a new configuration for eachappfixture.500) as before.end_timeset at forwarding, before the task finishes: this PR doesn't change when it is set, only its format. The log'sstart_timeandend_timehave always been proTES's own relay times (receipt and forwarding). See the follow-ups._page_sizeand_remote_task_idnext to the other private helpers: skipped to keep the diff small.Follow-ups (out of scope)
start_timeandend_timebe the backend's times instead of proTES's relay times?UNKNOWNuntil the Celery worker sets it.tasksis ontask_id/worker_id, but the field istask.id, so duplicate generated task IDs are never detected.🤖 Generated with Claude Code