Skip to content

Flaky: panel-focus.it.test.ts 'focuses the composer input when the panel opens' failed once in a serial embed gate, green in isolation and clean re-run #346

Closed

Description

@omridevk

Observed 2026-08-08 during the #326 branch gate (worktree, serial TURBO_CONCURRENCY=1 VITEST_MAX_FORKS=1, embed suite): one failure of packages/embed/test/panel-focus.it.test.ts > panel open focuses the composer > focuses the composer input when the panel opens, then 5/5 in isolation and 111/111 on a full clean embed re-run. Unrelated to the branch diff (no rebind/rpc-teardown in that test's path). Assertion text was lost (output filtered) — reproduce first.

Per the no-tolerated-flakes policy this owes a real fix, not a timeout bump alone. Suspect class: focus racing panel open animation under serial-gate machine load.

Activity

  1. omridevk commented on Aug 9, 2026

    @omridevk
    ContributorAuthor

    RCA session results (no fix shipped — root-cause trigger not yet provable):

    Reproduced at 1-4/20 under CDP CPU throttling (rate 16-24); 0/40 unthrottled. Failure: expect(locator).toBeFocused() times out, composer stays inactive.

    Proven mechanism (via patched focus/blur/remove/MutationObserver traces + probes in panel.tsx and rich-text-field.tsx):

    1. apps/conciv/src/routes/panel.tsx:52-55 autofocuses once, keyed on open() + composer handle.
    2. TipTap's focus command only calls view.focus() inside requestAnimationFrame — lands ~40-70ms late under load.
    3. In that window, ChatPane's root <div class="contents"> (apps/conciv/src/pane/chat-pane.tsx:306) is removed from the DOM by a Suspense boundary above ChatPane switching to fallback, then re-attached without recreating components.
    4. Removing the focused node drops focus to <body>; neither open() nor the handle changes, so the one-shot effect never re-fires. Focus lost permanently.

    Missing link: which read re-suspends the boundary. The detach reproduces in ~45-50% of throttled runs independent of focus timing. Disproven hypotheses (guards added, detach persisted, all reverted): registryCatalog.data under enabled: connected(); sessions.data via row() / meta.data?.harness.id; rAF starvation; editor destroyed pre-rAF; attribute mutations; explicit blur.

    Next step for whoever picks this up: build an unminified widget bundle (or reproduce in the pnpm dev vite host) so the Element.prototype.remove stack names the boundary, or instrument Solid's SuspenseContext to log which resource suspends. Preferred fix: make that read Suspense-safe (query.isPending ? undefined : query.data, the idiom at chat-pane.tsx:239) so panel content is never torn out — also fixes scroll/composer-state loss. Fallback: DOM-derived refocus rule (composer re-attached while open() and nothing focused) — carries focus-stealing risk, needs care.

    A deterministic regression test needs server-side control of when the pane's late query first loads; page.route() can't delay individual calls now that widget RPC rides the WebSocket.

    🤖 Generated with Claude Code

  2. omridevk commented on Aug 10, 2026

    @omridevk
    ContributorAuthor

    Reproduced again on 2026-08-10, on branch feat/tool-cards (PR #348), rebased onto e7529b87.

    Same shape as the original report: failed once inside a serial @conciv/embed gate run, then passed on a clean forced re-run of the same package.

    test/panel-focus.it.test.ts:50
    expectLocator(composer(page)).toBeFocused()  -> timed out
    
    • Failing run: TURBO_CONCURRENCY=1 VITEST_MAX_FORKS=1 turbo run test --filter=@conciv/embed — 26/27 files, 123/124 tests green, this the only failure.
    • Passing re-run: same command plus --force — 27/27 files, 124/124 tests green.

    Two data points that may help narrow it:

    1. It is not caused by the capture/tool-card work on that branch. Nothing in the failing path touches capture, CSS-bundle, or tool-request code, and the capture integration test in the same run passed.
    2. It reproduced in a run that was already fully serialized (TURBO_CONCURRENCY=1 VITEST_MAX_FORKS=1), so whatever the race is, serializing the gate does not remove it.

    Possibly related, given the failure is a focus assertion: this repo has a recorded landmine that ShadowRoot.activeElement returns null for focus held anywhere outside that root, so a focus assertion can be racing where the active element genuinely is rather than whether focus happened at all.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions