Skip to content

feat: store the provenance of tasks - #349

Merged
uniqueg merged 6 commits into
devfrom
feat/334-task-provenance
Oct 31, 2026
Merged

uniqueg merged 6 commits into
devfrom
feat/334-task-provenance

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Stores the provenance of each task's plugin pipeline run, as decided in #321 (step 6) and #334, with FOCA 0.18's foca.plugins.ProvenanceStore:

  • provenance in the task document: the prospective part (engine versions, request ID, pipeline source and hash, plugins, hook executions, route, client selection) when the task is stored, after routing; replaced with the attempts and the final reason once a backend accepted the task, or may have (SYSTEM_ERROR, final_reason: outcome_unknown). Errors while updating it are logged, never fail an accepted task.
  • New collections in taskStore (declared in config.yaml): plugin_builds and pipelines (keyed by hash, no index, as FOCA documents) and failed_runs with FOCA's TTL index (failed_at, 30 days, FAILURE_INDEXES).
  • Failed runs (rejected by plugins, no backend, forward timeout, ...) go to failed_runs only if plugins.provenance.record_failed (FOCA's default: off). Requests refused before the run starts (invalid tasks, loops, invalid gateway.* tags) have no run and no record.
  • The provenance is not served yet (feat: serve task provenance #322): the BASIC/FULL views and the task tracking (DbDocumentConnector) don't load it (projections), so up-to-1-MiB records don't slow listing or polling.
  • Docs: operations (fields, collections, retention and how to change it with collMod, queries), configuration (plugins.provenance), upgrading (new collections; older tasks have no provenance).

For the release notes

  • Features: tasks store the provenance of their plugin pipeline; records of failed pipeline runs with plugins.provenance.record_failed (feat: store the provenance of tasks #334).
  • Upgrading: three new collections (plugin_builds, pipelines, failed_runs with a TTL index); tasks created before have no provenance.

Closes #334

Verification

  • coverage run -m pytest: 1016 passed, 142 skipped (Helm not installed locally; chart tests run in CI); coverage report: 100%.
  • ruff check ., ruff format --check ., mypy: clean; ast-grep scan, ast-grep test --skip-snapshot-tests, semgrep scan --config=.semgrep --error: clean.
  • mkdocs build --strict: OK.
  • Not run locally: pre-commit run --all-files (hook repos can't be fetched through the sandbox proxy; its ruff, mypy, ast-grep and semgrep hooks were run directly), gitleaks, actionlint (no workflow changes); tests against real MongoDB (CI runs MongoDB 7.0).
  • CI: all checks passed (Lint, Test (MongoDB 7.0), Test (mongomock), Chart, Docs, Smoke test, Release readiness, Scan image, CodeQL, Read the Docs; image push/publish skipped on PRs).

Declined review findings

  • Adversarial (low): if storing the backend of an accepted task fails (_update_doc_in_db), its provenance keeps only the prospective part. Reporting the attempt earlier would run the response plugins before the backend is stored (task no longer cancelable if the instance stops). The client gets a 500 in that case anyway.
  • Adversarial (low): failure records are keyed by the client's X-Request-ID (FOCA's save_failure), so clients can replace records of requests whose ID they know. That is FOCA's design and can't change on FOCA 0.18; documented in docs/operations.md with the advice to have the reverse proxy set X-Request-ID. Worth a FOCA follow-up (key by run ID, keep the request ID as a field).
  • Quality (low): ProvenanceStore.save runs at creation and again with the attempts, repeating idempotent upserts of builds and pipelines (a few small writes per task).

Fixed from review: response-phase errors are no longer recorded as failed runs; the store is created only by POST /tasks, so other endpoints don't depend on its collections; attempts of tasks that a backend may have accepted are stored also if storing their state fails; more tests (unstorable builds, response-phase errors); docs wording.

Sourcery review (2 threads): fixed the order in _forwarded (e5d5917: the accepted attempt is reported right after the backend is stored, so the provenance has it also if starting the tracking fails); declined the 16 MiB BSON concern (request bodies are limited to 1 MiB, records to 1 MiB, and the provenance is written before any logs exist).

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Store and document task pipeline provenance, with optional records for failed runs and safe handling of provenance persistence errors.

New Features:

  • Store plugin pipeline provenance for each newly created task, including pipeline metadata, plugin executions, routing, backend attempts, and final outcomes.
  • Optionally retain provenance for failed pipeline runs in a dedicated collection when enabled by configuration.

Enhancements:

  • Exclude potentially large provenance records from task listing, retrieval, and tracking projections while retaining them in task documents.
  • Persist shared plugin builds and administrative pipelines by hash and tolerate provenance storage failures without failing task creation or accepted tasks.

Build:

  • Declare provenance collections in the default database configuration, including a 30-day TTL index for failed runs.

Documentation:

  • Document provenance fields, retention, configuration, querying, and upgrade requirements.

Tests:

  • Add coverage for successful and failed runs, backend failover, unknown outcomes, storage failures, lazy collection use, and projection behavior.

uniqueg and others added 4 commits October 31, 2026 06:42
Store the provenance of each task's pipeline run with the task
(`provenance`), via FOCA's ProvenanceStore: the prospective part when
the task is stored, replaced with the attempts once a backend accepted
it (or may have). Plugin builds and default and preset pipelines are
stored once, by hash, in `plugin_builds` and `pipelines`; failed runs
go to `failed_runs` (TTL index, 30 days) only if
`plugins.provenance.record_failed` is on.

Task views and the task tracking don't load the provenance.

Refs #334

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Operations (fields, collections, retention of failed runs, queries),
configuration (`plugins.provenance`) and upgrading (new collections,
older tasks without provenance).

Refs #334

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Errors of the response phase leave a task that runs at its backend, so
they are not recorded as failed runs. Tests for that, for plugin builds
that can't be stored, and docs fixes from the review.

Refs #334

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Create the provenance store on first use, so that only POST /tasks
needs its collections; store the attempts of tasks that a backend may
have accepted also if storing their state fails. Docs: clients choose
the identifiers of failure records.

Refs #334

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

Adds FOCA-backed task pipeline provenance, including prospective and retrospective task records, optional failed-run retention, shared plugin and pipeline documents, and MongoDB TTL configuration. Task creation now persists and updates provenance without making accepted-task handling dependent on provenance writes, while projections keep large records out of API views and tracking; documentation, upgrade guidance, and extensive tests cover the new behavior.

Sequence diagram for task provenance lifecycle

sequenceDiagram
    actor Client
    participant API as POST /tasks
    participant Pipeline as PipelineRun
    participant Provenance as ProvenanceStore
    participant Tasks as MongoDB tasks
    participant Backend as TES backend

    Client->>API: create_task
    API->>Pipeline: start
    Pipeline-->>API: run
    API->>Pipeline: route
    API->>Provenance: save(run)
    Provenance-->>API: prospective provenance
    API->>Tasks: insert task with provenance
    API->>Backend: forward task
    Backend-->>API: accepted
    API->>Pipeline: succeeded
    API->>Provenance: save(run)
    Provenance-->>API: attempts and final outcome
    API->>Tasks: update provenance
    API-->>Client: task response
Loading

Flow diagram for failed pipeline run recording

flowchart TD
    A[POST /tasks] --> B[start pipeline]
    B --> C{Pipeline run fails?}
    C -->|No| D[Store task with provenance]
    C -->|Yes| E{record_failed enabled?}
    E -->|No| F[Raise GatewayError]
    E -->|Yes| G[ProvenanceStore.save_failure]
    G --> H[failed_runs with failed_at]
    H --> I[TTL deletion after 30 days]
    F --> J[No task stored]
    H --> J
Loading

Flow diagram for projected task access

flowchart TD
    Request[Task listing or tracking] --> Query[MongoDB query]
    Query --> Projection[TASK_PROJECTION]
    Projection --> Result[Task data without provenance]
    Detail[Internal task lookup or update] --> Projection
    Result --> API[API views and task tracking]
Loading

File-Level Changes

Change Details Files
Integrate FOCA provenance capture into task creation, forwarding, and failure handling.
  • Create a lazily initialized ProvenanceStore for task POSTs.
  • Persist prospective provenance after routing and update it with backend attempts and final outcomes.
  • Record failed pipeline runs conditionally, while preserving accepted tasks when response or database updates fail.
  • Capture outcome-unknown attempts as SYSTEM_ERROR provenance.
pro_tes/ga4gh/tes/task_runs.py
Extend task persistence and database configuration for provenance data and retention.
  • Add optional provenance to task documents.
  • Declare shared plugin-build, pipeline, and failed-run collections.
  • Configure the 30-day TTL index for failed runs.
  • Exclude potentially large provenance records from task views and tracking projections.
pro_tes/ga4gh/tes/models.py
pro_tes/utils/db.py
pro_tes/config.yaml
Document provenance behavior, configuration, operations, retention, and upgrade requirements.
  • Describe stored fields, shared collections, failed-run behavior, secret headers, and query examples.
  • Document the record_failed option and TTL customization.
  • Explain new collections and compatibility for tasks created by earlier versions.
docs/configuration.md
docs/operations.md
docs/upgrading.md
Add comprehensive coverage for provenance storage, failure modes, projections, and collection lifecycle.
  • Test accepted, failover, rejected, no-backend, and outcome-unknown runs.
  • Verify failed-run opt-in, TTL configuration, deduplicated shared records, and unwritable stores.
  • Verify response failures preserve tasks and that non-POST endpoints do not require provenance collections.
tests/ga4gh/tes/test_provenance.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 #35542561 | 📁 Comparing 9c5f5c0 against latest (22c1001)

  🔍 Preview build  

4 files changed
± configuration/index.html
± operations/index.html
± reference/index.html
± upgrading/index.html

@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 (22c1001) to head (9c5f5c0).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #349   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         2136      2168   +32     
=========================================
+ Hits          2136      2168   +32     

☔ 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 08:08

@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="531" />
<code_context>
             },
         )
         response.client_payload = {"id": db_document.task.id}
-        response = attempt.succeeded(response, remote_id=remote_task_id)
+        try:
+            response = attempt.succeeded(response, remote_id=remote_task_id)
</code_context>
<issue_to_address>
**Accepted tasks lose backend provenance**

When the backend accepts a task but Celery raises while enqueueing progress tracking, `_forwarded` reaches its provenance `try/finally` only after enqueueing, so `_update_provenance` does not save the backend attempt and the caller gets an error while the stored task retains only prospective provenance.

Move the provenance `try/finally` so it also covers enqueueing progress tracking.

Also at `pro_tes/ga4gh/tes/task_runs.py:533-534`.
</issue_to_address>

### Comment 2
<location path="pro_tes/ga4gh/tes/task_runs.py" line_range="327" />
<code_context>
+        # the prospective part of the provenance (pipeline, plugins, route),
+        # stored with the task; the attempts are added once a backend
+        # accepted the task, or may have (cf. `_update_provenance`)
+        db_document.provenance = self.provenance.save(run)

         # create database document
</code_context>
<issue_to_address>
**Large tasks fail to be created**

When the task document is close enough to MongoDB’s 16 MiB BSON limit that adding provenance exceeds it, `self.provenance.save(run)` adds provenance to the BSON document that `_write_doc_to_db` inserts, so MongoDB rejects the insert and the caller gets an error instead of a created task.

Avoid adding provenance to the task’s BSON document when doing so would exceed MongoDB’s size limit.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and if provenance capture is wrong, task documents can retain inaccurate pipeline, plugin, or forwarding history after the code is reverted; failed-run records also persist for up to 30 days. This does not change task execution, but correcting the historical metadata may require deleting or repairing stored records.

Blocking findings: pro_tes/ga4gh/tes/task_runs.py:531, pro_tes/ga4gh/tes/task_runs.py:327


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
uniqueg and others added 2 commits October 31, 2026 09:34
Report the accepted attempt (and run the response phase) right after
the backend is stored, so that the provenance has it also if starting
the tracking fails; errors of the response phase are raised once the
task is tracked (Sourcery review).

Refs #334

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 88c9ac0 into dev Oct 31, 2026
19 checks passed
@uniqueg
uniqueg deleted the feat/334-task-provenance branch October 31, 2026 09:18
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: store the provenance of tasks

1 participant