Repository navigation
fix: PR 39 review findings (G3-803, G3-777, G3-764) - #40
Conversation
…rs, refusals From geneweaver-review.md (findings 1, 2, 3, 9, 10 and a note): 1. JaccardSimilarity's Venn grid drew each set at the size of its last pair. With pairwise deletion a cross-platform pair counts only the genes both platforms measure, so pairs disagree. Each cell is now sized from its own pair; the diagonal is the gene set's own size (the run's gene counts), noting when a pair shows it smaller. 2. BooleanAlgebra's species table named species by position: the ids skip 7, so 8 (C. elegans) read "Yeast" and 9 read "Chicken". It now uses the shared, id-keyed names -- full names, as legacy's table showed them. The gene set page's species tag had the same off-by-one; it is keyed by id too, and gains 11-13. 3. Suggestion paging fetched the next page from the list's length, which an id lookup at its head (or a dropped repeat) put off by one or more, so a search row was never shown. It now tracks the search's own offset. 9. UpSet drew a half-width bar for every set when all were empty: d3's max of zeros is 0, not undefined, so `?? 1` let a [0, 0] domain through. `|| 1`, here and in the MSET histogram. 10. Search filters now check p- and q-value cutoffs are within 0..1, as the analysis cutoffs do; and a search the API refuses shows its reason instead of "The gene set search is not responding". Note: a downloaded chart's object URL is revoked on the next turn, not straight after click(), which some browsers cancel.
…t, identity From geneweaver-review.md (findings 4-8 and a note). No legacy code, database function or migration changes. 4. threshold "custom" with no cutoff validated and silently meant "all genes" while reported as thresholded. ThresholdOptions refuses it (422), as the analysis page already did. 8. ABBA matched gene sets by legacy's own rule: every group of a gene set had to be one of the user's. It hid a user's own private gene sets, an admin's or curator's view, and group-restricted gene sets in public tiers -- and matched any gene set with an empty group list for anyone, anonymous included (1,006 on dev, all private or untiered). ABBA now reads the rule search and a tool run use: geneweaver.db.query.readable, one set-based form of geneset_is_readable2, shared by search and ABBA. On dev it only adds gene sets: seed Drd2/Drd1, anonymous 5,190 -> 5,647 (457 public-tier); an admin or curator 5,375 -> 7,190. 6. A seed gene set expanded to every identifier of every gene (legacy did the same). Only symbols match the seed, so the rest matched nothing, but symbol synonyms matched other genes sharing them: GS821 (163 genes) seeded 2,158 genes, GS167180 (74) seeded 1,094. Now one preferred symbol per gene: 1,064 and 502 (homonyms across species remain, as in legacy). This changes results -- ~7-9k fewer matching gene sets for those seeds -- and runs 2-3x faster. A seed over 20,000 genes is refused with its size (the largest gene set on dev, 17,370, still fits); ABBAInput caps genes at 20,000 for runs submitted to AsyncTask directly. 5. An in-process ABBA search bounded each statement (240 s) but not the request, which runs ~20 statements plus 4 per result gene, so a slow database could outlast the 300 s ingress. ABBA_REQUEST_TIMEOUT_SECONDS (270) now bounds the whole search: each statement's timeout shrinks to what is left, and running out answers 504 with the reason and frees the concurrency slot. The worker path sets no budget and is unchanged. 7. A signed ABBA identity covered only the user id, so one copied from a run's stored values could be replayed for any search, forever. v2 signs the user, an expiry (6 h) and a digest of the search's input. The key is ABBA_IDENTITY_SECRET where set, else DB_PASSWORD as before; the API and tools worker read it from an optional geneweaver-abba-identity Secret, so nothing changes until that Secret is created. Note: search()'s docstring said it leaves the connection clean; on the API's pooled connection its transaction is a savepoint, so the temp tables and SET LOCAL last until the caller's transaction ends. Documented.
There was a problem hiding this comment.
🔵 Needs a closer look
An active moderate finding shows that metadata and preparation queries can exceed the intended request deadline, leaving the timeout budget unenforced and requiring code changes.
No open issues 🎉
What changed in this PR
This PR fixes the findings from the review of PR 39, which added charts for each analysis tool on the /next/analyze page. It covers the UI charts and search, the ABBA search in the API, database, and tools worker, and two deployment files. It does not touch legacy code, database functions, or migrations.
Changes:
- UI: Fixes chart sizing and labels (UpSet, Jaccard, species names), search paging and p/q range checks, and shows the API's reason when a search is refused.
- ABBA search: Uses one shared access rule, matches one preferred symbol per gene, caps seed size at 20,000 genes, and adds a 270-second request budget that returns 504 when exceeded.
- Identity and config: The signed ABBA identity now covers the search input and expires after 6 hours. It uses an optional
ABBA_IDENTITY_SECRET, falling back toDB_PASSWORD, and the deployments read it from an optional Secret.
| File | Description |
|---|---|
| ui/src/app/search/search-filters.ts | Checks that p-value and q-value filters are between 0 and 1 before a search is sent. |
| ui/src/app/search/search-filters.spec.ts | Tests the new p-value and q-value range checks. |
| ui/src/app/search/geneset-search-source.ts | Pages from the search's own offset and stores the API's refusal reason. |
| ui/src/app/pages/analyze/visualizations/upset-plot.component.ts | Uses || 1 so an all-empty set list no longer draws half-width bars. |
| ui/src/app/pages/analyze/visualizations/upset-plot.component.spec.ts | Tests that empty gene sets draw zero-width bars. |
| ui/src/app/pages/analyze/visualizations/tool-result.component.ts | Passes gene counts into the Jaccard Venn grid so the diagonal uses each set's true size. |
| ui/src/app/pages/analyze/visualizations/mset-histogram.component.ts | Uses || 1 for the histogram's y-axis maximum. |
| ui/src/app/pages/analyze/visualizations/models.ts | Sizes each Jaccard cell from its own pair and reads species names by id. |
| ui/src/app/pages/analyze/visualizations/models.spec.ts | Tests per-pair sizing and species names by id. |
| ui/src/app/pages/analyze/visualizations/chart-utils.ts | Revokes the download URL on the next tick, so the download is not cancelled. |
| ui/src/app/pages/analyze/geneset-picker.component.ts | Shows the API's refusal reason under the gene set search. |
| ui/src/app/pages/analyze/geneset-picker.component.spec.ts | Tests paging after an ID lookup and the refusal message. |
| ui/src/app/components/speciestag/speciestag.component.ts | Looks up species by id instead of list position, fixing the labels from id 8 on. |
| ui/src/app/components/speciestag/speciestag.component.spec.ts | Tests species names by id, including unknown ids. |
| tests/services/test_abba.py | Tests the signed identity, the dedicated secret, the seed size cap, and the 504 timeout. |
| tests/controllers/test_tools.py | Tests that an ABBA search out of time returns 504 with its reason. |
| src/geneweaver/api/services/abba.py | Refuses seeds over 20,000 genes, signs the identity with the chosen secret, and maps timeouts to 504. |
| src/geneweaver/api/core/config_class.py | Adds the request timeout (270 s) and the optional identity secret settings. |
| src/geneweaver/api/controller/tools.py | Returns 504 with the timeout reason for an ABBA search that runs out of time. |
| packages/tools/tests/unit/test_thresholds.py | Tests that custom with no cutoff is refused. |
| packages/tools/tests/unit/test_abba.py | Tests the v2 identity (expiry and input digest) and the seed cap. |
| packages/tools/src/geneweaver/tools/thresholds.py | Refuses threshold: "custom" when no cutoff is given. |
| packages/tools/src/geneweaver/tools/temporal/activities.py | Reads the identity key from the shared signing secret helper and passes the input to verify it. |
| packages/tools/src/geneweaver/tools/abba/search.py | Adds a whole-search deadline, with each statement's timeout set to the time left. |
| packages/tools/src/geneweaver/tools/abba/schema.py | Caps the seed gene list at 20,000 entries. |
| packages/tools/src/geneweaver/tools/abba/identity.py | Version 2 identity: signs the expiry and a digest of the input, and checks both. |
| packages/db/tests/unit/test_abba.py | Tests the shared access rule, one symbol per seed gene, and the deadline behaviour. |
| packages/db/src/geneweaver/db/query/search/search.py | Uses the shared readable-gene-set predicate instead of its own copy. |
| packages/db/src/geneweaver/db/query/readable.py | New shared SQL predicate for which gene sets a user may read. |
| packages/db/src/geneweaver/db/query/abba.py | Uses the shared access rule and one preferred symbol per seed gene. |
| packages/db/src/geneweaver/db/abba.py | Runs each ABBA statement under the remaining time budget and reports running out of time. |
| deploy/k8s/base/tools-worker-deployment.yaml | Adds the optional identity Secret to the tools worker. |
| deploy/k8s/base/deployment.yaml | Adds the optional identity Secret to the API. |
Review effort: Lite
…ging main main added Similar gene sets while this branch was open, signing with the v1 identity: sign(user, DB_PASSWORD) on the API and DB_PASSWORD from the environment on the worker. This branch moved the identity to v2 (signed for the input, expiring, keyed by ABBA_IDENTITY_SECRET where set), so after the merge the API call no longer matched sign()'s signature and the worker referred to a removed os import. Similar gene sets now signs for its input with ABBA_IDENTITY_SECRET or the database password, and the worker verifies with signing_secret() against the run's input, exactly as for ABBA.
Test Coverage Report |
| from geneweaver.db.query.membership import Thresholds | ||
| from psycopg.rows import tuple_row | ||
|
|
||
| deadline = None if deadline_seconds is None else time.monotonic() + deadline_seconds |
There was a problem hiding this comment.
Fixed in 84299b7. The three name lookups now go through the same deadline-aware execute_within as the pipeline, so each one gets only what is left of the budget, at most 240 s. The budget no longer starts in search(): the API takes one deadline before it leases the connection and passes it through the access gate, the seed expansion, the lookups and the pipeline. A statement Postgres cancels at the deadline is reported as ABBADeadlineExceeded, which the API answers with 504, not 500. Tests: test_the_name_lookups_are_bounded_by_the_deadline (packages/tools) and test_preparation_spends_the_same_budget_as_the_search / test_a_gate_query_cancelled_at_the_deadline_is_a_504 (tests/services).
…genes count once Two warnings from the PR 40 review, and Copilot's comment on search.py. The 270 s budget started inside search(), so the access gate, the seed expansion and the three name lookups ran outside it, each under its own 240 s statement timeout: a slow preparation could use up the ingress's 300 s before the budget began, and a cancelled preparation query answered 500 instead of 504. The in-process request now takes one deadline before its connection is leased, and every statement spends from it: each gate check, the seed expansion, the name lookups and the pipeline get only what is left (at most 240 s each), and a statement cancelled at the deadline is ABBATimedOut (504). The bounding moves out of abba() into geneweaver.db.abba (execute_within, bound_next_statement, deadline_cancellation) so all of them share it, and the gate takes a before_each hook. search() takes the deadline as an instant; the worker passes none and runs as before. ABBAInput cleaned its genes after pydantic checked the 20,000 cap, and the API counted distinct genes but passed the raw list on, so a seed of exactly 20,000 genes plus a typed gene it already held was refused with 422. The cleaning now runs before the cap (clean_genes, mode="before"), and the API counts and passes the same cleaned list. ABBARequest's 1,000 typed-gene cap counts distinct genes the same way.

Fixes the ten findings and two notes in the PR 39 review (
geneweaver-review.md), and the two warnings in the PR 40 review of 2026-11-17.Base: this was stacked on #39 (
feat/G3-803-tool-visualizations). #39 merged on 2026-11-05, so the PR now targetsmain, with main merged in (d513c236). One fix was needed after that merge; see Merging main.Legacy and regressions
No legacy changes. No file under
legacy/, no database function and no migration is touched.Suites on the current head, run locally on Python 3.12:
test_first_party_subpackage_is_importable[client], becausegeneweaver.clientisn't installed locallypackages/dbpackages/toolspackages/tools-pluginLint passes on the changed files.
Two fixes change ABBA's results on purpose (findings 6 and 8 below). Both were measured on dev, old against new, for anonymous, group-member, private-set-owner, admin and curator users.
UI (68193113)
max(...) ?? 1lets 0 through)|| 1, here and in the MSET histogram.downloadSvgrevoked the URL right afterclick()API, database, tools (c75c400d, 84299b76)
4.
threshold: "custom"with no cutoff. It used to mean "all genes" while being reported as thresholded. It is now refused with a 422.8. ABBA used a third visibility rule.
Legacy's ABBA rule required every group of a gene set to be one of the user's. So it hid users' own private sets, the admin/curator view, and group-restricted sets in public tiers. It also matched any gene set with an empty group list for anyone, anonymous included (1,006 on dev, all private or untiered).
The fix: ABBA now uses
geneweaver.db.query.readable, one set-based form ofgeneset_is_readable2shared with search.On dev it only adds gene sets. For seed Drd2/Drd1:
6. ABBA seed gene sets expanded to every identifier (as legacy does). Only symbols match the seed, but symbol synonyms matched other genes sharing them.
ABBAInputcleaned its genes after pydantic checked the cap, and the API counted distinct genes but passed the raw list on. So a seed of exactly 20,000 genes, plus a typed gene it already held, was refused with 422.clean_genesnow runs before the cap, and the API counts and passes the same cleaned list. The 1,000 typed-gene cap onABBARequestcounts distinct genes too.5. ABBA's request time.
ABBA_REQUEST_TIMEOUT_SECONDS(270, under the 300 s ingress) is one budget for the whole in-process request. It starts before the connection is leased.search(), so the access gate, the seed expansion and the three name lookups ran outside it. All of them now spend from it. Each statement's timeout is what's left, at most 240 s. A statement cancelled at the deadline answers 504 with the reason, not 500.7. ABBA identity token.
ABBA_IDENTITY_SECRETwhere set, elseDB_PASSWORDas before. The API and tools worker read it from an optionalgeneweaver-abba-identitySecret, so nothing changes until that Secret is created.Note:
search()docstring. It no longer claims the connection is left clean. On the API's pooled connection, the search runs in a savepoint.Merging main (3a458115)
While this PR was open, main added Similar gene sets, which signs its runs with ABBA's identity in its v1 form:
sign(user, DB_PASSWORD), andDB_PASSWORDfrom the environment on the worker. The merge was textually clean, but the API call no longer matched v2'ssign(), and the worker used anosimport this PR had removed. Similar gene sets now signs and verifies exactly as ABBA does: for its input, with an expiry, keyed byABBA_IDENTITY_SECRETor the database password. A test checks the dedicated secret and that a signature fits only the search it was made for.After merge / deploy
ui/src/app/search/search-filters.ts: both change the p/q cutoff checks. Whichever merges second resolves it.geneweaver-abba-identitywithABBA_IDENTITY_SECRETin each environment, the same value for the API and the tools worker.