Repository navigation
feat: serve task provenance - #352
Conversation
Add GET /tasks/{id}/provenance (proTES extension), for owners and
admins (rules owners-get-provenance and admins-get-provenance): the
stored provenance with its plugin builds and pipeline expanded; 404 for
tasks without provenance. New tasks get FOCA's gateway tags, at creation
and after forwarding (written before the tracking starts); relayed
tasks still have none. forwarded_to is marked deprecated in the spec.
Refs #322
Co-Authored-By: Claude Opus 5.5 <[email protected]>
API (endpoint, gateway tags, deprecation of forwarded_to), access control (who gets the provenance), operations and upgrading. Refs #322 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Get the gateway.provenance tag from FOCA's creation_tags() once the task identifier is drawn, instead of composing it in proTES. Tests that the tracking keeps the tags and that admins can be denied the provenance; docs and spec say admins get 404 for unknown tasks, forwarded_to is deprecated in the configuration page too (quality review). Refs #322 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tracker stores only the state and logs of a finished task, so that tags written after it read the task are kept. Tasks are also created if FOCA can't build their gateway tags. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document that tracking keeps the tags of a task, and that tasks may lack the tags of the stored task if they can't be built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideImplements provenance serving for task owners and admins, expands shared provenance references at read time, and adds FOCA gateway tags throughout task creation and routing. The change also preserves tags across tracking updates, retains but deprecates Sequence diagram for serving expanded task provenancesequenceDiagram
participant Caller
participant GetTaskProvenance
participant TaskRuns
participant TaskDB
participant SharedData
Caller->>GetTaskProvenance: GetTaskProvenance(id)
GetTaskProvenance->>TaskRuns: get_task_provenance(id)
TaskRuns->>TaskDB: Find task projection with provenance
alt task missing
TaskDB-->>TaskRuns: no document
TaskRuns-->>Caller: TaskNotFound 404
else provenance missing
TaskDB-->>TaskRuns: document without provenance
TaskRuns-->>Caller: ProvenanceNotFound 404
else provenance recorded
TaskDB-->>TaskRuns: provenance record
TaskRuns->>SharedData: Resolve pipeline and plugin builds by hash
SharedData-->>TaskRuns: Expanded references
TaskRuns-->>Caller: TaskProvenance 200
end
Sequence diagram for gateway tags during task forwardingsequenceDiagram
participant Client
participant TaskRuns
participant TES
participant TaskDB
participant Tracker
Client->>TaskRuns: Create task
TaskRuns->>TaskRuns: without_server_tags
TaskRuns->>TaskDB: Store task with creation_tags
TaskRuns->>TES: Forward task without gateway tags
TES-->>TaskRuns: Accepted or outcome unknown
TaskRuns->>TaskDB: _update_records with routing_tags and provenance
TaskRuns->>Tracker: Start task__track_task_progress
Tracker->>TaskDB: _store_final with state and logs only
TaskDB-->>Tracker: Preserve gateway tags
File-Level Changes
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 #352 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 23 23
Lines 2168 2209 +41
=========================================
+ Hits 2168 2209 +41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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="591-593" />
<code_context>
"""
try:
+ tags = {**(db_document.task.tags or {}), **routing_tags(run)}
self.db_client.update_one(
- {"worker_id": worker_id},
- {"$set": {"provenance": self.provenance.save(run)}},
+ {"worker_id": db_document.worker_id},
+ {"$set": {"provenance": self.provenance.save(run), "task.tags": tags}},
)
except Exception as exc:
</code_context>
<issue_to_address>
**Forwarding provenance is lost**
When mongoDB or a provenance-store write fails during `_update_records` after a backend has accepted the task, `_update_records` catches the database error and does not retry, so the already-accepted task keeps only its earlier provenance and creation tags; the attempt details and routing tags are permanently absent even after the database recovers.
Retry or otherwise repair the provenance and routing-tag write after transient storage failures, without failing the already-accepted task.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="590" />
<code_context>
+ db_document: The stored task, with its tags.
"""
try:
+ tags = {**(db_document.task.tags or {}), **routing_tags(run)}
self.db_client.update_one(
- {"worker_id": worker_id},
</code_context>
<issue_to_address>
**Forwarding attempts disappear**
When FOCA's `routing_tags(run)` raises while processing a task that a backend accepted or may have accepted, `routing_tags(run)` raises before `self.provenance.save(run)` is called, and the broad handler logs and suppresses the error. The task then retains its pre-forward provenance, so callers see a provenance record without the forwarding attempt.
Save the updated provenance independently of routing-tag generation, or handle tag-generation failure separately so it cannot prevent the provenance update.
</issue_to_address>Linked issues
#322 feat: serve task provenance · 3 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Serve task provenance to owners and admins; return 404 to others and for tasks without provenance. | 🟡 Partly met | Owners and admins can fetch provenance, and tasks without provenance return 404, but non-owners are explicitly denied with 403 rather than the acceptance criterion's 404. |
| 2 | Expand the stored plugin-build and pipeline references, while keeping client pipelines inline. | ✅ Met | The endpoint resolves missing builds and pipeline data from the shared collections; inline records are retained. |
| 3 | Add the gateway tags to new tasks, serve them in BASIC and FULL views, and keep them off relayed tasks. | ✅ Met | Creation and routing tags are added, and the tests cover both task views and relayed tasks. |
| 4 | Keep forwarded_to served and mark it deprecated in the spec, docs, and release notes. | 🟡 Partly met | The spec and docs mark it deprecated and the change leaves existing serving in place, but no release note is added in the diff. |
| 5 | Document provenance retention, privacy, and record_failed behavior. | ✅ Met | The operations documentation describes retention with the task and privacy; it also documents record_failed. |
Sourcery assessment
Needs a human reviewer. 2 findings to address first, and the default admins-get-provenance rule lets admins retrieve a task’s plugin builds, resolved pipeline, and backend-attempt history. Removing the rule can stop future reads, but it cannot undo disclosures that already happened; this is an access-policy decision, not just a reversible API bug.
Blocking findings: pro_tes/ga4gh/tes/task_runs.py:593, pro_tes/ga4gh/tes/task_runs.py:590
If FOCA can't build the routing tags of a task, its provenance with the attempts is stored nevertheless (Sourcery review of #352). Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Linked issues
#322 feat: serve task provenance · 6 of 7 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Serve task provenance with plugin builds and resolved pipelines expanded; return 404 when provenance is absent. | ✅ Met | The endpoint expands references from the shared collections, preserves inline values, and returns the specified 404 detail when a record is missing. |
| 2 | Allow owners and admins to get provenance; return 404 to others, following the task endpoint's ownership behavior. | 🟡 Partly met | Owners and admins are authorized, but non-owner, non-admin callers receive 403 rather than the acceptance criterion's 404. |
| 3 | Store plugin builds and pipelines in shared collections, with client pipelines inline. | ✅ Met | FOCA's ProvenanceStore is configured with the plugin_builds and pipelines collections, and the endpoint expands those references. |
| 4 | Add the specified gateway tags to new tasks, serve them in BASIC and FULL views, and keep them off relayed tasks. | ✅ Met | Creation and routing tags are added at their respective stages; the tests check both task views and that relayed tasks have no gateway tags. |
| 5 | Keep forwarded_to served and written while marking it deprecated. | ✅ Met | The OpenAPI schema marks both forwarded_to and tesForward as deprecated; existing forwarding metadata handling remains. |
| 6 | Document the API, access control, provenance privacy and retention, and record_failed behavior. | ✅ Met | The API, access-control, and operations docs cover these topics, including the record_failed option. |
| 7 | Test the endpoint, tags, and deprecation flag, with 100% coverage. | ✅ Met | Tests cover the endpoint, tags, and deprecated schema fields; the PR verification reports 100% coverage. |
Summary
Serves the provenance stored since #334, as decided in #322:
GET /ga4gh/tes/v1/tasks/{id}/provenance(proTES extension inapi/additions.openapi.yaml, schemaTaskProvenance): the task'sprovenancewith the plugin builds (builds, by hash) and the resolved pipeline (pipeline.resolved) expanded fromplugin_buildsandpipelines; records that kept them inline (stored: false) are served as they are. Owners and admins only (new named rulesowners-get-provenanceandadmins-get-provenance; owner roles on a task already cover the sub-path), others403as forGET /tasks/{id}; tasks without provenance (created before feat: store the provenance of tasks #334)404withNo provenance was recorded for the task.(newProvenanceNotFound), as chosen in the issue.creation_tags()when the task is stored (plusgateway.provenancewith the task's provenance path, set once the identifier is drawn),routing_tags()with the backend update (accepted or outcome unknown). The client's tags are kept (without_server_tags), relayed tasks still carry nogateway.*key. Tags and provenance are written right after theresponsephase and before the tracking starts, as the tracker writes the task back.forwarded_to(tesTaskLog.metadata.forwarded_to,tesForward) markeddeprecated: true, still written and served (removal: feat!: stop serving forwarded_to #324).stateandlogsof a finished task, so tags written after it read the task (e.g., the routing tags of a task that a resumed poll found finished while it was created) are kept. Tasks are still created if FOCA can't build their creation tags (logged, documented).For the release notes
GET /tasks/{id}/provenancefor owners and admins; FOCA's gateway tags on new tasks (feat: serve task provenance #322).logs[].metadata.forwarded_to, in favour of thegateway.*tags (feat: serve task provenance #322).owners-get-provenance/admins-get-provenance; clients re-submitting fetched tasks must drop server-writtengateway.*tags (else400).Closes #322
Verification
Local (venv with FOCA 0.18.0):
ruff format,ruff check: clean;mypy: no issues in 68 filescoverage run -m pytest: 1040 passed, 169 skipped;coverage report: 100%mkdocs build --strict: clean.semgrep) and ast-grep (sgconfig.yml): no findingstest_gateway_tags_trackedfails against the previous whole-task upsert in_store_finaland passes with the fixpre-commit itself couldn't fetch its hook repositories through the sandbox proxy; its hooks were run directly as above.
CI: all checks passed (CI passed, Test (MongoDB 7.0), Test (mongomock), Lint, Docs, Chart, Smoke test, Scan image, CodeQL, codecov).
Declined review findings
None. Two review rounds (adversarial and quality reviewer subagents); all findings fixed (round 1: docs lists and wording, FOCA creation tags, tests, a stale-read race in
_store_final; round 2: field selection in_store_final, docs on tracking and missing tags, wrapping).Sourcery: storing the attempts independently of the routing tags fixed (f45ff54); declined retrying the record writes after database errors (best effort by design: the backend has the task, errors are logged with the worker ID). Declined answering others with 404 instead of 403: GET /tasks/{id} answers them 403 (also for unknown tasks), and the issue asks for the same behaviour.
Open questions
None.
🤖 Generated with Claude Code