Skip to content

G3-801: manage tool runs (list, delete, rerun, download) and describe each tool's form - #43

Open
belkassaby wants to merge 2 commits into
mainfrom
feat/G3-801-tool-run-management
Open

belkassaby wants to merge 2 commits into
mainfrom
feat/G3-801-tool-run-management

Conversation

@belkassaby

@belkassaby belkassaby commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes G3-801. The run endpoints were already on main (POST /tools/{tool}, GET /tools/runs/{id}); this adds what the ticket still asked for: run listing, delete, rerun, result download, data-driven tool forms, field-level validation errors, and the requirements inherited from G3-800 (access on read, diagnosable failures, retention, the legacy compatibility contract).

AsyncTask, as read from its code

Runs live in AsyncTask and v3 keeps no run table, so everything here goes through AsyncTask's API as the user. The ticket asks for its guarantees to be established from its code, not assumed. At 5f2acea, the build dev runs:

Need What AsyncTask does So v3
List my runs GET /runs: the caller's runs of every plugin, with no tool name or request, and no paging keeps runs whose workflow id is ats:GeneWeaverTools:…, joins GET /inputs, and pages itself
Filter by workflow GET /runs?workflow_id= returns the run without checking its owner never uses it; filed as G3-838
Delete DELETE /runs/{id} refuses a run that still has a result, and doesn't stop a running workflow cancels if running, deletes the result, then the run
Rerun POST /runs with input_id reuses the stored envelope resubmits the recorded request through our own gate; ABBA and Similar gene sets carry a signed identity that expires after 6 h
Why a run failed nothing stored; a failed run is only a status reports what is known (see Failures)
Retention none per user (see Retention)

Changes

  • Run record (services/run_record.py): every submission stores its request (tool, gene sets, parameters) as JSON in the AsyncTask input's description, which GET /inputs returns. It is what lets a run be listed by tool, rerun, and access-checked on read. No AsyncTask change is needed.

  • GET /tools/runs: the caller's runs, newest first, paged (limit up to 100, offset). Each has its tool, name, gene sets, status, stalled, problem, created and can_rerun.

  • DELETE /tools/runs/{id}, and DELETE /tools/runs?older_than_days=N for the caller's old runs.

  • POST /tools/runs/{id}/rerun: validates the recorded request as the endpoint would (2–20 distinct gene sets), then goes through the same access gate and input resolvers as a new run, so changed access or gene set contents apply. It answers in the generic shape, including for UpSet (not POST /tools/upset's typed UpSetResult). It answers as the run endpoints do (202 with the new run_id) and adds rerun_of.

  • Access on read (G3-736): GET /tools/runs/{id} checks that the caller can still read the run's gene sets, and answers 403 otherwise. ABBA and Similar gene sets results also leave out gene sets the caller can no longer read, counted in withheld_genesets (one query: new geneset.readable_ids, using the shared readable rule). The record is the input's description, which its owner can rewrite in AsyncTask (PATCH /inputs/{id}). So the tool is taken from the submitted envelope, which can't be changed, a record naming a different tool is ignored, and every gene set named by either the envelope or the record is checked. Runs from before this change are read by their envelope, wherever each tool keeps its gene sets (geneset_ids, Triclique's groups, PhenomeMap's gene_sets, MSET's universe). A completed run whose gene sets still can't be found is refused with 409 rather than returned unchecked. Runs of other AsyncTask plugins are 404.

  • Failures (G3-739): decided not to read Temporal from the API; it talks only to AsyncTask. A failed, cancelled, terminated or timed-out run carries a problem saying what is known. A run still running after TOOL_RUN_STALLED_AFTER_MINUTES (45) is flagged stalled: the tool activity is bounded at about 30 min, but AsyncTask sets no workflow timeout, so a run whose workflow never starts runs forever. Recording the cause and bounding the workflow are AsyncTask's to fix: G3-839.

  • Retention: runs older than TOOL_RUN_RETENTION_DAYS (90) are deleted, as the caller, when they list their runs (0 or less turns expiry off). Only a run's owner may delete it, so a user who never lists again keeps their runs until AsyncTask expires runs itself.

  • GET /tools/runs/{id}/download?format=…&table=…:

    • JSON for every tool;
    • CSV or TSV for each tool's tables: Jaccard and HyperGeometric pairs (by gene set id, not position), UpSet intersections, Boolean Algebra's answer, DBSCAN clusters, PhenomeMap nodes, ABBA's gene sets and genes, Similar gene sets' list with legacy's export columns;
    • Combine's matrix as legacy's .odemat;
    • the clustering tree as Newick.

    Legacy's figures were rendered in the browser, and so are v3's charts, which the page downloads as SVG.

  • GET /tools/{tool}: the tool's form fields from odestatic.tool / tool_param (new geneweaver.db.tool). Each is mapped to the name and type v3 takes, e.g. DBSCAN_minPts becomes min_points and "Included" becomes true, and carries its label, description, default, choices, widget and legacy name. Also returned: the visible legacy options v3 does not offer, with why (PhenomeMap's MaxInNode, permutations and emphasis; Triclique's methods), and the JSON Schema of the threshold options. GET /tools adds each tool's legacy name, description and order. Similar gene sets is described but not listed, since the Analyze page offers every listed tool.

  • 422s keep detail (the message the page shows) and add errors: [{loc, msg, type}], located at the request field, e.g. ["body", "parameters", "method"].

  • Legacy /api/tool/get/{file,link,status}: documented, not served.

    • They authenticate with the legacy API key in the URL path; status takes no credential at all.
    • They point at the public /results/ directory.
    • v3 runs sit behind the user's Auth0 token in AsyncTask and produce data, not files. Legacy keeps serving them for legacy runs.

    Recorded in docs/v3/V3_ROADMAP_AND_GAP.md (A4).

