Skip to content

Stop the rapid-submit chat UI check failing on a fast runner - #7972

Merged
danielhanchen merged 12 commits into
unslothai:mainfrom
danielhanchen:pr/chatui-rapid-submit-race
Aug 6, 2026
Merged

danielhanchen merged 12 commits into
unslothai:mainfrom
danielhanchen:pr/chatui-rapid-submit-race

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The failure

Chat UI Tests fails on macos-14 while the identical commit passes on ubuntu-latest and windows-latest:

runner conclusion job duration
macos-14 failure 3m52s
ubuntu-latest success 10m46s
windows-latest success 10m36s
[ui] STEP rapid submit: 100 ms follow-up queues behind the first turn
playwright._impl._errors.TimeoutError: Page.wait_for_selector: Timeout 10000ms exceeded.
Call log:
  - waiting for locator("button[aria-label=\"Remove queued prompt 1\"]")

Why

The step submits a prompt, waits 100 ms, submits a follow-up, then requires the follow-up to appear as a queued item carrying a Remove control. That control exists only while the queued item is still cancellable, which requires the first turn to still be running. Nothing can queue behind a turn that has already finished.

So the check silently assumes gemma-3-270m cannot answer within 100 ms. On the macOS runner, which is roughly three times faster here, it can.

This is the same hazard the file already documents a few lines earlier, for the same model:

# 4. Wait for this turn's streaming to finish. Stop may never
#    appear (gemma-3-270m can finish before it paints), so its
#    appearance is best-effort; then wait for it to detach.

The Stop button got that treatment. The rapid-submit step did not.

The change

Keep the assertion strict where it is meaningful. If the queued control does not appear, check whether the first turn is still streaming:

  • still streaming: the queue genuinely failed to form. Screenshot and fail, exactly as before.
  • already finished: queuing was not possible, so the precondition never held. Log and continue.

The follow-up wait_for_function is untouched, so both assistant turns must still complete, both must be non-empty, and nothing may be left streaming or queued. The fast path stays covered; only the inapplicable-precondition case stops being a hard failure.

Scope

One file, tests/studio/playwright_chat_ui.py, test-only. No product code.

I could not reproduce the macOS timing locally, and would not expect to: a Linux host takes the same slow path as the two runners that already pass. The change adds an exception branch around an existing wait and alters nothing on the path those runners take, so their behaviour is unchanged by construction. Cross-platform staging CI on macos-14 is the check that exercises it.

The step submits a prompt, waits 100 ms, submits a follow-up, and requires the
follow-up to appear as a queued item with a Remove control. That control only
exists while the first turn is still running, so the check silently assumes the
first turn cannot finish within 100 ms.

On macos-14 it does. The same commit passes on ubuntu-latest and
windows-latest and fails on macos-14, where the whole job takes 3m52s against
about 10m40s elsewhere; gemma-3-270m answers inside the window, nothing queues,
and the wait times out after 10s. The Stop button a few lines above is already
documented as able to finish before it paints, for exactly this reason.

Keep the assertion where it means something: if the queued control does not
appear, fail as before when the first turn is still streaming, and only treat
it as inapplicable when that turn is demonstrably finished. The follow-up
assertion that both turns complete and nothing is left queued is unchanged, so
the fast path is still covered.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

Correcting the evidence in the description, and adding the macos-14 validation.

Validation. A cross-platform staging run of this branch on macos-14 passes, and not vacuously: the job reaches the step and continues through the remaining ~20 steps to the end.

[ui] STEP rapid submit: 100 ms follow-up queues behind the first turn
[ui] OK 100 ms follow-up waited and both assistant turns completed
[ui] STEP turn 1: 'Reply with exactly: hello'
...

Note there is no [ui] SKIP line. The queued control did appear on that run, so the strict path was taken and passed. The new branch was not exercised.

Correction 1: the runner-speed inference was not supported by the data I quoted. I put up a table showing macos-14 at 3m52s against about 10m40s for the other two and read that as macOS being roughly three times faster. That is wrong. The macOS job aborted at step 7 of about 25; the other two ran the whole script. It was short because it failed early, not because the runner is fast. The durations are not comparable and should not have been presented as evidence.

Correction 2: this is intermittent on macOS, not deterministic. The description implies macos-14 always finishes the first turn inside the window. The staging run above shows it does not. The window is marginal, which is what makes this flaky rather than a hard platform failure.

What is unchanged is the mechanism, which does not depend on either claim: the Remove queued prompt 1 control exists only while the first turn is still running, so a turn that completes within the 100 ms wait_for_timeout leaves nothing to queue and the 10 s wait can only time out. The file already documents the same model finishing faster than expected, for the Stop button, four lines above.

The change is also unchanged in effect: it fails exactly as before when the first turn is still streaming, and relaxes only when that turn is demonstrably finished, in which case the assertion's precondition never held. The trailing assertion that both turns complete, are non-empty, and leave nothing queued or streaming still runs either way.

