Skip to content

Intermittent mixed-sign grid row/cell height assertion in frontend CI #87

Closed

Description

@DavidVFitzGerald

Summary and impact

The mock Flows grid unit test "sizes mixed-sign rows from summaries and stripes by row index" (apps/frontend/src/services/mock/flows-grid.test.tsx:125, expect(cell.style.height).toBe(row.style.height)) intermittently sees a value cell 53px tall inside a row styled 52px. It failed the required frontend quality job on backend PR #86, which changes no frontend files. A flaky required gate blocks unrelated PRs; if the mismatch can reach a rendered frame, it is also a user-visible signed-bar geometry defect (spec §6.6). Unknown which: the investigation decides.

Delivery phase

Phase 1 - frontend with mock services. Delivered together with #76 in one PR (maintainer decision 2026-11-15): branch fix/76-87-unit-headroom, PR body Refs #76 and Refs #87.

Steps to reproduce

Observed once in hosted CI: run https://github.com/DavidVFitzGerald/LCA-diff/actions/runs/43750349407 attempt 1 (PR #86 at d3bd9ed, base 9b0ebba): npm run test:unit, 402 passed / 1 failed, 65.5 s; AssertionError: expected '53px' to be '52px'. Attempt 2 (same SHA) passed; the preceding run 43750251968 at 1b9ee46 passed with identical frontend files. Not yet reproduced locally.

Reproduction attempts (worktree/project from #76):

docker compose -p lca-diff-headroom exec -T workspace bash -lc 'cd apps/frontend && fails=0; for i in $(seq 1 50); do npx vitest run src/services/mock/flows-grid.test.tsx -t "sizes mixed-sign rows" >/dev/null 2>&1 || { fails=$((fails+1)); echo "fail $i"; }; done; echo "isolated fails=$fails/50"'
docker compose -p lca-diff-headroom exec -T workspace bash -lc 'cd apps/frontend && fails=0; for i in $(seq 1 10); do npx vitest run src/services/mock/ >/dev/null 2>&1 || { fails=$((fails+1)); echo "fail $i"; }; done; echo "mock-dir fails=$fails/10"'

Plus every full run made for #76.

Expected behavior and authority

Spec §6.6 (signed-bar exact geometry: one row height from the whole-row summary, cells fill it) and §9.2 item 15; roadmap F4 gate (coherent mixed-sign row heights, no height jumps). In every rendered frame, each mounted value cell's height equals its row's height, and rows start where the previous one ends. The unit test should pass deterministically. A test-only fix must first show that product behaviour is correct.

Actual behavior

Intermittent: a mounted value cell has style.height 53px while its row has 52px (the virtualizer's estimate, DEFAULT_ROW_HEIGHT). Only this assertion failed; no backend test or provider data involved.

Lead to check (hypothesis only): SignedValueCell takes row.rowHeight from the summary geometry at render time, while the row's style.height is the virtualizer's row.size, which ComparisonGrid.tsx updates via rowWindow.resizeItem inside a queueMicrotask scheduled from useLayoutEffect. The test's waitFor passes once any row exceeds 52px, and Testing Library's MutationObserver callback may run between the commit and that microtask, or newly summarized rows may be in that window. Whether a browser can paint the mismatch depends on whether the virtualizer's resulting re-render is flushed before paint.

Environment and version

Hosted Ubuntu 24.04, pinned node:24-bookworm container, Node 24.22.3, Vitest 5.1.0, jsdom 31.0.1, @tanstack/react-virtual 3.14.24, React 19.3.1. Mock adapter, synthetic 220 × 2,000+ workload. Reproduce locally in the rootless workspace container.

Context and dependencies

F4 grid #23 / gate #26 (merged, af5317d). Groomed READY 2026-11-15 together with #76; no other dependency. Frontend-only fix in the #76 branch. Concurrent #27 (PR #88) does not touch the grid files.

Acceptance criteria

  • AC1 Reproduce/characterize (first step, before any fix). Record the counts from the 50 isolated runs, 10 src/services/mock/ runs and the [Task] Restore unit-test budget headroom for the 300-selection and deep-scroll tests #76 baseline full runs. Independently of whether it reproduces, run two temporary, uncommitted probes and record their results:
    • jsdom: a MutationObserver (or equivalent) during the test's scroll to row 300 that records every mutation batch in which a mounted [role="gridcell"][data-state] height differs from its row's, and whether the mismatch persists across a macrotask (setTimeout(0)).
    • browser, both projects: in the large scenario, sample every requestAnimationFrame during the scroll to row ~300 and the deep jump to scrollTop 40,000 (≥ 300 frames per project), counting frames where any mounted value cell's rendered height (getBoundingClientRect) differs from its row's by > 0.5 px.
  • AC2 Classify and fix.
    • (A) Assertion race only if the browser probe finds 0 mismatched frames in both projects and the jsdom mismatch never survives a macrotask. Fix the test's synchronization so it asserts the same per-row/per-cell equality and row-start contiguity for every mounted row on a settled grid (no tolerance, no toBeCloseTo on heights, no dropping rows from the check); it must still fail if equality is never reached.
    • (B) Geometry defect if any rendered frame mismatches or the mismatch survives a macrotask. Fix product code so a row and its cells take their height from one value in the same commit (e.g. in ComparisonGrid.tsx/useFlowGrid.ts/SignedValueCell.tsx), without breaking view anchoring ([Task] F4 — Virtualize comparison rows and columns with sticky alignment #23 D2-D4) or the flushSync-in-lifecycle constraint.
  • AC3 Regression. (A): the corrected unit test plus a committed note in the test explaining the synchronization. (B): a committed regression test (jsdom mutation-level check and/or a browser frame check in e2e/flows-grid.spec.ts) that is shown to fail on the pre-fix code (record the failing run) and pass after. Existing §6.6 geometry tests (geometry.test.ts, SignedValueCell.test.tsx, the mixed-sign grid test) keep their assertions.
  • AC4 Stability. After the fix: 0 failures in 50 isolated runs of the test, 10 src/services/mock/ runs, and the [Task] Restore unit-test budget headroom for the 300-selection and deep-scroll tests #76 AC3/AC4 full runs.
  • AC5 Gates. [Task] Restore unit-test budget headroom for the 300-selection and deep-scroll tests #76 AC9 gates pass; full e2e in both projects if product code changed. Evidence (probe method, counts, classification) is recorded in docs/engineering/unit-headroom-verification.md and the handoff.

Regression and verification plan

Commands above and in #76's verification plan (project lca-diff-headroom, port 5221). Browser probe via a temporary spec run with npm run test:e2e -- --project=chromium <probe> and --project=firefox <probe>, removed afterwards (git status clean). Independent QA at the delivered SHA. Mock evidence only; does not prove real API integration.

Out of scope and follow-ups

No backend changes, timeout increases for this test, retries or disabled checks. Other flakes get their own issues (#51 already tracked). B4 and I1 unaffected.

Activity

  1. added
    bug
    frontend
    on Nov 15, 2026
  2. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    The single failed-job rerun passed, including the full frontend workflow: https://github.com/DavidVFitzGerald/LCA-diff/actions/runs/43750349407 . No source changes occurred between attempts. Keep this investigation open; the transient failure evidence remains in attempt 1.

  3. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    PM: READY (delivered with #76 in one PR)

    • Phase: 1, frontend with mocks. It shares [Task] Restore unit-test budget headroom for the 300-selection and deep-scroll tests #76's branch fix/76-87-unit-headroom, project lca-diff-headroom and port 5221. The PR body says Refs #76 and Refs #87.
    • Dependencies: none outstanding. The F4 grid is on main (af5317d).
    • Spec references: §6.6 (signed-bar geometry), §9.2 item 15, and the F4 gate (coherent mixed-sign heights).
    • Step 1, before any fix (AC1): reproduce and characterize.
    • Classification rule (AC2):
      • (A) Assertion race only if no rendered frame mismatches and no jsdom mismatch survives a macrotask. The fix is then test synchronization that still asserts equality for every mounted row and cell on a settled grid, with no tolerance.
      • (B) Geometry defect otherwise. The fix is then in product code (ComparisonGrid.tsx, useFlowGrid.ts or SignedValueCell.tsx), with one height source per commit. It must keep the [Task] F4 — Virtualize comparison rows and columns with sticky alignment #23 D2–D4 anchoring and must not call flushSync inside a lifecycle method. It needs a regression test shown to fail before the fix.
    • Lead: the cell height comes from the summary at render time, but the row height comes from the virtualizer's row.size. That is updated by resizeItem in a microtask queued from useLayoutEffect. This is only a hypothesis; the probes decide.
    • Stability (AC4): after the fix, no failures in 50 isolated runs, 10 mock-directory runs, or the [Task] Restore unit-test budget headroom for the 300-selection and deep-scroll tests #76 gate runs.
    • Not allowed: timeout increases, retries or relaxed height assertions for this test.

    Hand-off: Software Engineer (with #76), then QA at the delivered SHA.

    🤖 Generated with Claude Code

  4. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: state → implementing (one PR for #76 + #87, maintainer decision 2026-11-15). Software Engineer assigned on fix/76-87-unit-headroom from af5317d, worktree /tmp/lca-diff-headroom, Compose project lca-diff-headroom, port 5221. #52 runs in parallel; AC3 gate runs need a quiet host and are coordinated with the coordinator.

    🤖 Generated with Claude Code

  5. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Engineering: READY FOR QA (#87, delivered with #76)

    AC1: reproduce and characterize, at af5317d before any fix

    AC2: classification B, geometry defect

    Chromium painted a mismatched frame.

    Cause. The lead was right:

    1. The cell took its height from the summary at render time.
    2. The row's height was the virtualizer's row.size.
    3. resizeItem updates row.size from a microtask after the layout effect, through a non-synchronous re-render, so the new size reaches the row one commit after the cell.

    Fix (product code).

    • ComparisonGrid passes renderCell the row's height in that commit.
    • FlowsGrid uses the summary geometry only once the row has that height. Until then the cell stays pending at the row's height, so every commit has one height per row.
    • The resize microtask, pin and record ([Task] F4 — Virtualize comparison rows and columns with sticky alignment #23 D2–D4) are unchanged. No flushSync is added.

    AC3: regression

    • The mixed-sign test now records every mutation batch during the scroll and expects no value cell whose height differs from its row's. It then runs its existing checks on a settled grid.
    • Against the pre-fix product code it failed 3 of 3 (96 mismatches, e.g. row 295: 53px in 52px). After the fix it passes.
    • geometry.test.ts and SignedValueCell.test.tsx are unchanged and pass.
    • After the fix, both probes find 0 mismatches: jsdom in 3 runs, Chromium and Firefox in 396 frames each.

    AC4: stability

    AC5: gates

    Run in the container at decb56a:

    • npm ci (lockfile unchanged), format:check, lint, typecheck and build pass.
    • @smoke: 14 passed.
    • Full e2e in both projects: 68 passed.
    • Hosted quality passed (run 43781924606), and the hosted workflow_dispatch full run passed (run 43781929921, 68 browser tests).

    Limitations and residual risk

    Next: QA, at delivered SHA 7e4e1c2.

    🤖 Generated with Claude Code

  6. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator state: QA. The Engineer handed off PR #94 at 7e4e1c2 (code at decb56a). Independent QA starts in a detached worktree at 7e4e1c2. Heavy runs wait for the #52 QA suite to go idle.

    🤖 Generated with Claude Code

  7. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    QA: PASS

    All #87 criteria passed. The PR as a whole is still held by #76 AC4; see the #76 QA comment.

    What I reviewed

    • Branch fix/76-87-unit-headroom, delivered SHA 7e4e1c2a65b43c42cea04f2533e81178a9b276d0. The code SHA is decb56a; the fix landed in d78ccd8.
    • Mock mode only.
    • Environment: rootless workspace container, Compose project lca-diff-headroom-qa, port 5229. The worktree was detached at 7e4e1c2 and stayed clean.

    Criteria

    AC Verdict Evidence
    AC1 Reproduce/characterize PASS (inspection) The doc records the counts at af5317d (0/50, 0/10, 0/3) and both probes: jsdom showed 2 of 6 batches mismatched in 10 of 10 runs, surviving a microtask but not a macrotask; Chromium showed 1 of 396 frames mismatched and Firefox 0 of 396. I did not re-run the browser probe.
    AC2 Classify and fix PASS Details below.
    AC3 Regression PASS Details below.
    AC4 Stability PASS Details below.
    AC5 Gates PASS Details below.

    AC2: classification and fix

    • Classification B follows the issue's rule, because a rendered Chromium frame mismatched.
    • The fix is in product code.
      • ComparisonGrid passes row.size, the same value it uses for the row's style.height, to renderCell.
      • FlowsGrid uses the summary geometry only when summarized.rowHeight === rowHeight. Otherwise the cell is pending at the row's height.
      • So every commit has one height per row.
    • Anchoring is intact. The resizeItem microtask in useLayoutEffect, and pin/record ([Task] F4 — Virtualize comparison rows and columns with sticky alignment #23 D2–D4), are untouched. The anchoring, columns and hold files pass.
    • No flushSync. The diff adds none; the only existing one is in ProcessHeaders.tsx and was already there.
    • Not vacuous. A temporary probe on the settled grid after the scroll to row 300 found:
      • 8 rows taller than 52px, carrying 96 summarized [data-state] cells at the row's height. So cells do get the summary geometry once the row resizes, and don't stay pending.
      • The only pending cells were the 12 in pinned row 0, which is outside the window. That is identical to the pre-fix code.

    AC3: regression test shown failing before the fix

    • Pre-fix run. I used a scratch copy of the delivered tree with only ComparisonGrid.tsx and FlowsGrid.tsx restored from main, uncommitted. The mixed-sign test failed 3 of 3:

      AssertionError: expected [ 'row 295: 53px in 52px', …(95) ] to deeply equal []
      
    • Delivered code. The same test passed 3 of 3.

    • Existing tests. The existing equality, stripe and contiguity checks are unchanged and now run on a settled grid. geometry.test.ts and SignedValueCell.test.tsx are unchanged and pass. There is no height tolerance and no toBeCloseTo on heights; the only toBeCloseTo is the existing one on row start offsets.

    AC4: stability, at the delivered code, unscaled

    Runs Failures Load start → end
    50 isolated runs of -t "sizes mixed-sign rows" (230 s) 0 / 50 2.60 → 2.08
    10 runs of src/services/mock/ (201 tests each, 410 s) 0 / 10 2.14 → 4.62
    3 #76 AC3 full runs and 3 AC4 pairs (12 suite runs) 0 failures of the mixed-sign test see the #76 comment

    The one failure in the AC4 pairs was the #93 D1/D2 race, not this test.

    AC5: gates, in the container

    • npm ci (lockfile unchanged), format:check, lint, typecheck and build pass.
    • @smoke: 14 passed.
    • Full e2e in both projects: 68 passed.
    • Hosted CI at 7e4e1c2 is green: quality 43781924606, workflow_dispatch 43781929921, plus Backend and ETL.
    • The evidence (probe method, counts, classification) is in unit-headroom-verification.md.

    Commands

    # pre-fix regression (scratch copy /root/qa/prefix = delivered tree + main's ComparisonGrid.tsx/FlowsGrid.tsx)
    docker compose -p lca-diff-headroom-qa exec -T workspace bash -lc 'cd /root/qa/prefix && for i in 1 2 3; do npx vitest run src/services/mock/flows-grid.test.tsx -t "sizes mixed-sign rows"; done'
    docker compose -p lca-diff-headroom-qa exec -T workspace bash -lc 'cd apps/frontend && for i in 1 2 3; do npx vitest run src/services/mock/flows-grid.test.tsx -t "sizes mixed-sign rows"; done'
    docker compose -p lca-diff-headroom-qa exec -T workspace bash -lc 'cd apps/frontend && for i in $(seq 1 50); do npx vitest run src/services/mock/flows-grid.test.tsx -t "sizes mixed-sign rows"; done'
    docker compose -p lca-diff-headroom-qa exec -T workspace bash -lc 'cd apps/frontend && for i in $(seq 1 10); do npx vitest run src/services/mock/; done'

    Notes

    Next: this issue is ready for review with the PR, but the PR stays held by #76 AC4.

    🤖 Generated with Claude Code

  8. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator state: ready for review.

    🤖 Generated with Claude Code

  9. DavidVFitzGerald commented on Nov 16, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: closed. PR #94 merged at eea972f after QA PASS and green hosted checks.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfrontend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions