Repository navigation
fix(serve): dismiss a dialog that opened while no client was attached - #91
Merged
Merged
Conversation
tenequm
force-pushed
the
fix/orphan-dialog-attach
branch
2 times, most recently
from
September 19, 2026 00:22
ecc9f0f to
cc54111
Compare
…r's context The watch now tracks dialogs with openDialogs.observe/take and shares its dismissal rounds, fires its commands without a reply map, prefilters frames before decoding, and writes on a context detached from the connecting client: coder/websocket closes the whole connection when a write's context ends, so a client leaving mid-dismissal ended the watch for the rest of that browser's life.
An orphaned dialog held an idle reap's state capture for the full 30s captureTimeout, with the seed lock held, so a reconnect to that seed waited too. The browser is going away, so its dialogs are dismissed first.
tenequm
force-pushed
the
fix/orphan-dialog-attach
branch
from
September 19, 2026 00:28
cc54111 to
8f581ec
Compare
tenequm
added a commit
that referenced
this pull request
Sep 19, 2026
## Problem #91 has the dialog watch dismiss an orphaned dialog before the teardown capture, on an idle reap and on shutdown. On a signal shutdown (`cuttle down`, `docker stop`) that dismissal never landed. The watch's read loop ran on `pool.baseCtx`, which is the daemon's `signal.NotifyContext` context. coder/websocket closes a connection when a `Read`'s context ends, so SIGTERM closed every watch before `pool.shutdown()` reached `captureAndTerminate`. The dismissal then wrote to a closed socket and dropped the error, while still logging `dismissing 1 native dialog(s)`. The capture sat on the dialog until the shared `shutdownCaptureBudget` ran out, which cost every other seed its final snapshot as well. ## Fix The watch now uses `ctx` only to bound its dial. Its read loop runs on `context.WithoutCancel(ctx)`, so it ends when the browser's connection does. Chrome's exit (terminate, SIGKILL after grace, or a crash) closes the loopback socket, so the watch cannot outlive its browser. ## Verification Live test, headed session mode, one image per side. Open https://example.com, write a localStorage key, schedule `setTimeout(() => alert('x'), 3000)`, detach, wait 6s, then `docker stop -t 40`. - main: the stop took 8.4s and logged `shutdown: 8s budget spent before every seed was snapshotted`. - this branch: the stop took 0.55s, and the capture completed 0.26s after the dismissal. - The #91 attach path still works on this branch: after an orphaned dialog, the next client's `Page.enable` answers in 1ms. `just check` and `go test -race -count=5 ./internal/serve/` pass. ## Release notes `cuttle down` or a container stop no longer waits out its whole snapshot budget when a native dialog opened while no driver was attached. The dialog is dismissed before the final capture, so every seed's final state is saved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A native dialog that opens while no CDP client is attached (a page timer that fires after
cuttle pw detach, or after the driver dropped) is seen by no session, so the dismiss-on-disconnect from #87 never runs. Chrome binds a pending dialog to the DevTools sessions that were Page-enabled when it opened: a later client'sPage.enablewaits on the blocked renderer, and itsPage.handleJavaScriptDialoggets "No dialog is showing". Every latercuttle pwauto-attach hung until playwright's 30s timeout, and only closing the tab recovered.Fix
Each launched browser now gets a
dialogWatch: the daemon's own browser-level CDP connection that auto-attaches to every page (existing and future, pages only), enables Page on each, and tracks which tabs have a dialog showing. When a client connects to a seed that had no other client,serveWShas the watch dismiss those dialogs before the client is proxied, including any a dismissal sets off (same rounds as #87). The watch reuses #87'sopenDialogstracking and dismissal rounds, and writes on a context detached from the connecting client (coder/websocket closes the whole connection when a write's context ends).An idle reap or shutdown also has the watch dismiss any dialog before the teardown capture: an orphaned dialog otherwise held the capture for the full 30s
captureTimeoutwith the seed lock held (measured live in pool mode: 30s before, 0.27s after).It does not dismiss at open time: with no client attached the dialog may be the person's in the viewer, and with a client attached it is that client's to answer (it still surfaces to playwright as a modal state). Works the same in session and pool mode, since every instance comes from
spawn. Best-effort: a browser the watch cannot dial simply has none.Verification
Live, against an image built from this branch, with a page doing
setTimeout(() => alert('x'), 3000):pw goto,pw detach, wait 6s,pw snapshot.pw snapshotfailed after 32s (playwright attach timeout).pw snapshotreturned the page in 3s; the log showsdismissing 1 native dialog(s) no client answered.pw tab-new).pw snapshotstill reportsModal state: ["alert" dialog with message "x"]andpw dialog-dismissclears it.--mode=pool --idle-timeout=10, raw CDP client per seed): the next attach'sPage.enableanswers in ~260ms after an orphaned dialog; after an idle reap the relaunched browser gets a fresh watch and the same fix holds.alert()does not change in/json/list) until the next client connects.New unit test
TestDialogWatchDismissesADialogNoClientSawdrives the watch against the fake browser harness; it fails when dismissal is disabled.just checkpasses.Release notes
A native dialog (alert, confirm, "Leave site?") that opens while no driver is attached no longer hangs the next
cuttle pwcommand for 30s: cuttle dismisses it when the next client connects. A dialog that opens while a driver is attached still reaches the driver.