What I cannot yet show is a run that takes the new branch, since that needs the fast timing to actually occur. The honest status is: mechanism sound, fix conservative, no regression on macos-14, and the specific timing that triggered the original failure not reproduced on demand.

The previous revision detected the fast-completion case by checking for a Stop
generating button. That signal is wrong: the composer renders Stop generating
only when queueDisabled, and while a turn is running with queuing enabled it
renders Queue message instead. A genuine queue-control regression would have
read as the fast case and been skipped.

Fix the precondition rather than the detection. The queue check needs the first
turn to outlast the 100 ms wait, so make the first prompt long enough that it
cannot finish inside it, and assert the queue control unconditionally as
before.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The previous revision leaned on a long prompt to keep the first turn alive
across the 100 ms follow-up wait. That is still a guess about model output:
sampling settings are applied after this point, GGUF_REPO can select another
model, and nothing forces the reply to be long, so an early EOS or a terse
refusal lands in the same window a short reply already did.

Delay the first turn's response with a route handler instead. The thread runs
from submit until the handler lets it through, so the window no longer depends
on the model, the prompt or the sampler, and the queue control can go back to
being asserted unconditionally. Unrouted in a finally so no later turn is
slowed.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The previous revision held the first turn with a sleep inside a sync Playwright
route handler. That handler runs on the test thread, so it fires during the
wait after the first submit, sleeps, and releases the request before the second
submit is reached. The hold sat entirely before the follow-up rather than
across it, so a fast first response could still finish first and the queued
selector could still time out.

Move the follow-up and the observation into the page. A timer submits the
second prompt 100 ms after the first, and a poll records whether the queued
control appeared; both keep running while this thread is parked in the handler.
The follow-up is therefore sent while the response is still held, so the first
turn is necessarily running, and a missing queue control is a real regression
rather than timing. The composer value goes through the native setter and an
input event, since React reverts a plain assignment on the next render.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The follow-up captured the textarea before the first submit. This is the chat's
first message, so sending it flips thread.isEmpty and the welcome composer is
replaced by the dock composer. The captured node is detached by the time the
timer runs: its input event never reaches React's delegated handler and
requestSubmit fires on a form outside the document, so nothing is queued.

Query the live textarea inside the timer instead, retrying briefly while the
replacement mounts. Also stop reporting success unconditionally: the flag is
set only after a submit into a connected form, and an error is recorded and
raised otherwise, so a composer that never appears cannot read as a missing
queue control.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
The macos-14 run failed with the guard this step added: the first turn's
request was never intercepted, so nothing was held and the step tested nothing.
The route glob simply did not match what the composer calls.

Intercept everything for the duration of this step and decide in the handler by
URL. A glob that stops matching is silent; a predicate on the URL cannot miss,
and the cost is one string check per request for one step. The failure now also
prints the candidate URLs seen, so a future mismatch does not need another CI
round to diagnose.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The macos-14 run showed the step completing in 0.24s having intercepted
nothing: saw 0 candidate URLs. The fixed 100 ms delay raced the first request
being issued at all, so the follow-up went out before there was anything to
queue behind and the hold had nothing to hold.

Gate on the user bubble appearing instead, which is what happens when the first
submit registers. The response is held from that point until the handler
releases it, so the turn is necessarily still running when the follow-up goes
out. The error string now also covers a first turn that never registers, so the
two causes stay distinguishable.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
Two constraints ruled out every previous shape. A sync Playwright route handler
runs on the test thread, so holding a request there blocks the test and the
follow-up cannot be sent during the hold. And the page cannot observe a
Playwright interception, so no in-page timer can be aligned with one: the last
three runs failed with the step's own guard, saw 0 candidate URLs, because the
follow-up went out before the first request had been issued at all. Gating on
the user bubble did not help either, since the UI adds it optimistically before
the network call.

Wrap fetch in the page instead. The page sees the exact moment the first turn's
request goes out, sends the follow-up then, and delays that response itself, so
the turn is provably still running with no timing assumption anywhere. The
wrapper is restored afterwards rather than left installed.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

Green on macos-14, the runner this started on.

[ui] STEP rapid submit: 100 ms follow-up queues behind the first turn
[ui] OK 100 ms follow-up waited and both assistant turns completed
[ui] STEP turn 1: 'Reply with exactly: hello'
...

Not a vacuous pass: the assertion is unconditional, so reaching that line requires the first turn's request to have been intercepted and the queued control to have been observed while it was held. staging-7972 macos-14, staging-7972 studio-playwright, Mac Studio UI CI and Unsloth UI CI are all green on the same commit, and the script continues through the remaining twenty-odd steps.

Recording what the review process changed here, since the final shape is nothing like the first one:

  1. detecting the fast case via Stop generating was unsound: the composer renders that only when queueDisabled, so a real queue regression would have been classified as fast completion and skipped
  2. a long prompt was a prediction about model output, not a guarantee: sampling is pinned later, GGUF_REPO can select another model, and an early EOS lands in the same window
  3. time.sleep in a sync Playwright route handler runs on the test thread, so the hold sat entirely before the follow-up rather than across it
  4. the composer was captured before the first submit, but this is the chat's first message, so thread.isEmpty flips and the welcome composer is replaced; the captured node was detached
  5. three CI runs then failed on this step's own guard with saw 0 candidate URLs, because the follow-up was going out before the first request had been issued at all
  6. gating on the user bubble did not fix that either, since the UI adds it optimistically before the network call

The last two are the constraint that decides the design: a Playwright interception cannot be observed from the page, and a sync route handler cannot hold a request without blocking the test. So the hold moved into the page. Wrapping fetch means the page sees the exact moment the first turn's request goes out, sends the follow-up at that instant, and delays that response itself. There is no timing assumption left anywhere, and no dependence on what the model does. The wrapper is restored afterwards rather than left installed.

Net effect on the assertion: unchanged from before this PR, still unconditional. What changed is that its precondition is now established rather than assumed, and the two failure modes, "could not send the follow-up" and "follow-up did not queue", are separate messages instead of one ambiguous timeout.

Two gaps in the previous revision.

In the exact regression this step exists to catch, the follow-up submits and no
queue control appears, so queueSeen and error both stayed false forever. The
wait then died on a generic 60s Playwright timeout and the screenshot, the
explicit message and the fetch teardown below it were unreachable, while the
poll had already stopped silently. An observation deadline now resolves the
wait so the assertion and cleanup always run, and the message carries the
submitted and intercepted flags.

Scheduling the follow-up only from inside the completion interceptor also
narrowed what this covers: by then run-start persistence has been awaited, so
the pre-render interval the step is named after was no longer exercised. Arm a
100 ms timer at submit as well; whichever fires first wins and the other is a
no-op, so the window is covered again without giving up the guarantee when
persistence delays the request.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Round 6 addressed in 5c8076e2d.

The retry-window point was right: the composer retry ran on its own 5 s deadline while the intercepted response was released after 3 s, so a retry landing at 3-5 s could submit after the first turn had already finished and report a queue failure for correct behaviour. The interception now records state.holdUntil = Date.now() + holdMs and the retry takes Math.min(deadline, state.holdUntil - 250), so the follow-up can only be sent while the response is genuinely still held.

The restore-before-interception point no longer applies to this head: e66cdcd38 changed the guard to if not state["queueSeen"] and not state["intercepted"], so a run where the queue formed before the first request was observed passes on queueSeen alone. Restoring fetch there is safe because the wrapper is replaced with the real one.

Validated on macos-14 with the change actually staged (verified by file content, not by a push report). The step is non-vacuous:

[ui] STEP rapid submit: 100 ms follow-up queues behind the first turn
[ui] OK 100 ms follow-up waited and both assistant turns completed
[ui] STEP turn 1: 'Reply with exactly: hello'
...
[ui] PASS comprehensive UI flow

Separately, this is also the fix for the Chat UI Tests red currently showing on unrelated PRs. main's version of this step waits a fixed 100 ms and then requires the queued-prompt control within 10 s, with nothing holding the first turn open, so a fast local GGUF finishes inside the window and the assertion times out on an application that behaved correctly.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 5c8076e2d6

ℹ️ 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

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1bebfc67df

ℹ️ 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".

// The request is out and the turn is running. Send the
// follow-up now, then keep the response pending so it
// cannot complete first.
setTimeout(() => sendFollowUp(), 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the follow-up on the 100 ms timer

When the first chat/completions fetch starts before the 100 ms timer, this zero-delay callback submits the follow-up immediately and sets state.submitted, making the later 100 ms callback a no-op. At that point assistant-ui has already entered the request/run path, so the follow-up can queue through liveThreadIsRunning even if the pre-stream reservation that this test is intended to verify is broken; this is especially likely on the fast-runner path motivating the change. Delay the response here, but let only the timer armed 100 ms after the original form submission send the follow-up.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The two callbacks are not ordered the way this reads. The follow-up goes out at min(fetch_start, 100 ms) after the first submit, so the zero-delay callback can only ever make it earlier than the timer, never later. Whichever fires first sets state.submitted and the other is a no-op, so removing the zero-delay send would move the submit later in exactly the fast case the concern is about.

The stronger point is that both callbacks sit on the same side of liveThreadIsRunning. The reservation is taken in sendReservedComposer before aui.composer().send(), and chat/completions is only reachable from inside the adapter's run(), which is where findPreStreamRunReservation / adoptPreStreamRunReservation run. By the time the interceptor can observe a request the run has already started, and at 100 ms it has started at least as certainly. So neither path is the one that isolates livePreStreamRunActive.

The window where that gate is the only thing holding the queue is the opposite case: the request delayed past 100 ms by persistence. The 100 ms timer still owns that case and this PR does not touch it.

The arming call also runs after requestSubmit() returns, so the timer is at submit + round trip + 100 ms, which widens the gap rather than closing it.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 6, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 6, 2026
@danielhanchen
danielhanchen merged commit 4ce9bf0 into unslothai:main Aug 6, 2026
17 checks passed
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.

2 participants