Live: the loader now hands off when the resume is the arrival

The overlay could sit in its generating shader over a DOM that already
held all three variants, and only a page refresh cleared it (#719).

The server's generation preflight runs live-wrap with
--defer-source-write, so the wrapper and every variant reach the DOM in a
single HMR batch. The deferred-wrapper scout is constructed at init and
the variant MutationObserver at Go; observer callbacks run in
construction order, so on that batch the scout resumes first and
resumeSession, not the observer, is the transition into CYCLING. It set
the state and the bar but never called hideShaderOverlay(), so the frozen
capture of the original stayed painted over the variants. It also
reported browser_resumed, which does not count as publication progress,
and then disconnected and re-created the observer, dropping the records
that observer had already queued for the same batch, so variants_ready
never fired at all.

resumeSession now finishes the same transition the observer does (shader
down, inline edit off, insert session finalized, params panel rebuilt)
and reports variants_ready when it already holds every variant. The
deferred scout names itself in the journal as
browser_resumed_deferred_wrapper, so the two resume paths are no longer
indistinguishable.

Wrapper resolution goes through findVariantsWrapper, which prefers a
wrapper that actually holds non-original variants. A target inside a
.map() renders one wrapper per item, and an agent that relocates the
wrapper out of the shared primitive live-wrap scaffolded leaves an empty
one behind; first match could pin either and strand the session at 0/N.
With zero or one match this is the querySelector it replaces.

Tests: waitForCycling now asserts the generating shader is gone once the
bar cycles, across every runtime fixture (it failed on vite8-react-plain
before this change and passes after), marked no-retry so the reload
recovery cannot hide it. Source-shape tests pin the transition, the
variants_ready report, and the wrapper preference.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vau2X53xGTjjTCXWMVBoNY
This commit is contained in:
Paul Bakaus
2026-09-04 00:10:03 -07:00
co-authored by Claude Code
parent 3a857af9ea
commit 5e626e2d9f
5 changed files with 152 additions and 17 deletions
+3 -2
View File
@@ -93,7 +93,8 @@ export async function waitForCyclingRobust(page, expectedCount, opts = {}) {
try {
await waitForCycling(page, expectedCount, { timeout: firstPassTimeoutMs });
return;
} catch {
} catch (preErr) {
if (preErr?.impeccableNoRetry) throw preErr;
log(`Cycling not reached in ${firstPassTimeoutMs}ms — retracing preActions`);
await runPreActions(page, preActions);
}
@@ -106,7 +107,7 @@ export async function waitForCyclingRobust(page, expectedCount, opts = {}) {
if (process.env.IMPECCABLE_E2E_DEBUG) {
firstErr.message += '\n\n--- live UI snapshot ---\n' + JSON.stringify(await liveUiSnapshot(page), null, 2);
}
if (agentMode !== 'llm') throw firstErr;
if (agentMode !== 'llm' || firstErr?.impeccableNoRetry) throw firstErr;
}
log('Cycling not reached after LLM generate — reloading to pick up HMR');
+30
View File
@@ -605,6 +605,35 @@ export async function clickGo(page) {
throw lastErr || new Error('Go click did not leave configure mode');
}
/**
* The generating shader is the visible loader: a frozen capture of the
* original painted over the target while variants are being written. Every
* transition into CYCLING has to take it down, so a cycling bar with the
* shader still up is the stuck loader from issue #719, not a cosmetic
* detail. The transition is synchronous, so a short window is generous.
*/
async function assertGeneratingShaderCleared(page) {
const stillUp = await page
.waitForFunction(
() => !(window.__impeccableLiveQuery || document.querySelector.bind(document))('#impeccable-live-shader'),
undefined,
{ timeout: 5_000 },
)
.then(() => false)
.catch(() => true);
if (stillUp) {
const err = new Error(
'CYCLING reached but the generating shader overlay (#impeccable-live-shader) is still up: '
+ 'the loader never handed off to the variant cycler',
);
// Cycling was reached, so the recovery paths in waitForCyclingRobust
// (retrace preActions, reload) have nothing to recover and a reload would
// hide the defect by taking the shader down with the page.
err.impeccableNoRetry = true;
throw err;
}
}
/**
* Wait for the bar to enter CYCLING state — happens after the agent's
* variants land in the DOM via HMR and the MutationObserver counts them.
@@ -636,6 +665,7 @@ export async function waitForCycling(page, expectedCount, { timeout = 30_000 } =
{ barSel: BAR_ID, expected: expectedCount },
{ timeout },
);
await assertGeneratingShaderCleared(page);
} catch (err) {
if (process.env.IMPECCABLE_E2E_DEBUG) {
const snapshot = await page.evaluate((barSel) => {