Testing

  • pytest tests: 887 passed, 33 skipped. The one failure, test_first_party_subpackage_is_importable[client], also fails before this change (geneweaver.client isn't installed locally).
  • packages/db/tests/unit: 56,542 passed. packages/tools/tests/unit: 300 passed, 5 skipped. packages/tools-plugin: 62 passed.
  • ruff check and ruff format --check are clean on every changed file.
  • The tests:
    • Run management is tested against a fake AsyncTask that answers as 5f2acea does and records every call, including the order a delete must follow.
    • Downloads are tested on real tool outputs (UpSet, Jaccard, Combine, Boolean Algebra, DBSCAN, Clustering), passed through JSON as AsyncTask stores them.
    • The catalog is tested on dev's actual tool_param rows, typos and placeholders included, and was also run over the live rows from dev.
  • Every new route and schema appears in /api/openapi.json.
  • Independent review (bcc5af3 fixes its findings):
    • It found no cross-user path, and checked each AsyncTask call's shape against 5f2acea.
    • It found the editable-record gap described above, missing gene set keys for MSET, PhenomeMap and Triclique, a rerun skipping the request schema, Boolean Algebra's intersect downloading the union, and retention 0 deleting everything. Each is fixed, with a regression test.
  • Assumption, not verified: AsyncTask stores init_time as a timestamp without a time zone, and v3 reads a naive time as UTC. That's right only while the Cloud SQL TimeZone is UTC (the default). Otherwise stalled detection and retention shift by the offset.
  • Not yet done on dev: an end-to-end pass of list, rerun, download and delete against the deployed AsyncTask.

…be each tool's form (G3-801)

Finishes G3-801: the run endpoints existed; managing runs did not.

Runs live in AsyncTask and v3 keeps no run table, so everything goes through AsyncTask's API
as the user. Its guarantees were read from its code at 5f2acea, the build dev runs:
GET /runs lists every plugin's runs, with no tool or request; DELETE /runs/{id} refuses a
run that still has a result and does not stop a running workflow; a failed run is only a
status; nothing is ever expired; and GET /runs?workflow_id= returns a run without checking
its owner, so it is never used.

- Each submission records its request (tool, gene sets, parameters) as the AsyncTask
  input's description (services/run_record.py), which GET /inputs returns. That record
  is what lets runs be listed by tool, rerun, and access-checked on read.
- GET /tools/runs: the caller's GeneWeaver runs (told apart by workflow id), newest
  first, paged, each with its tool, gene sets, status, stalled and problem, can_rerun.
  Runs older than TOOL_RUN_RETENTION_DAYS (90) are deleted first, as the caller: only a
  run's owner may delete it, so retention is per user.
- DELETE /tools/runs/{id} cancels a running run, deletes its result, then the run;
  DELETE /tools/runs?older_than_days=N deletes the caller's old runs.
- POST /tools/runs/{id}/rerun resubmits the recorded request through the same gate and
  resolvers; ABBA and Similar gene sets are signed again, as their identity expires.
- GET /tools/runs/{id} re-checks access on read (G3-736): the caller must still read the
  run's gene sets, and gene sets an ABBA or Similar gene sets result names that they can
  no longer read are withheld (geneset.readable_ids, the shared readable rule). A
  completed run whose gene sets cannot be found is refused rather than returned.
- Failures (G3-739): AsyncTask records no reason and sets no workflow timeout, so a run
  whose workflow never starts runs forever. The API reports what is known: a problem for
  each failed status, and stalled past TOOL_RUN_STALLED_AFTER_MINUTES (45). It does not
  read Temporal; recording the cause and bounding the workflow belong in AsyncTask.
- GET /tools/runs/{id}/download: JSON for every tool, CSV/TSV for each tool's tables,
  Combine's matrix as legacy's .odemat, the clustering tree as Newick. Legacy's figures
  were rendered in the browser, as v3's charts are.
- GET /tools/{tool} describes a tool from odestatic.tool and tool_param, mapped to the
  names and types v3 takes (DBSCAN_minPts -> min_points, "Included" -> true), with the
  visible legacy options v3 does not offer listed with why, and the threshold options'
  JSON Schema. GET /tools adds each tool's legacy name, description and order.
- A 422 keeps its detail message and adds errors: [{loc, msg, type}], located at the
  request field (["body", "parameters", "method"]), so the page can mark the field.
- The legacy /api/tool/get/{file,link,status} routes are not served: they authenticate
  with the legacy API key and point at public result files, while v3 runs sit behind the
  user's Auth0 token and produce data. Recorded in the roadmap (A4).
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Test Coverage Report

============================= test session starts ==============================
platform linux -- Python 3.11.18, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/runner/work/geneweaver/geneweaver
configfile: pyproject.toml
plugins: anyio-4.13.0, cov-4.1.0, asyncio-1.3.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 921 items

tests/controllers/test_api_standards.py ................................ [  3%]
........................................................................ [ 11%]
.............................................................sssssssssss [ 19%]
ssssssssssssssssssssss                                                   [ 21%]
tests/controllers/test_genes.py .............                            [ 22%]
tests/controllers/test_genesets.py ..................................... [ 26%]
.....................                                                    [ 29%]
tests/controllers/test_genesets_search.py ......................         [ 31%]
tests/controllers/test_monitor.py .                                      [ 31%]
tests/controllers/test_publications.py ........                          [ 32%]
tests/controllers/test_return_schemas.py .                               [ 32%]
tests/controllers/test_search.py ..                                      [ 32%]
tests/controllers/test_sessions.py ..................................... [ 36%]
....                                                                     [ 37%]
tests/controllers/test_species.py ....                                   [ 37%]
tests/controllers/test_tools.py ........................................ [ 42%]
.....................................                                    [ 46%]
tests/core/test_security.py ...........                                  [ 47%]
tests/core/test_session.py ........................                      [ 49%]
tests/services/io/test_read_file_contents.py ...............             [ 51%]
tests/services/test_abba.py .................................            [ 55%]
tests/services/test_asynctask.py ....................................    [ 59%]
tests/services/test_gene.py ..............                               [ 60%]
tests/services/test_genset.py .......................................... [ 65%]
..................................................                       [ 70%]
tests/services/test_monitors.py ..                                       [ 70%]
tests/services/test_ontology.py ....                                     [ 71%]
tests/services/test_publications.py .......                              [ 71%]
tests/services/test_run_record.py ............                           [ 73%]
tests/services/test_similar_genesets.py ........                         [ 74%]
tests/services/test_species.py .......                                   [ 74%]
tests/services/test_tool_catalog.py ...................                  [ 76%]
tests/services/test_tool_downloads.py .................                  [ 78%]
tests/services/test_tool_inputs.py .................                     [ 80%]
tests/services/test_tool_runs.py ......................................  [ 84%]
tests/services/test_tools.py ........................................... [ 89%]
........................................................................ [ 97%]
............                                                             [ 98%]
tests/test_namespace_integrity.py .............                          [100%]

=============================== warnings summary ===============================
tests/data/__init__.py:10
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:10: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    geneset_response_json = importlib.resources.read_text("tests.data", "response_geneset_1234.json")

../../../../../opt/hostedtoolcache/Python/3.11.18/x64/lib/python3.11/importlib/resources/_legacy.py:80: 11 warnings
  /opt/hostedtoolcache/Python/3.11.18/x64/lib/python3.11/importlib/resources/_legacy.py:80: DeprecationWarning: open_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    with open_text(package, resource, encoding, errors) as fp:

tests/data/__init__.py:11
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:11: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    geneset_w_gene_id_type_json = importlib.resources.read_text(

tests/data/__init__.py:15
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:15: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    geneset_list_response_json = importlib.resources.read_text("tests.data", "geneset.json")

tests/data/__init__.py:17
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:17: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    gene_homologus_ids_json = importlib.resources.read_text("tests.data", "homologus_ids.json")

tests/data/__init__.py:19
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:19: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    gene_id_mapping_json = importlib.resources.read_text("tests.data", "gene_maping.json")

tests/data/__init__.py:21
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:21: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    publications_json = importlib.resources.read_text("tests.data", "publications.json")

tests/data/__init__.py:23
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:23: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    jwt_test_keys_json = importlib.resources.read_text("tests.data", "security_jwt_RS256_keys.json")

tests/data/__init__.py:25
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:25: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    species_json = importlib.resources.read_text("tests.data", "species.json")

tests/data/__init__.py:27
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:27: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    genes_json = importlib.resources.read_text("tests.data", "genes.json")

tests/data/__init__.py:29
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:29: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    monitors_json = importlib.resources.read_text("tests.data", "monitors.json")

tests/data/__init__.py:31
  /home/runner/work/geneweaver/geneweaver/tests/data/__init__.py:31: DeprecationWarning: read_text is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
    ontology_json = importlib.resources.read_text("tests.data", "ontology.json")

tests/controllers/test_sessions.py: 17 warnings
tests/core/test_session.py: 10 warnings
  /home/runner/work/geneweaver/geneweaver/.venv/lib/python3.11/site-packages/starlette/testclient.py:445: DeprecationWarning: Setting per-request cookies=<...> is being deprecated, because the expected behaviour on cookie persistence is ambiguous. Set cookies directly on the client instance instead.
    return super().request(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

---------- coverage: platform linux, python 3.11.18-final-0 ----------
Name                                              Stmts   Miss  Cover
---------------------------------------------------------------------
src/geneweaver/api/__init__.py                        5      2    60%
src/geneweaver/api/controller/__init__.py             0      0   100%
src/geneweaver/api/controller/api.py                 19      1    95%
src/geneweaver/api/controller/auth.py                95      1    99%
src/geneweaver/api/controller/genes.py               38      0   100%
src/geneweaver/api/controller/genesets.py           100      3    97%
src/geneweaver/api/controller/message.py             27      0   100%
src/geneweaver/api/controller/monitors.py            15      0   100%
src/geneweaver/api/controller/publications.py        34      0   100%
src/geneweaver/api/controller/search.py              20      0   100%
src/geneweaver/api/controller/species.py             16      0   100%
src/geneweaver/api/controller/tools.py              127      0   100%
src/geneweaver/api/controller/utilities.py            9      0   100%
src/geneweaver/api/core/__init__.py                   0      0   100%
src/geneweaver/api/core/config.py                     2      0   100%
src/geneweaver/api/core/config_class.py              46      0   100%
src/geneweaver/api/core/exceptions.py                13      1    92%
src/geneweaver/api/core/security.py                 139     20    86%
src/geneweaver/api/core/session.py                   37      1    97%
src/geneweaver/api/dependencies.py                   72     37    49%
src/geneweaver/api/main.py                            1      0   100%
src/geneweaver/api/schemas/__init__.py                0      0   100%
src/geneweaver/api/schemas/apimodels.py              62      6    90%
src/geneweaver/api/schemas/auth.py                   17      0   100%
src/geneweaver/api/schemas/messages.py               15     15     0%
src/geneweaver/api/schemas/score.py                  12     12     0%
src/geneweaver/api/schemas/search.py                 58      1    98%
src/geneweaver/api/schemas/tools.py                  60      0   100%
src/geneweaver/api/services/__init__.py               0      0   100%
src/geneweaver/api/services/abba.py                  78      1    99%
src/geneweaver/api/services/asynctask.py            136      4    97%
src/geneweaver/api/services/genes.py                 45      0   100%
src/geneweaver/api/services/geneset.py              186      5    97%
src/geneweaver/api/services/io.py                     4      0   100%
src/geneweaver/api/services/monitors.py              10      0   100%
src/geneweaver/api/services/parse/__init__.py         0      0   100%
src/geneweaver/api/services/publications.py          46      0   100%
src/geneweaver/api/services/pubmeds.py                0      0   100%
src/geneweaver/api/services/run_record.py            26      0   100%
src/geneweaver/api/services/similar_genesets.py      48      0   100%
src/geneweaver/api/services/species.py               17      0   100%
src/geneweaver/api/services/tool_catalog.py          88      4    95%
src/geneweaver/api/services/tool_downloads.py       135     12    91%
src/geneweaver/api/services/tool_inputs.py           64      0   100%
src/geneweaver/api/services/tool_runner.py            8      0   100%
src/geneweaver/api/services/tool_runs.py            206      4    98%
src/geneweaver/api/services/tools.py                286      5    98%
---------------------------------------------------------------------
TOTAL                                              2422    135    94%
Coverage HTML written to dir htmlcov

================ 888 passed, 33 skipped, 49 warnings in 17.87s =================

@belkassaby
belkassaby had a problem deploying to jax-cluster-dev-10--dev November 19, 2026 17:22 — with GitHub Actions Error
…editable record (G3-801)

From the review of this PR:

- The record is the AsyncTask input's description, which its owner can rewrite
  (PATCH /inputs/{id}). The read check now takes the tool from the envelope, which
  cannot be changed, ignores a record naming another tool, and checks every gene set
  the envelope or the record names. A Similar gene sets run patched to claim "upset"
  with no gene sets is still gated on its gene set and filtered.
- Runs without a record read their gene sets wherever each tool's envelope keeps them:
  MSET's universe, PhenomeMap's gene_sets keys, Triclique's two groups. Completed runs of
  those tools from before records no longer answer 409 while still being polled.
- A registered tool's rerun is validated as ToolRunRequest first (2 to 20 distinct gene
  sets), as a new run is.
- Boolean Algebra's "intersect" downloads the intersection, not the union.
- TOOL_RUN_RETENTION_DAYS of 0 or less turns expiry off, rather than deleting every run.
@belkassaby
belkassaby temporarily deployed to jax-cluster-dev-10--dev November 19, 2026 17:34 — with GitHub Actions Inactive
@belkassaby
belkassaby requested review from bergsalex and francastell and a balanced review from Copilot and removed request for Copilot November 21, 2026 13:08

This branch was previously deployed

1 inactive deployment
jax-cluster-dev-10--dev — bcc5af3e Deployed Nov 19, 2026 by belkassaby via Deploy: Dev / deploy #102
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.

1 participant