Repository navigation
feat!: stop serving forwarded_to - #374
Conversation
Remove `logs[].metadata.forwarded_to` (`tesForward`), replaced by the gateway tags `gateway.backend` and `gateway.backend_task_id` (#322), without a deprecation period (maintainer decision for 0.4.0). - No longer record forwards in task logs; drop `TesForward`, `Metadata` and `flatten_forwards()`; `TesTaskLog.metadata` is a string map that drops non-string values. - Serve tasks stored by earlier versions without `forwarded_to` (views `BASIC` and `FULL`), but still cancel them by their stored forwards. - Remove `custom.storeLogs`; the app and the Helm chart refuse it. - Document the breaking change in the upgrade guide. BREAKING CHANGE: tasks are served without `logs[].metadata.forwarded_to` and `custom.storeLogs` is refused; read the gateway tags instead. Closes #324 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Serve tasks stored by earlier versions without `remote_task_id` and `tes_uri` in their log metadata either, which the removed `Metadata` model dropped, and test that the projection hides them. Document that unfinished tasks stored before 0.3.0 are canceled but not tracked, and apply the remaining review fixes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
State in the 0.3.0 notes, too, that unfinished tasks stored before 0.3.0 are canceled but not tracked again, and reword a projection comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis breaking change stops recording and serving non-TES-compliant forwarded_to log metadata, uses gateway tags for forwarding information, and maintains controlled cancellation and tracking compatibility for legacy stored tasks while rejecting the removed storeLogs configuration. Sequence diagram for legacy task cancellationsequenceDiagram
participant Client
participant TaskRuns
participant Database
participant Backend
Client->>TaskRuns: cancel_task(id)
TaskRuns->>Database: load stored task
TaskRuns->>TaskRuns: _remote_task_id(document)
alt tes_endpoint.task_id exists
TaskRuns->>Backend: cancel_task(tes_endpoint.task_id)
else legacy forwarded_to exists
TaskRuns->>Backend: cancel_task(last forward id)
else remote_task_id exists
TaskRuns->>Backend: cancel_task(remote_task_id)
else malformed forward
TaskRuns-->>Client: 409 Conflict
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
4 files changed± api/index.html± configuration/index.html± reference/index.html± upgrading/index.html |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #374 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 23 23
Lines 2234 2217 -17
=========================================
- Hits 2234 2217 -17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 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="1145-1156" />
<code_context>
- # the metadata model drops `remote_task_id`, so it is read as stored
stored_logs = document.get("task", {}).get("logs") or [{}]
stored_metadata = stored_logs[0].get("metadata") or {}
+ forwards: Any = stored_metadata.get("forwarded_to")
+ # nested forwards have the next one in `forwarded_to`
+ while isinstance(forwards, dict) and isinstance(
+ forwards.get("forwarded_to"), dict
+ ):
+ forwards = forwards["forwarded_to"]
+ if isinstance(forwards, dict):
+ forwards = [forwards]
+ if isinstance(forwards, list) and forwards:
+ forward = forwards[-1]
+ if isinstance(forward, dict) and isinstance(forward.get("id"), str):
+ return forward["id"]
remote_task_id = stored_metadata.get("remote_task_id")
return remote_task_id if isinstance(remote_task_id, str) else None
</code_context>
<issue_to_address>
**Cancellation targets the wrong task**
When stored forwards are malformed and either a stale `remote_task_id` or a valid outer ID is available, `_remote_task_id` falls back to `remote_task_id` or accepts the outer forward ID, so `cancel_task` sends a stale or upstream identifier to the backend instead of returning 409.
Validate the entire forwards chain and return no remote ID whenever any present link is malformed, so `cancel_task` rejects it with 409.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="698-701" />
<code_context>
)
else:
- tasks.append(flatten_forwards(document["task"]))
+ tasks.append(document["task"])
cursor.close()
logger.debug("Listed %s tasks", len(tasks))
</code_context>
<issue_to_address>
**Legacy metadata bypasses filtering**
When a stored task contains a non-string log metadata value outside the excluded fields, `list_tasks` and `get_task` return raw task dictionaries, so `TesTaskLog.drop_non_string_metadata` does not run and responses violate the TES string-map contract.
Parse or filter tasks before returning them from `list_tasks` and `get_task` so their log metadata contains only strings.
Also at `pro_tes/ga4gh/tes/models.py:419-421`.
</issue_to_address>
### Comment 3
<location path="tests/tasks/test_track_task_progress.py" line_range="298" />
<code_context>
+ {"$set": {"task.logs.0.metadata": {"forwarded_to": forwards, "a": "b"}}},
+ )
+ run()
+ document = tasks.find_one({"worker_id": ARGS["worker_id"]})
+ assert document is not None
+ assert document["task"]["state"] == "COMPLETE"
</code_context>
<issue_to_address>
**Wrong backend task ID passes**
When the tracking code sends an incorrect `remote_task_id`, `test_stored_forwards_tracked` only checks the resulting state and metadata at lines 300–302; `FakeClient.get_task` returns `COMPLETE` for any ID, so tracking the wrong backend task still passes.
Assert that `client_class.requested` contains the expected ID in this test, or make the fake reject unexpected IDs.
</issue_to_address>Linked issues
#324 feat!: stop serving forwarded_to · 3 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Stop writing and serving metadata.forwarded_to; remove tesForward, TesForward and flatten_forwards(). |
✅ Met | New forwards are no longer written, the schema and models are removed, and legacy log metadata is filtered from task responses. |
| 2 | Keep old task forwards and remote_task_id available internally for tracking and cancellation; use tes_endpoint.task_id for new tasks. |
🟡 Partly met | Legacy forwards and remote_task_id are used for cancellation, and new tasks use tes_endpoint.task_id; however, resuming tracking requires that endpoint field, so old unfinished tasks without it are not tracked. |
| 3 | Remove custom.storeLogs. |
✅ Met | The app rejects the setting and the Helm chart refuses to render with it. |
| 4 | Document the breaking change and point users to the gateway.* tags. |
✅ Met | The upgrading guide describes the removal and maps the former log fields to gateway tags. |
| 5 | Ensure old unfinished tasks remain tracked and cancelable, and no served task has metadata.forwarded_to. |
🟡 Partly met | Legacy forwards are hidden and old tasks can be canceled, but unfinished tasks without tes_endpoint.task_id are not resumed for tracking. |
Sourcery assessment
Needs a human reviewer. 3 findings to address first, and tasks created while this version is running will no longer record the forwarding history in their logs; the gateway tags retain the backend and remote task ID, but not necessarily every hop. Reverting restores the old behavior for future tasks, but cannot reconstruct forwarding details that were never recorded.
Blocking findings: pro_tes/ga4gh/tes/task_runs.py:1156, pro_tes/ga4gh/tes/task_runs.py:701, tests/tasks/test_track_task_progress.py:298
Drop log metadata of stored tasks that is not strings when serving them, and refuse to cancel tasks with malformed stored forwards at any level (409) instead of falling back to an outer or replaced remote identifier. Check that legacy tasks are tracked by their remote identifier (Sourcery review). Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Linked issues
#324 feat!: stop serving forwarded_to · 3 of 4 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Stop writing and serving metadata.forwarded_to; remove tesForward, TesForward and flatten_forwards(). |
✅ Met | New logs no longer record forwards, old non-string metadata is filtered when serving, and the schema, models and helper are removed. |
| 2 | Keep reading stored forwards and remote_task_id internally for tracking and cancellation; new tasks use tes_endpoint.task_id. |
🟡 Partly met | Cancellation resolves legacy identifiers from stored forwards or remote_task_id, but tracking resumes only tasks with tes_endpoint.task_id, leaving older forward-only unfinished tasks untracked. |
| 3 | Remove custom.storeLogs and refuse it in the app and Helm chart. |
✅ Met | The app rejects the removed key and the chart validation fails when it is configured. |
| 4 | Document the breaking change and point clients to the gateway.* tags. |
✅ Met | The upgrade guide and API documentation describe the removal and the replacement tags. |
Summary
Removes the non-TES-compliant
logs[].metadata.forwarded_to(tesForward) in 0.4.0, without a deprecation period (maintainer decision, 2026-11-02). It is replaced by the gateway tagsgateway.backend,gateway.backend_task_idandgateway.forwarded_at(#322).TesForward,Metadataandflatten_forwards()are removed, andtesForwardis gone fromapi/additions.openapi.yaml.TesTaskLog.metadatais now a string map that drops values that aren't strings.BASICandFULL) withoutforwarded_toor the 0.2 backend referencesremote_task_idandtes_uri, using an exclusion projection. They can still be canceled:tes_endpoint.task_idis used first, then the stored forwards (as a list or as a nested object), thenremote_task_id. Malformed forwards return409; before, they failed validation with a500.custom.storeLogsis removed. The app refuses to start and the Helm chart refuses to render with it.docs/api.mdanddocs/configuration.mdare updated too.Unfinished tasks stored before 0.3.0 can be canceled but aren't tracked again. Tracking needs
tes_endpoint.task_id. This hasn't changed since 0.3.0 and is now stated consistently in the docs.Closes #324
Verification
pytest: 1105 passed, 177 skipped. Coverage is 100% (coverage run -m pytestandcoverage report).ruff format,ruff checkandmypy(70 files) report no issues.mkdocs build --strict: OK.ast-grep scan: clean. Semgrep runs in the push hook.BASICandFULL, served without backend references and canceled at the last forward;409) and legacy cancel throughremote_task_id;custom.storeLogsin the config and in the chart;forwarded_tofrom the spec;forwarded_to == nullagainst real MongoDB in CI).CI passed, tests on MongoDB 7.0 and mongomock, smoke test, chart, docs, lint, image scan, CodeQL, Codecov).Declined review findings
tes_endpoint.task_idsince 0.3.0 (fix: track tasks by rescheduled polls #288), so unfinished tasks stored before 0.3.0 keep their last state. This PR doesn't change that. Every task that 0.3.x tracks is still tracked, and pre-0.3.0 tasks can still be canceled. Resuming those tasks from their log metadata would be new behaviour, outside feat!: stop serving forwarded_to #324.Open questions
🤖 Generated with Claude Code
Summary by Sourcery
Remove forwarded task details from task logs and use gateway tags while maintaining compatible serving, cancellation, and tracking of legacy tasks.
Bug Fixes:
Enhancements:
Deployment:
Documentation:
Tests:
Chores: