Skip to content

Fix the deterministic macOS failure in the floating monitor geometry test - #7714

Closed
danielhanchen wants to merge 1 commit into
mainfrom
ci-chatui-monitor
Closed

danielhanchen wants to merge 1 commit into
mainfrom
ci-chatui-monitor

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Chat UI Tests has been red across the repo's open PRs. It is not flaky: it fails deterministically on macOS, and the appearance of flakiness comes from three separate workflows publishing the same check name.

On #7686, the three checks named Chat UI Tests are three different runners:

job runner result
91316909182 macos-14 fail
91316909276 ubuntu-latest pass
91316909316 windows-latest pass

So "one of three parallel runs failed" reads as a flake but is one consistently broken platform. Every mac failure emits the identical box, {'x': 1008, 'y': 712, 'width': 256, 'height': 172}.

The race

In exercise_floating_monitor_geometry, the caller gates on the /api/system request, not its response, because ctx.on("request", ...) fires when the request is issued:

monitor_deadline = time.time() + 10
while len(system_requests) == login_system_request_count and time.time() < monitor_deadline:
    page.wait_for_timeout(100)

initial_box is then sampled a couple of IPC round trips later with no further gate. Until the response is applied, the panel paints use-system.ts's DEFAULT_SYSTEM, whose gpu is {available: false, devices: []}. On macOS detect_hardware() returns DeviceType.MLX and hardware.py:2705 reports "available": True with one device, so hasGpu flips and floating-monitor.tsx:469 renders a VRAM row. The panel's natural height changes permanently.

That makes the later predicate unsatisfiable:

lambda box: (
    abs(box["height"] - initial_box["height"]) <= tolerance
    and abs(box["y"] + box["height"] - viewport["height"] + inset) <= tolerance
)

The bottom-anchor half passes (712 + 172 = 884 = 900 - 16); only the height comparison against the stale baseline fails, which is exactly the reported box. The growth check is satisfied by the VRAM row alone, which is why growth completes in 0.4s and the shrink burns its whole deadline.

Measured against the real component with the real stylesheet: RAM alone renders 113.5px, RAM plus one VRAM row renders exactly 172.0px at y=712.

The fix

Wait for the real signal before sampling the baseline, via one wait_for_function with three conditions: a non-zero RAM total (proving a real payload replaced DEFAULT_SYSTEM), the scroll region exactly fitting the content it was reconciled against (proving the ResizeObserver pass landed), and that geometry holding for two consecutive animation frames.

The frame-stability condition is load-bearing. There is an intermediate state where both rows exist but the space-y-3 gap has not been applied, and that state is self-consistent, so an instantaneous check latches onto it. Two frames is how Playwright itself defines a stable element, and wait_for_function defaults to polling="raf", so consecutive polls are consecutive frames.

No sleeps added and no timeout raised.

Verification

The real exercise_floating_monitor_geometry was extracted from git show HEAD: (before) and the working tree (after) and run against the live component with the /api/system response held back by a randomised delay:

scenario before after
GPU-reporting host, delay 0-500ms 24/25 failed 0/25 failed
GPU-reporting host, delay 0-60ms 40/40 failed 0/40 failed
no-GPU host (ubuntu/windows control) 0/20 failed 0/20 failed

Every "before" failure reproduced the byte-identical CI string including 'height': 172. The no-GPU control explains why ubuntu and windows pass and confirms the fix does not regress them.

Scope

Test-only; no frontend or backend file is touched.

Two things this was not able to establish locally: the suite was not run end to end (the harness renders the real FloatingMonitor from the worktree through the project's own vite server and executes the real test function, but it is not the whole suite), and it was not run on macOS, so the MLX-implies-available: True step rests on the backend source plus the platform correlation of the failing jobs rather than on a mac run. CI on this PR covers both.

…geometry

The geometry check baselines the panel with a single bounding_box() taken as
soon as the caller observes an /api/system request go out. The response has not
been applied yet at that point, so the panel is still painting use-system.ts's
zero-filled DEFAULT_SYSTEM, which reports no GPU. On a host that does report one
the VRAM row then lands and adds a row permanently, so the panel never returns
to the sampled baseline and "content shrink" waits out its whole 5s deadline
before failing.

That is why this looked flaky but is not: macos-14 reports a single MLX device
and failed on every PR, while ubuntu-latest and windows-latest have no GPU row
to add and passed. Three jobs share the name "Chat UI Tests", so the one
consistent platform failure read as one of three parallel runs failing at
random.

Wait for the payload to be rendered and for the panel to have finished resizing
to it before sampling the baseline. The gate requires a non-zero RAM total, the
scroll region to exactly fit the content it was reconciled against, and that
geometry to hold for two consecutive animation frames, which is how Playwright
defines a stable element and is what wait_for_function's default polling="raf"
provides.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 7d5cc8c190

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

Superseded by #7722, which combines this with the other two repo-wide CI fixes so a single merge unblocks the whole batch. The files there are byte-identical to this PR's head, and the commits are cherry-picked with provenance. Closing.

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