Skip to content

fix(agent): wait for snapshot frames on DOM events, not a 16ms timer poll - #645

Open
ngocht wants to merge 1 commit into
CoreBunch:mainfrom
ngocht:fix/agent-snapshot-frame-wait
Open

ngocht wants to merge 1 commit into
CoreBunch:mainfrom
ngocht:fix/agent-snapshot-frame-wait

Conversation

@ngocht

@ngocht ngocht commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Summary

waitForAgentRenderFrame polled every 16ms with chained setTimeouts. In a background tab Chrome throttles chained timers to once per second, and to once per minute after five minutes hidden. An MCP site_render_snapshot routed to an unfocused editor could therefore stall for minutes.

It now re-checks on a MutationObserver over the canvas DOM and the readiness markers (data-instatic-canvas-document-loaded, data-agent-snapshot-ready, the breakpoint and request-id attributes). Observer callbacks are microtasks and are not throttled. A 250ms timer stays as a fallback; the 5s deadline is unchanged.

Impact: render snapshots resolve as soon as the frame is ready, whether or not the editor tab is focused.

Verification

  • bun run build — ran tsc -p tsconfig.app.json (clean)
  • bun test — ran bun test src/__tests__/agent/: 269 pass. New renderFrameWait.test.ts simulates throttled timers (every timer ≥1s): resolves in <500ms with this change, fails (1035ms) on main.
  • bun run lint — eslint on the changed files (clean)
  • Docker/deployment check, if relevant

Checklist

  • Tests cover behavior changes.
  • Docs were updated when behavior, config, deployment, or public surfaces changed.
  • No compatibility shim was added for old pre-release behavior.
  • No secrets, local databases, uploads, or generated artifacts are included.

🤖 Generated with Claude Code

…poll

waitForAgentRenderFrame polled every 16ms with chained setTimeouts. In a
background tab Chrome throttles chained timers to once per second, and to
once per minute after five minutes hidden, so an MCP render snapshot routed
to an unfocused editor could stall for minutes.

It now re-checks on a MutationObserver over the canvas DOM and readiness
markers; observer callbacks are microtasks and are not throttled. A 250ms
timer stays as a fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ngocht
ngocht marked this pull request as ready for review October 14, 2026 18:12

This branch has not been deployed

No deployments
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.

1 participant