Skip to content

[Bug]: Preview click / hover / drag abort when the target node is replaced mid-probe #30585

Closed

Description

@vtsixthai

DRAFT, NOT SENT — issue text for pingdotgg/t3code

Status: draft. Nothing was posted, commented, emailed, opened or subscribed. This file exists so the
owner can approve, edit or discard one specific external publication.

Destination (verified in UPSTREAM-DESTINATION.md):
https://github.com/pingdotgg/t3code/issues/new?template=bug_report.yml

Fields below are written to match .github/ISSUE_TEMPLATE/bug_report.yml at
main @ a185dd924889cd7f925760431a9f29b973a35e2f.


Title

[Bug]: Preview click / hover / drag abort when the target node is replaced mid-probe

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Serve a page whose target element is removed and re-created on a short interval (40 ms was
    sufficient for the original observation), with the same selector resolving to the new node:

    <button id="save">Save</button>
    <script>
      setInterval(() => {
        const old = document.querySelector('#save');
        const next = old.cloneNode(true);
        old.replaceWith(next);
      }, 40);
    </script>
  2. From a thread, call preview_open on that page and take a preview_snapshot.

  3. Invoke the normal selector-based preview click (on the observed build: preview_act with
    action: "click"), with timeoutMs in the 300–3000 range. The same positioning helper also
    affects hover and drag; source-level tests can exercise their ServerBrowserPage handlers.

  4. Observe: no trusted click reaches the element, and the call fails with an execution error whose
    message contains Element is not attached to the DOM. Repeating the same call sometimes succeeds,
    depending on whether the probe lands between replacements.

A reduced timing model reproduces the same abort deterministically without a browser: with
timeout = 300, a scroll call that consumes 270 ms and succeeds, and a boundingBox that needs 100 ms,
the shipped code gives the box probe its full 300 ms budget and succeeds. An earlier proposed
repair incorrectly gave the box only about 30 ms and failed; the attached corrected candidate restores
the shipped full box budget and succeeds. This separate regression control validates the candidate,
not an additional defect in the shipped box probe.

Expected behavior

A click, hover or drag whose target is replaced while targetPoint is positioning should re-resolve
the locator inside the caller's existing timeout and dispatch once. A target that stays un-attached
should still fail, bounded, with zero input dispatched.

Actual behavior

targetPoint in apps/server/src/preview/ServerBrowserPage.ts probes the node once:

await locator.scrollIntoViewIfNeeded({ timeout });
const box = await locator.boundingBox({ timeout });

scrollIntoViewIfNeeded throws Element is not attached to the DOM as soon as the node is replaced,
before any input is dispatched, and the whole gesture is abandoned. targetPoint is shared by
click, hover and drag, so all three abort the same way. The failure is state-dependent: the same
call can succeed on the next attempt purely because a probe landed between replacements.

Scope check performed while preparing this report: the targetPoint body is unchanged in the
published source at v0.1.0, v0.1.2, v0.1.3, v0.1.4, v0.1.5, v0.1.6, and at
main @ a185dd924889cd7f925760431a9f29b973a35e2f (2026-11-04). It is also token-identical to the
body extracted from a shipped 0.1.5 single-executable, so the published releases and the running
server carry the same code. Nothing in the file mentions the detach message.

Impact

Minor bug or occasional failure

The action is not silently wrong: it fails without dispatching input, and a caller that treats the
error as retryable recovers. It costs a failed tool call and a retry when a target re-renders during
positioning, which is common on pages that re-render lists, tables or modals.

Version or commit

main @ a185dd924889cd7f925760431a9f29b973a35e2f, and in the checked releases v0.1.0, v0.1.2, v0.1.3, v0.1.4,
v0.1.5 and v0.1.6 (no claim about unchecked tags). The observed failure was on a 0.1.5 server build.

Environment

Linux x86_64 server, t3 serve on a background service, agent driving the shared browser preview over
the preview tools; playwright-core 1.60.0 as bundled by the server.

Logs or stack traces

PreviewAutomationExecutionError: Element is not attached to the DOM

Workaround

No reliable caller-side workaround was validated. A sampled stability check before the normal
click still reproduced the same failure. Selector-bound keyboard activation is not exposed by the
observed tool build; a global Enter is not a safe substitute. This report does not recommend a
JavaScript-click bypass. A retry after an uncertain input outcome can duplicate an action, so it is
not proposed as a general workaround.


Note for the maintainer: a candidate change, not a merge-ready patch

A one-function change that retries only this failure was developed and independently reviewed
elsewhere. It is offered as a starting point because the review work is done, not as a finished PR.
Two limits are stated deliberately:

  1. It was written against the function body, not against the TypeScript module. It reproduces the
    exact shipped behaviour of the function; the two in-function constants can be hoisted to module
    scope when rebasing. The rebase target is apps/server/src/preview/ServerBrowserPage.ts; in
    v0.1.5 the function is lines 134–146.
  2. The detach test is a substring match, not an exact match. The message check is
    /Element is not attached to the DOM/. A different error whose message echoes a selector
    containing that sentence would also be retried. That case is bounded (a short retry series, zero
    input dispatched, the same error object rethrown) but it is a real false-positive class, so
    anchoring to the whole message would be preferable if this lands. This report does not claim exact
    discrimination of the detached state.

Behaviour the change would add:

  • One input dispatch per action, and zero on every failure path. The probe never dispatches input.
  • At most one bounded retry series per action for the detach case, bounded by the caller's timeout;
    unmatched errors are rethrown unchanged on the first call with the same error object; the
    substring false-positive exception described above remains open for maintainer review.
  • No new error tag, no new message text, no schema field, no handler change. hover and drag change
    identically because they share this function, and drag never retries or resumes a pointer
    sequence after input has begun.
  • The retry bound covers scroll re-resolution only. The box probe and the input call keep their own
    timeouts, so total action time can exceed the caller's timeout.
  • Known limit, stated rather than fixed: a node that detaches after a successful probe still fails the
    action safely. This narrows one window; it does not make the gesture atomic.
  • One observable difference: when the retry probe itself times out, the public error becomes a
    timeout rather than the captured detach error. Both are bounded failures with zero input.

Two things about the surrounding code that this report does not attempt to resolve, because issue
#25557 proposes a single shared deadline across targetPoint and the subsequent click, while this
change preserves the current per-step timeout behaviour. If a shared-deadline model lands, the retry
series should draw its budget from the remaining request time instead.

Request

  1. Confirm the abort is worth a change, and decide whether it belongs with the shared-deadline work in
    [Bug]: preview_click still gives each step a full timeout after #17693, so a stalled click's reason never reaches the agent #25557.
  2. If yes, review a rebased version against the module and its existing tests.
  3. Cover all three consumers in apps/server/src/preview/ServerBrowserPage.test.ts: mid-probe detach
    for click, hover and drag, each asserting success and exactly one input call, plus unchanged
    ordinary-error and un-attached-target cases.
  4. Ship it through the normal release process. No version, digest or release identifier is asserted
    here.

Pre-publication checklist for the owner

Check State
Destination is the official project, not a derivative yes, UPSTREAM-DESTINATION.md §2–§4
Matches the repo's issue form yes, fields above follow bug_report.yml
Duplicate search done and recorded yes, EXISTING-FIX-STATUS.md §3
No business, hotel, rate, credential, browser-profile or channel-manager detail yes
No local thread ids, host paths or private data yes
Overclaims removed (exact-sentinel, error parity, scope, release authority) yes
Discloses the unanchored-match false positive yes, maintainer note item 2
Discloses the patch's rebase requirement yes, maintainer note item 1
Sent NO
--- a/ServerBrowserPage.targetPoint.js
+++ b/ServerBrowserPage.targetPoint.js
@@ -3,8 +3,35 @@
 			x: input.x ?? 0,
 			y: input.y ?? 0
 		};
-		await locator.scrollIntoViewIfNeeded({ timeout });
-		const box = await locator.boundingBox({ timeout });
+		// Bounded re-resolution of the positioning probe. A node replaced while the probe runs makes
+		// scrollIntoViewIfNeeded throw "Element is not attached to the DOM" immediately; that one state
+		// is retried inside the caller's existing timeout. Every other failure is rethrown unchanged.
+		// No input is dispatched here: the single click still happens once, after this returns.
+		const DETACHED_ONLY = /Element is not attached to the DOM/;
+		const BACKOFF_MS = [20, 20, 100, 100, 500];
+		const MIN_PROBE_MS = 50;
+		const deadline = Date.now() + timeout;
+		let cause = null;
+		let attempt = 0;
+		let box = null;
+		for (;;) {
+			const remaining = deadline - Date.now();
+			if (cause !== null) {
+				if (remaining <= MIN_PROBE_MS) throw cause;
+				const wait = Math.min(BACKOFF_MS[Math.min(attempt - 1, BACKOFF_MS.length - 1)], remaining - MIN_PROBE_MS);
+				await new Promise((resolve) => setTimeout(resolve, wait));
+			}
+			try {
+				await locator.scrollIntoViewIfNeeded({ timeout: Math.max(1, deadline - Date.now()) });
+				box = await locator.boundingBox({ timeout });
+				break;
+			} catch (error) {
+				const message = error instanceof Error ? error.message : String(error);
+				if (!DETACHED_ONLY.test(message)) throw error;
+				cause = error;
+				attempt++;
+			}
+		}
 		if (box) return {
 			x: box.x + box.width / 2,
 			y: box.y + box.height / 2
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