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 nocode, no fields and no exported class to check withinstanceof. - 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, withcode: 'COMMAND_TIMEOUT',timeoutMsandbrowserReclaimed. The message is unchanged, so existing message checks keep working.browserReclaimedmeans the kill command was sent; it doesn't confirm that Chromium exited. - Add
reclaimBrowserOnTimeout?: booleantoAgentBrowser.create()andAgentBrowser.session(), and pass it through toSandboxRunner.- 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 default stays
- The README documents how to classify timeouts and how to opt out.
Verification
node --run test:unitpasses (46/46), and so doesnode --run typecheck.- The new tests cover:
- the typed error
- the default reclaim
- opting out through both
createandsession - 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
2This pull request is a draft
Merging is unavailable until it is marked ready for review.
The latest updates on your projects. Learn more about Vercel for GitHub.