Skip to content

feat: serve task provenance - #352

Merged
uniqueg merged 7 commits into
devfrom
feat/322-serve-provenance
Oct 31, 2026
Merged

uniqueg merged 7 commits into
devfrom
feat/322-serve-provenance

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Serves the provenance stored since #334, as decided in #322:

  • GET /ga4gh/tes/v1/tasks/{id}/provenance (proTES extension in api/additions.openapi.yaml, schema TaskProvenance): the task's provenance with the plugin builds (builds, by hash) and the resolved pipeline (pipeline.resolved) expanded from plugin_builds and pipelines; records that kept them inline (stored: false) are served as they are. Owners and admins only (new named rules owners-get-provenance and admins-get-provenance; owner roles on a task already cover the sub-path), others 403 as for GET /tasks/{id}; tasks without provenance (created before feat: store the provenance of tasks #334) 404 with No provenance was recorded for the task. (new ProvenanceNotFound), as chosen in the issue.
  • FOCA's gateway tags on new tasks: creation_tags() when the task is stored (plus gateway.provenance with 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 no gateway.* key. Tags and provenance are written right after the response phase and before the tracking starts, as the tracker writes the task back.
  • forwarded_to (tesTaskLog.metadata.forwarded_to, tesForward) marked deprecated: true, still written and served (removal: feat!: stop serving forwarded_to #324).
  • The tracker stores only the state and logs of 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).
  • Docs: API (endpoint, example, gateway tags table, deprecation), access control (who sees provenance, rule names), operations (served, privacy notes), upgrading.

For the release notes

  • Features: GET /tasks/{id}/provenance for owners and admins; FOCA's gateway tags on new tasks (feat: serve task provenance #322).
  • Deprecated: logs[].metadata.forwarded_to, in favour of the gateway.* tags (feat: serve task provenance #322).
  • Upgrading: custom policy lists must add owners-get-provenance/admins-get-provenance; clients re-submitting fetched tasks must drop server-written gateway.* tags (else 400).

Closes #322

Verification

Local (venv with FOCA 0.18.0):

  • ruff format, ruff check: clean; mypy: no issues in 68 files
  • coverage run -m pytest: 1040 passed, 169 skipped; coverage report: 100%
  • mkdocs build --strict: clean
  • semgrep (.semgrep) and ast-grep (sgconfig.yml): no findings
  • regression test test_gateway_tags_tracked fails against the previous whole-task upsert in _store_final and passes with the fix

pre-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

uniqueg and others added 5 commits October 31, 2026 12:14
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]>
@sourcery-ai

sourcery-ai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implements 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 forwarded_to, adds access-control and upgrade documentation, and provides broad API and regression test coverage.

Sequence diagram for serving expanded task provenance

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

Sequence diagram for gateway tags during task forwarding

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

File-Level Changes

Change Details Files
Adds an owner/admin-protected provenance retrieval endpoint that expands stored plugin-build and pipeline references while preserving inline records and distinguishing missing provenance from missing tasks.
  • Registers the proTES OpenAPI endpoint and TaskProvenance schema.
  • Adds owner/admin policies, configuration, exception mapping, and controller/service retrieval logic.
  • Expands referenced builds and resolved pipelines from shared collections and covers authorization, not-found, and legacy-record behavior with tests.
pro_tes/api/additions.openapi.yaml
pro_tes/config.yaml
pro_tes/exceptions.py
pro_tes/ga4gh/tes/server.py
pro_tes/ga4gh/tes/task_runs.py
docs/access-control.md
docs/api.md
docs/upgrading.md
tests/ga4gh/tes/test_provenance_api.py
Integrates FOCA gateway tags into task creation and routing while preventing server tags from being forwarded to backend TES instances.
  • Adds creation tags, including the provenance URL, after the task identifier is assigned.
  • Adds routing tags after forwarding, including accepted and outcome-unknown attempts, without failing task creation when tag construction errors.
  • Preserves client tags, strips reserved server tags before relay, and documents tag behavior and client re-submission requirements.
pro_tes/ga4gh/tes/task_runs.py
docs/api.md
docs/operations.md
docs/upgrading.md
tests/ga4gh/tes/test_provenance_api.py
tests/ga4gh/tes/test_plugins.py
Prevents task tracking from overwriting tags written during forwarding and deprecates the legacy forwarding metadata in favor of gateway tags.
  • Limits final tracking persistence to state and logs so concurrent tag updates survive.
  • Marks forwarded_to and tesForward deprecated while retaining their existing behavior.
  • Adds regression coverage for tag preservation and updates API/configuration documentation.
pro_tes/tasks/track_task_progress.py
pro_tes/api/additions.openapi.yaml
docs/api.md
docs/configuration.md
docs/operations.md
tests/ga4gh/tes/test_provenance_api.py

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 Oct 31, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35545739 | 📁 Comparing 3aa6c9b against latest (ed3a119)

  🔍 Preview build  

6 files changed · ± 6 modified

± Modified

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ed3a119) to head (3aa6c9b).

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

@uniqueg
uniqueg marked this pull request as ready for review October 31, 2026 13:45

@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 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


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

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

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.

Comment thread pro_tes/api/additions.openapi.yaml Resolved
@uniqueg
uniqueg merged commit 4244881 into dev Oct 31, 2026
19 checks passed
@uniqueg
uniqueg deleted the feat/322-serve-provenance branch October 31, 2026 14:19
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.

feat: serve task provenance

1 participant