Repository navigation
fix: bound task listings and stored task data - #292
Conversation
- Pages of the view FULL have at most custom.controllers.list_tasks.max_page_size_full tasks (default 64), and the cursor is processed document by document instead of being loaded as a list. - Inline contents of inputs are limited to custom.controllers.post_task.max_inline_content bytes together (default 64 KiB), also those that middlewares add (413). - Docs: rate limits at the proxy are recommended for production. Part of #284 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tasks that fail validation after the middlewares, and tasks that no TES instance accepts, are deleted with their owner's roles, instead of being stored as SYSTEM_ERROR. Part of #284 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # docs/upgrading.md
Also: don't read original tasks in listings, raise the default inline content limit to the 128 KiB that the TES specification recommends, keep the error of the request if a task can't be discarded, and complete the docs of the new errors. Part of #284 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The TES specification recommends supporting 128 KiB per content field; all contents together are bounded by the request size limit. Also don't claim in the error that tasks were not kept, as they are kept if they can't be deleted. Part of #284 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR bounds memory and storage growth by limiting FULL task listings and inline input content, streaming listing cursors, and removing tasks that are definitively not forwarded while preserving uncertain outcomes; configuration, error mapping, tests, and operational documentation are updated accordingly. Sequence diagram for bounded task creation and forwardingsequenceDiagram
actor Client
participant API as proTES
participant Middleware
participant TES as TES instance
participant DB as Task database
Client->>API: POST /tasks
API->>API: _check_inline_content
alt inline content exceeds limit
API-->>Client: 413 Content Too Large
else content is within limit
API->>Middleware: Apply middlewares
Middleware-->>API: Modified task
API->>API: _check_inline_content
alt modified task is too large or invalid
API->>DB: _discard_task
API-->>Client: 413 or 400
else task is valid
API->>TES: Forward task
alt TES accepts
TES-->>API: Accepted
API-->>Client: Task identifier
else TES may have accepted
TES-->>API: Uncertain outcome
API-->>Client: 502 Bad Gateway
else no TES accepts
API->>DB: _discard_task
API-->>Client: 500 Internal Server Error
end
end
end
Flow diagram for bounded FULL task listingsflowchart TD
A[GET /tasks] --> B{view is FULL}
B -->|yes| C[Limit page size to min max_page_size and max_page_size_full]
B -->|no| D[Limit page size to max_page_size]
C --> E[Query cursor with page_size plus one]
D --> E
E --> F[Iterate cursor one document at a time]
F --> G[Return page and next_page_token]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #292 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 29
Lines 2343 2372 +29
=========================================
+ Hits 2343 2372 +29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 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="897-902" />
<code_context>
+ if not isinstance(inputs, list):
+ return
+ size = max(
+ (
+ len(item["content"].encode("utf-8", errors="surrogatepass"))
+ for item in inputs
+ if isinstance(item, dict) and isinstance(item.get("content"), str)
+ ),
+ default=0,
+ )
+ if size > limit:
</code_context>
<issue_to_address>
**Middleware contents exceed size bound**
When middleware adds multiple inline contents that are each within the per-input limit but whose combined size exceeds the configured bound, `_check_inline_content` measures only the largest individual content, while the request-body limit applies before middleware processing. The transformed task therefore exceeds the intended aggregate bound and is stored and forwarded.
Change `_check_inline_content` to measure the aggregate size of inline contents and reject the transformed task when it exceeds the configured limit.
Also at `pro_tes/ga4gh/tes/task_runs.py:173`.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="598-601" />
<code_context>
+ """
+ try:
+ self.db_client.delete_one({"worker_id": db_document.worker_id})
+ remove_task_owner(
+ collection=collection, task_id=str(db_document.task.id), owner=owner
+ )
+ except Exception:
+ logger.exception("Task '%s' could not be discarded", db_document.task.id)
+ with suppress(Exception):
</code_context>
<issue_to_address>
**Owner roles remain after deletion**
When task deletion succeeds but revoking one or more owner roles fails, `remove_task_owner` raises after the task document has been deleted, so `_discard_task` attempts to mark a nonexistent document `SYSTEM_ERROR` and leaves remaining owner policy roles behind indefinitely.
Handle owner-role revocation independently of task deletion and skip the `SYSTEM_ERROR` update when the task document is already gone.
</issue_to_address>
### Comment 3
<location path="tests/ga4gh/tes/test_server.py" line_range="709-711" />
<code_context>
+ if accepted:
+ assert response.status_code == 200
+ return
+ assert response.status_code == 413
+ assert "inline content" in response.get_json()["detail"]
+ assert not relayed(backend)
+ assert mongo_client[DB]["tasks"].count_documents({}) == 0
+
+
+def test_create_task_inline_content_middleware(
</code_context>
<issue_to_address>
**Middleware rejection leaves task stored**
When the middleware adds oversized inline content, the test checks only the `413` response and that nothing was relayed; a broken path that leaves the already-inserted task in the database still passes.
Also assert that the task was not stored (and that its owner roles were removed).
</issue_to_address>
### Comment 4
<location path="tests/ga4gh/tes/test_server.py" line_range="1187" />
<code_context>
+ """Tasks that could not be forwarded are not kept, so users don't own them."""
backend.failing.update(BACKENDS)
response = client.post(f"{BASE_PATH}/tasks", json=TASK)
assert response.status_code == 500
- (task_id,) = list_ids(client, USER)
- response = client.get(f"{BASE_PATH}/tasks/{task_id}")
</code_context>
<issue_to_address>
**Wrong server error still passes**
When task deletion fails after no TES instance accepts it, `test_create_task_not_discarded` checks only `response.status_code == 500`, so returning a different 500 problem instead of the original forwarding error passes; the database-state assertion does not distinguish the responses.
Assert that the response identifies the original no-instance-accepted error, not merely that its status is 500.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and when validation fails or no TES instance accepts a task, the new cleanup deletes the stored task record and its owner roles. Reverting stops future deletions but cannot restore records already removed; the loss is limited to tasks from those failed submissions.
Blocking findings: pro_tes/ga4gh/tes/task_runs.py:902, pro_tes/ga4gh/tes/task_runs.py:601, tests/ga4gh/tes/test_server.py:711, tests/ga4gh/tes/test_server.py:1187
Part of #284 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Closes #284.
FULLhave at mostcustom.controllers.list_tasks.max_page_size_fulltasks (new, default 64). The cap also applies to the default page size. Listings iterate the cursor one document at a time instead oflist(cursor). They no longer readtask_originalin the viewsBASICandFULL, since onlytaskis served.400), and tasks that no TES instance accepts (500), are deleted, together with their owner's roles. Before, they were stored asSYSTEM_ERROR. Tasks that a TES instance may have accepted (502) are still kept asSYSTEM_ERROR. If the deletion fails, the error is logged, the task is markedSYSTEM_ERRORif possible, and the original error is returned.inputs[].content) is limited tocustom.controllers.post_task.max_inline_content(new, default 131072 bytes of UTF-8, i.e., 128 KiB, the minimum that the TES specification recommends per field). Larger tasks are rejected with413 Content Too Large, before and after the middlewares. All contents together are bounded byserver.max_content_length.upgrading.md: the behaviour changes.The follow-ups #285 (per-user task limit) and #286 (retention of finished tasks) are opt-in features for after the release.
How it was verified
coverage run -m pytest: 942 passed, 81 skipped; coverage 100%.test_server.pyandtest_access_control.pyalso passed against MongoDB 7.0 (MONGODB_TEST_URI).pre-commit run --all-files: all hooks passed.mkdocs build --strict: OK.task_originalexclusion, the projection tests fail. With_sanitize_requestoutside the discardingtry,test_create_task_unknown_fieldfails.Declined review findings
_check_inline_contentinstead of a limit (quality, low). The static helper with an explicit limit is simpler to test and reads the config only once per request.server.max_content_length. Middlewares are configured by the deployer and are trusted code._write_doc_to_db). TheSYSTEM_ERRORupdate on a deleted task has no effect.Open questions
None.
🤖 Generated with Claude Code