Skip to content

Table Copy: keep a fetched copy while the table's content is unchanged - #461

Merged
alisman merged 2 commits into
masterfrom
table-copy-e2e-robust
Nov 19, 2026
Merged

alisman merged 2 commits into
masterfrom
table-copy-e2e-robust

Conversation

@alisman

@alisman alisman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Mutations table's Copy (#413) flaked once in CI on #457's run: the first click never reached "Copy Ready!". It passed on the re-run.

The cause in the app: the Copy state reset whenever the table's answer object was replaced, even by an identical answer (a re-render, a page turn). That could drop a first click's fetch while it was still running.

The fix:

  • The reset now keys on what the copied text depends on (copyTableKey in lib/table-tsv.ts):
    • the document the copy is fetched from (docJson()), with the view's index and table;
    • then the answer's query, its column ids and each study's row counts.
  • A sort, a filter, a gene, a cohort, a driver setting or a pin in the document, or a change of rows, still drops a fetched copy. The same table answered again keeps it.

The e2e (test/e2e/tables.cjs):

  • waits for the table to settle before the first click;
  • retries the first click once if the button fell back to "Copy";
  • on a failure, names the button's label and the status text (a "could not copy: …" was hidden before).

Review fix (since 00557aa)

The key now starts from the document, the view's index and its table. Before, a change to the document alone (the drivers setting, a gene or cohort swap with equal counts, the OncoKB or Genome Nexus pins) kept a stale copy. Added C8–C11 and the planted bug copy-key-ignores-doc.

Spec table

id case expected
C1 two deep-equal answers same key
C2 a page turn (rows, offset, pageSize differ) same key
C3 the sort changes different
C4 one more column different
C5 one study's all changes, totals the same different
C6 total changes different
C7 a list entry's cohort changes different
C8 the document differs (a driver setting), counts equal different
C9 the view's index differs different
C10 the table differs (mutations vs sv) different
C11 no table on either side, all else equal same key

Verification

  • A separate agent wrote test/table-copy-key.test.ts (C1–C11) from the table.
  • Planted bugs copy-key-ignores-rows, copy-key-ignores-sort and copy-key-ignores-doc are in scripts/mutants/mutations/table-copy.ts. Each fails the suites that import lib/table-tsv.ts.
  • npm test passes, and the e2e tables area passes (Copy: identical to table.tsv).

Tracker

None. This fixes the reliability of #413's feature and ticks nothing.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q3ezTXaZDnWotHSveqDGjf

The Copy button's two steps reset whenever the table answer object was
replaced, even by an identical answer (a re-render, a page turn), so a
first click's fetch could be dropped and "Copy Ready!" never appear. This
flaked the tables e2e once on CI (#457). The reset now keys on what the
copied text depends on (copyTableKey: the query, the column ids, each
study's row counts), so a sort, a column or a row change still drops it.

The e2e waits for the table to settle before the first click, retries the
first click once if the button fell back to "Copy", and names the button's
label and the status text when it fails.

Tests: test/table-copy-key.test.ts (C1-C7, written by a separate agent
from the spec table); two planted bugs in table-copy.ts, each failing the
suites that import lib/table-tsv.ts. npm test passes; e2e tables passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTXaZDnWotHSveqDGjf
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cbiolab-genie Ready Ready Preview Nov 19, 2026 4:45pm UTC
cbiolab-new Ready Ready Preview Nov 19, 2026 4:45pm UTC
cohort-lab Ready Ready Preview Nov 19, 2026 4:45pm UTC

Request Review

Comment thread lib/table-tsv.ts Outdated
* or a page turn, and is dropped when the query, the columns or the rows change.
*/
export function copyTableKey(t: { query: unknown; columns: { id: string }[]; lists: { cohort: string; study: string; total: number; all: number }[]; total: number; all: number }): string {
return JSON.stringify([t.query, t.columns.map((c) => c.id), t.lists.map((l) => [l.cohort, l.study, l.total, l.all]), t.total, t.all]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: the key leaves out things that change the copied text, so a kept copy can paste stale rows.

The key covers the table query, the column ids and the row counts. But the table.tsv that fetchCopy posts is built from the whole view doc (docJson(), vi, table). Several parts of the doc change the rows or their text without changing any of those:

  • drivers (the page's driver settings): lib/views/mutations/run.ts:103 passes them to mutationValue, so they change each row's driver-call/Annotation cell and the default order. Every count stays the same, so the key stays the same.
  • gene: switching the view's gene to one with the same per-study counts keeps the key. In a small study, two genes with one mutation each is ordinary. Copy Ready! then pastes the old gene's mutations.
  • the cohort's members: swapping one sample for another with the same number of mutations keeps the per-study total/all. lists[].cohort is the cohort's name, not its definition.
  • the OncoKB/Genome Nexus pins (oncokbPin, variantPins) change cell text the same way.

Before this PR, any new answer reset the copy, so none of these could leak. That's the stale-copy bug #413's generation counter was there to prevent.

Suggested fix: build the key from what the fetch actually sends, e.g. docJson?.() plus vi and table. That only works if the doc doesn't carry the page offset. Alternatively, keep the counts key but add the doc string to it. C1–C7 are good, but please add a case where the same counts come from a different doc (the gene or driver settings), and a planted bug that drops the doc from the key.

@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Review: changes requested

Blocking:

  • copyTableKey keys on the query, the column ids and the row counts, not on the doc that the Copy fetch sends. A change to the view's driver settings, its gene (with the same per-study counts), the cohort's members (same counts) or the OncoKB/Genome Nexus pins keeps the key. Copy Ready! then pastes stale rows, which is the bug Mutations table: the portal's Copy button, the table.tsv's text to the clipboard (MUT-TB-2) #413's reset prevented. Details are inline on lib/table-tsv.ts:37. Fix: build the key from docJson() + vi + table, and add a test and a planted bug for the doc-only case.

Not blocking: the generation check still drops answers from a superseded fetch. The e2e retry and the failure diagnostics look fine. CI was still pending at review time.

Review fix. copyTableKey keyed only on the answer's query, columns and
row counts, but the copy is fetched from the whole view document. A
change to the document alone (the drivers setting, a gene or cohort swap
with equal counts, the OncoKB or Genome Nexus pins) kept a stale copy,
so Copy Ready! could paste the old rows. The key now starts from
docJson(), the view's index and its table.

Tests: C8-C11 in test/table-copy-key.test.ts (a separate agent); C1-C7
pass the same source on both sides. Planted bug copy-key-ignores-doc;
the three copy-key planted bugs each fail the suites that import
lib/table-tsv.ts. npm test passes; e2e tables passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTXaZDnWotHSveqDGjf
@alisman

alisman commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Re-review: pass. 162d5fc fixes the blocking finding. copyTableKey now leads with what the copy is fetched from: the view document (docJson()), the view index and the table, ahead of the answer's query, columns and counts. A change to the document alone now drops a kept copy: drivers, a gene or cohort swap with equal counts, or an OncoKB / Genome Nexus pin. C8–C10 pin each part, C11 keeps the re-render case, and the new planted bug copy-key-ignores-doc is caught by C8.

nit: docJson() is serialised on every render of every table to build the key. If that shows up in profiles, the key could be memoised on the doc's identity.

@alisman
alisman added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit e21ad4f Nov 19, 2026
12 checks passed
@alisman
alisman deleted the table-copy-e2e-robust branch November 19, 2026 17:13

This branch was successfully deployed

1 active deployment
Preview – cohort-lab — 162d5fcf Deployed Nov 19, 2026 by vercel[bot]
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