Repository navigation
fix(engine): retry transient screenshot refusals in place - #9219
miguel-heygen wants to merge 2 commits into
Conversation
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 993ff0f53f. I read the source changes and new tests at 1eb02aa818, then the delta to this head (two field comments removed, nothing else).
Verdict: approve. No blocker.
Need: yes, one refused screenshot should not end the pool · Size: ok · Reuse: the refusal pattern stays single-owner in captureFailure.ts and the existing segment recycle is reused · Simpler: already minimal, one sendCaptureScreenshot helper for all four call sites · Structure: fine (checked TRANSIENT_BROWSER_ERROR_PATTERNS and isTargetLossError; no split)
Risk: low — bounded retry (2 tries, 150 ms and 300 ms) on one exact message; other errors pass through unchanged.
What I checked
- Every production
Page.captureScreenshotsend now goes throughsendCaptureScreenshot(pageScreenshotCapture,captureAlphaPng,captureScreenshotWithAlpha, the 1x1 compositing shot inframeCapture.ts). The only raw sends left are test fixtures. - Both
captureAlphaPngcallers (hdrCompositor.ts,captureHdrFrameShared.ts) pass the retry callback. captureScreenshotWithAlpharetries inside itstry, so the background override is restored once.- The refusal was already classed as
transient_browser, so the whole-render fallback still sits behind the in-place retry and the segment recycle. Worst case is bounded.
"fails without the fix:" line is present. I turned the fix off locally and reran:
- retry disabled in
sendCaptureScreenshot: 4 engine tests fail (3 inscreenshotService.test.ts, 1 inframeCapture-screenshotRetry.test.ts). - refusal removed from
isTargetLossError: 2 producer tests fail (segmentRecycle.test.ts, the newcaptureSegmentedStage.test.tscase). - restored: engine 71/71 (3 files), producer 44/44 (2 files), cli 99/99 (2 files).
Not run: a real browser render, the sibling suites listed in the body, lint and typecheck (CI was still pending when I posted).
Nits, none blocking
screenshot_retriessits next tocapture_transient_retries;capture_screenshot_retrieswould match the neighbours.- A recycled segment after a refusal logs "browser target lost". The target was not lost; a neutral message would read better in a log.
- The backoff sleep does not watch the abort signal (at most 450 ms).
— Rames
Edit accuracy: accurate 275 (base branch 275), smooth 52 of thoseThe gate passes. Quarantined, measured but not gated (0) |
Summary
Chrome's
Page.captureScreenshotCDP call can transiently reject a single frame withProtocol error (Page.captureScreenshot): Unable to capture screenshotduring long or busy renders. Previously,pageScreenshotCapture,captureAlphaPng,captureScreenshotWithAlpha, and the page-side compositing micro-screenshot did zero in-place retries, so one refusal immediately aborted the worker pool and discarded captured frames; segmented renders also omitted this refusal fromisTargetLossError, so they never recycled the browser and retried the segment.Changes
packages/engine/src/services/captureFailure.ts): extractisTransientScreenshotRefusalanchored toProtocol error (Page.captureScreenshot): Unable to capture screenshotand reuse the same pattern insideTRANSIENT_BROWSER_ERROR_PATTERNS.packages/engine/src/services/screenshotService.ts,packages/engine/src/services/frameCapture.ts): routepageScreenshotCapture,captureAlphaPng,captureScreenshotWithAlpha, and the page-side compositing micro-screenshot throughsendCaptureScreenshot, retrying up to 2 times with short exponential backoff (150ms, 300ms) only onisTransientScreenshotRefusal. Deterministic screenshot errors (such as zero-width screenshots), target loss, and timeouts propagate without extra retries;captureScreenshotWithAlphastill restores the background color override once infinally.packages/producer/src/services/render/segmentRecycle.ts): includeisTransientScreenshotRefusalinisTargetLossErrorso segmented renders recycle the browser and retry the segment once if in-place per-frame retries are exhausted.packages/engine/src/types.ts,packages/producer/src/services/render/observability.ts,packages/producer/src/services/renderOrchestrator.ts,packages/cli/src/telemetry/renderObservability.ts,packages/cli/src/telemetry/events.ts): wireonScreenshotRetryintoRenderCaptureObservability.screenshotRetriesand emitscreenshot_retriesonrender_completeandrender_error.Verification
fails without the fix:
packages/engine/src/services/screenshotService.test.ts(3 new retry tests threwUnable to capture screenshoton attempt 1),packages/engine/src/services/frameCapture-screenshotRetry.test.ts(aborted mid-render on frame 1 refusal),packages/producer/src/services/render/segmentRecycle.test.ts(isTargetLossErrorreturnedfalse),packages/producer/src/services/render/stages/captureSegmentedStage.test.ts(failed segment without recycling),packages/cli/src/telemetry/renderObservability.test.ts(captureScreenshotRetrieswasundefined), andpackages/cli/src/telemetry/events.test.ts(screenshot_retriesomitted fromrender_complete/render_error).packages/engine/src/services/screenshotService.test.ts(43 tests: single refusal recovery, exhaustion after 2 retries, no retry on deterministic/target-loss/timeout errors, alpha and background-override restore)packages/engine/src/services/frameCapture-screenshotRetry.test.ts(multi-framecaptureFrameToBufferrun where a fake page refusesPage.captureScreenshotonce mid-render and finishes with every frame intact andonScreenshotRetrycounted)packages/engine/src/services/captureFailure.test.ts(27 tests)packages/producer/src/services/render/segmentRecycle.test.ts(3 tests) andpackages/producer/src/services/render/stages/captureSegmentedStage.test.ts(41 tests)packages/cli/src/telemetry/renderObservability.test.ts(12 tests) andpackages/cli/src/telemetry/events.test.ts(87 tests)renderOrchestrator.test.ts(313),captureStage.test.ts(24),captureStreamingStage.test.ts(62),captureHdrFrameShared.dom-mask.test.ts(1).oxlint,oxfmt --check,fallow audit --base origin/main --fail-on-issues, andtsc --noEmitacross engine, producer, cli, core, and scripts all green.