Repository navigation
feat: store the provenance of tasks - #349
Conversation
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]>
Reviewer's GuideAdds 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 lifecyclesequenceDiagram
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
Flow diagram for failed pipeline run recordingflowchart 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
Flow diagram for projected task accessflowchart 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]
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± configuration/index.html± operations/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 #349 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 23 23
Lines 2136 2168 +32
=========================================
+ Hits 2136 2168 +32 ☔ 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="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
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]>
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:provenancein 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.taskStore(declared inconfig.yaml):plugin_buildsandpipelines(keyed by hash, no index, as FOCA documents) andfailed_runswith FOCA's TTL index (failed_at, 30 days,FAILURE_INDEXES).failed_runsonly ifplugins.provenance.record_failed(FOCA's default: off). Requests refused before the run starts (invalid tasks, loops, invalidgateway.*tags) have no run and no record.BASIC/FULLviews and the task tracking (DbDocumentConnector) don't load it (projections), so up-to-1-MiB records don't slow listing or polling.collMod, queries), configuration (plugins.provenance), upgrading (new collections; older tasks have no provenance).For the release notes
plugins.provenance.record_failed(feat: store the provenance of tasks #334).plugin_builds,pipelines,failed_runswith 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.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).Declined review findings
_update_doc_in_db), its provenance keeps only the prospective part. Reporting the attempt earlier would run theresponseplugins before the backend is stored (task no longer cancelable if the instance stops). The client gets a500in that case anyway.X-Request-ID(FOCA'ssave_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 indocs/operations.mdwith the advice to have the reverse proxy setX-Request-ID. Worth a FOCA follow-up (key by run ID, keep the request ID as a field).ProvenanceStore.saveruns 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:
Enhancements:
Build:
Documentation:
Tests: