Skip to content

Fix Windows app UI test flakes in thread detail, timeline auto-load and composer paste - #8083

Merged
ymichael merged 3 commits into
mainfrom
bb/fix-windows-app-ui-test-flakes-thr_9z3dsijk75
Nov 24, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/fix-windows-app-ui-test-flakes-thr_9z3dsijk75

Conversation

@ymichael

@ymichael ymichael commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Four @bb/app tests failed intermittently on Windows CI this week (group C of the flake sweep: 18 + 8 + 2 + 1 failures since 11-17, including main on 11-17, 11-19 and 11-23). Each has its own cause:

  • ThreadDetailSecondaryContent.test.tsx (up to 6 tests per failure, latest four on 11-23). The first test in the file that renders the inline panel waits for every module the panel's open-time warmup preloads. ThreadSecondaryPanelWithTabWarmup preloads ten tab-content splits (terminal, browser deck, file preview, new tab, tab content), and the panel mock loaded the real ThreadSecondaryPanel through importOriginal. The lazy-module harness settles every in-flight import before a findBy polls. That was 4.6 s and 9.8 s in passing Windows runs on main, and past the 15 s limit in failing ones. The timed-out test then leaves its act() open, so every later test in the file renders an empty <body><div/></body>. That explains the cascade of inline-secondary-panel not-found errors.
  • PromptBoxInternal.test.tsx › keeps HTML code and authored links literal… (8 failures, latest 11-19). The composer's thread-link paste extension starts a 2 s conversion budget at paste time. It then dynamically imports mentions/pasted-thread-links (remark/unified). This test is the first paste in the file, so on a cold Windows worker that module load can use up the whole budget. finish() then runs before the module is loaded, and the paste is never converted (expected [] to have a length of 2 but got +0).
  • useThreadTimelineController.test.tsx › keeps auto-loading when an older page settles before its loading state renders (2 failures). This is a real race in useAutoLoadOlderRows. Two sentinel checks can run in the same timers phase: the effect's rAF→setTimeout(0) and the scroll-position setTimeout(0). The first starts an older-page load whose mocked request settles in microtasks, which clears loadInFlightRef. The second then runs before React commits the new cursor. It reads a stale liveRef and requests the same page again with the old cursor. In the app that is a duplicate older-page request whose response is thrown away. In the test the duplicate consumes the next mocked page, so the real next load gets undefined and throws. That disables auto-load, and hasOlderTimelineRows stays true.
  • SplitThreadArea.test.tsx › carries maximization through focus, CLI-style open, and pane move (1 failure, same SHA passed on attempt 2). focusPane sets the maximized pane synchronously, so the test's first waitFor passed before the focus navigation to thr-b had committed. If that route commit landed after the test's store-only "CLI-style" open, route reconciliation moved focus back to pane-2. In the app the real CLI path (onThreadPaneAction) navigates to the newly focused pane itself, so only the test's shortened open could lose to the stale route.

What changed

  • apps/app/src/components/thread/timeline/useAutoLoadOlderRows.ts: a load now goes idle → loading → settled. Once settled, auto-load refuses to start again until React commits: settling forces that commit, and the layout effect that refreshes liveRef sets the phase back to idle. This replaces loadInFlightRef. Settling forces the commit with a useState setter, which startLoad lists as a dependency so React Compiler can keep its memoization (a useReducer dispatch or a setter destructured without its value fails the app build). The forced commit is not a dependency of the frame-delayed sentinel check: a real page already re-runs that check through its new cursor and loading state, and a load that changes nothing (a split pane hidden by maximize, whose controller returns immediately) must not re-check every frame. The first version of this PR had that dependency and re-rendered such a pane about 48 times a second; useAutoLoadOlderRows.test.tsx now covers it.
  • useThreadTimelineController.test.tsx: the auto-load race test holds the frames that are pending when the intersection fires and releases them in the same tick. Both checks then run in the same timers phase, so the test exercises the race on every run instead of by chance.
  • ThreadDetailSecondaryContent.test.tsx: the panel mock is now a plain stub (no importOriginal), and the five tab-content modules the warmup preloads are stubbed. This file renders none of them. Also deleted "keeps the panel's own hide control for the inline thread panel": it was the one test that rendered the real panel. ThreadDetailSecondaryContent has passed no inlinePanelToggle since Delete unused code, expired compatibility paths and redundant tests #4606, and the inline "Hide right panel" control is covered by ThreadSecondaryPanel.collapseControl.test.tsx. Its renderActualPanel switch is gone with it.
  • PromptBoxInternal.test.tsx: the thread URL paste describe loads pasted-thread-links in beforeAll. Its tests then cover conversion within the 2 s budget, not cold module loading. The product budget is unchanged.
  • SplitThreadArea.test.tsx: wait for the location to reach thr-b after the focus command before simulating the CLI-style open.

No server/daemon wire, CLI or doc changes.

How you verified

Reproduced each failure locally with its exact CI message, then checked the fix against the same reproduction:

  • Auto-load race: with the held-frame test, main's hook fails 37/40 runs (expected true to be false). A trace shows the same anchorSeq: 2 page requested three times. The fixed hook passes 40/40. useAutoLoadOlderRows.test.tsx and ThreadTimelineSurface.test.tsx pass.
  • No-op load loop: with a hidden-by-maximize pane whose sentinel is in range, the first version of this PR re-rendered the pane 48 times a second (main: 0). The final hook re-renders once and stops, and the new useAutoLoadOlderRows test fails on that first version (6 loads in 5 frames). The race test still passes 20/20 with the final hook.
  • Paste: delaying the pasted-thread-links module load by 2.1 s reproduces expected [] to have a length of 2 but got +0. 1.8 s passes, so the boundary is the product's 2 s timer, not waitFor. With the beforeAll, all 6 paste tests pass with the module load delayed 2.5 s.
  • SplitThreadArea: holding the focus navigation until just after the store-only open reproduces expected 'pane-2' to be 'pane-3'. The fixed test waits for that commit.
  • ThreadDetailSecondaryContent: on main at host load ~330, the first inline-panel test took 7.6 s, 8.4 s and 7.9 s, and one run hit the 15 s timeout with the same cascade as CI. With this change it took 1.4 s, 0.65 s and 1.4 s. One real ThreadSecondaryPanelTabContent load is left: vitest serves the mock to the first of six concurrent dynamic imports of that module and the real module to the rest.
  • All six affected files (ThreadDetailSecondaryContent, SplitThreadArea, useThreadTimelineController, PromptBoxInternal, useAutoLoadOlderRows, ThreadTimelineSurface) together: 5/5 runs, 328/328 passing (329/329 with the new no-op load test after the follow-up commit), at host load averages of 64–185.
  • pnpm exec turbo run typecheck lint --filter=@bb/app passes; oxfmt --check is clean.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 3 commits November 23, 2026 16:33
…nd composer paste

- useAutoLoadOlderRows: block auto-starts after a load settles until React
  commits, so a second sentinel check in the same timers phase cannot
  re-request the page with a stale cursor; re-check once per settled page.
- useThreadTimelineController test: hold pending frames so both checks run
  in one timers phase and the race is exercised deterministically.
- ThreadDetailSecondaryContent test: stub the panel and the tab-content
  splits its warmup preloads; delete the real-panel hide-control test
  (covered by ThreadSecondaryPanel.collapseControl.test.tsx).
- PromptBoxInternal test: load pasted-thread-links before the paste tests so
  module loading does not consume the 2 s conversion budget.
- SplitThreadArea test: wait for the focus route commit before the
  store-only CLI-style open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…othing

The settle counter was a dependency of the frame-delayed sentinel check, so a
load that resolved without changing the timeline (a split pane hidden by
maximize returns immediately) re-rendered and re-checked once per frame
forever. The counter now only forces the commit that returns the phase to
idle; a real page already re-runs the check through the new cursor and
loading state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The useReducer dispatch, and a useState setter destructured without its
value, are not recognised as stable, so the compiler rejected startLoad's
manual memoization and the app build failed. Use the useState setter and list
it in startLoad's dependencies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 9328fae into main Nov 24, 2026
33 checks passed
@ymichael
ymichael deleted the bb/fix-windows-app-ui-test-flakes-thr_9z3dsijk75 branch November 24, 2026 05:48
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