Skip to content

fix(browser): propagate snapshot timeouts - #856

Merged
artemgetmann merged 1 commit into
mainfrom
codex/browser-snapshot-timeout-recovery-20260605
Jun 5, 2026
Merged

artemgetmann merged 1 commit into
mainfrom
codex/browser-snapshot-timeout-recovery-20260605

Conversation

@artemgetmann

Copy link
Copy Markdown
Owner

Review Fast Path

  • User path fixed: browser.snapshot on heavy pages now uses the caller timeout budget for Playwright AI snapshots and refs=aria, instead of falling into a hidden 5s timeout.
  • Proof: pnpm exec vitest run src/browser/server.agent-contract-snapshot-endpoints.test.ts; pnpm exec vitest run --config vitest.e2e.config.ts src/browser/pw-ai.e2e.test.ts; changed-file oxlint --type-aware; git diff --check.
  • Shared-state footgun removed: recoverable Playwright snapshot failures disconnect only the exact targetId, then local managed profiles fall back to the same tab's raw CDP aria snapshot.
  • Still hurts: live GrabFood proof still pending until after PR/merge/runtime-safe validation.

Why This Matters

  • GrabFood-style heavy pages can take longer than Playwright's private snapshot default.
  • The browser tool should not wedge or quietly fail at 5s when the caller requested a larger budget.

Scope Boundary

  • Parses and clamps snapshot timeoutMs at the plan boundary.
  • Threads timeout through route calls into snapshotAiViaPlaywright and snapshotRoleViaPlaywright for refs=aria.
  • Adds exact-target Playwright disconnect and raw CDP aria fallback for recoverable local managed snapshot failures.
  • Does not refactor browser routing, Chrome MCP behavior, dependencies, or shared runtime ownership.

Verification

  • pnpm install to bootstrap this isolated lane after vitest was missing.
  • pnpm exec vitest run src/browser/server.agent-contract-snapshot-endpoints.test.ts -> 1 file, 4 tests passed.
  • pnpm exec vitest run --config vitest.e2e.config.ts src/browser/pw-ai.e2e.test.ts -> 1 file, 8 tests passed.
  • pnpm exec oxlint --type-aware src/browser/routes/agent.snapshot.ts src/browser/routes/agent.snapshot.plan.ts src/browser/pw-tools-core.snapshot.ts src/browser/server.agent-contract-snapshot-endpoints.test.ts src/browser/pw-ai.e2e.test.ts src/browser/server.control-server.test-harness.ts -> 0 warnings/errors.
  • git diff --check -> clean.

AI Assistance

  • AI-assisted
  • Testing degree: targeted

Summary

  • Problem: browser snapshot requests with larger caller timeouts still hit Playwright private snapshot's hidden 5s default.
  • Why it matters: heavy pages can wedge or fail before the tool's real timeout budget is used.
  • What changed: timeout propagation, exact-target recovery disconnect, local raw-CDP aria fallback, and focused regression tests.
  • What did NOT change (scope boundary): no dependency changes, no shared runtime restart, no broad browser stack refactor.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Related: live GrabFood browser snapshot timeout recovery lane

User-visible / Behavior Changes

browser.snapshot?format=ai&timeoutMs=... can now spend the requested timeout budget up to the existing 60s clamp. On recoverable local AI snapshot failure, response can degrade to format: "aria" with fallback: "raw-cdp-aria" instead of hard failing.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: isolated worktree, local pnpm/Vitest
  • Model/provider: n/a
  • Integration/channel (if any): Browser control server unit/e2e harness
  • Relevant config (redacted): default local managed test profile

Steps

  1. Request AI snapshot with timeoutMs=42000 and exact targetId.
  2. Request refs=aria&interactive=true&timeoutMs=12000.
  3. Simulate _snapshotForAI timeout on exact targetId=abce9999.
  4. Verify exact-target disconnect and raw CDP aria fallback.

Expected

  • Caller timeout reaches Playwright snapshot helpers.
  • Timeout recovery does not snapshot the wrong tab.
  • Local fallback returns usable aria structure.

Actual

  • Targeted tests pass with exact mock assertions for timeout, disconnect, fallback, and targetId.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: route timeout propagation; helper timeout propagation; recoverable timeout fallback; non-recoverable no-fallback; exact targetId.
  • Edge cases checked: _snapshotForAI timeout text does not get mistaken for missing-private-API fallback.
  • What you did not verify: live GrabFood page yet; planned after merge or runtime-safe path.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert this PR.
  • Files/config to restore: src/browser/routes/agent.snapshot.ts, src/browser/routes/agent.snapshot.plan.ts, src/browser/pw-tools-core.snapshot.ts, related tests/harness.
  • Known bad symptoms reviewers should watch for: AI snapshot responses unexpectedly returning aria fallback too often, or labels requests losing image labels after recoverable timeout.

Risks and Mitigations

  • Risk: fallback response shape changes from AI text to aria nodes when recovery is needed.
    • Mitigation: only on recoverable local managed failures with same-tab raw CDP wsUrl; response marks fallback: "raw-cdp-aria".

- What: thread snapshot timeoutMs through the plan, route, and Playwright AI/refs=aria helpers; recover stuck AI snapshots with exact-target disconnect plus local raw-CDP aria fallback.

- Why: heavy pages like GrabFood should use the caller's browser-tool budget instead of silently dying at Playwright's hidden 5s default or wedging the lane.

- Risk: fallback returns aria structure instead of AI text on recoverable local snapshot failures; covered by targeted route/helper regression tests.
@artemgetmann
artemgetmann marked this pull request as ready for review June 5, 2026 08:58
@artemgetmann
artemgetmann enabled auto-merge (squash) June 5, 2026 09:01
@artemgetmann
artemgetmann merged commit 9ce9371 into main Jun 5, 2026
22 of 24 checks passed
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