#25

Throw a typed CommandTimeoutError and allow opting out of Chromium reclaim

Draftvercel[bot]wants to merge intofrom

Problem

When a command misses its deadline, SandboxRunner rejects with a plain Error('command timed out after Nms') and then runs pkill -9 chromium. Callers can only classify the failure by matching that message. They also always lose the page state, refs, cookies and tabs, even when they'd rather keep the browser and inspect or retry. Vercel Agent's preview browser uses this library; it has to match the message with a regex and can't avoid the kill. On pages that never finish loading, every timeout throws the session away.

Reproduction

The setup is a mocked Sandbox whose command never finishes, called with AgentBrowser.create({ reclaimBrowserOnTimeout: false }) and exec('snapshot', { timeoutMs: 1 }). On main (1.3.0):

  • The call rejects with a bare Error, with no code, no fields and no exported class to check with instanceof.
  • It still sends pkill -9 chromium.

The new unit tests fail on unmodified main (node --run test:unit: 4 of 46 failing) and pass with this change.

Fix

  • Export CommandTimeoutError extends Error, with code: 'COMMAND_TIMEOUT', timeoutMs and browserReclaimed. The message is unchanged, so existing message checks keep working. browserReclaimed means the kill command was sent; it doesn't confirm that Chromium exited.
  • Add reclaimBrowserOnTimeout?: boolean to AgentBrowser.create() and AgentBrowser.session(), and pass it through to SandboxRunner.
    • The default stays true, because a timed-out CLI call can wedge Chromium.
    • When it's false, only the timed-out CLI process is killed.
  • The README documents how to classify timeouts and how to opt out.

Verification

  • node --run test:unit passes (46/46), and so does node --run typecheck.
  • The new tests cover:
    • the typed error
    • the default reclaim
    • opting out through both create and session
    • a failed cleanup reporting browserReclaimed: false
    • non-timeout failures not being wrapped
  • Integration tests against a real Sandbox and Chromium weren't run in this environment.

Created by Vercel Agent Factory.

Activity

2
vercel[bot]9d ago

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated
remote-agent-browser ReadyPreview, v0Nov 3, 2026 8:04pm UTC

This pull request is a draft

Merging is unavailable until it is marked ready for review.