Skip to content

fix: resolve wait --download race condition#664

Open
juliobrasa wants to merge 1 commit intovercel-labs:mainfrom
juliobrasa:fix/download-wait-race-condition
Open

fix: resolve wait --download race condition#664
juliobrasa wants to merge 1 commit intovercel-labs:mainfrom
juliobrasa:fix/download-wait-race-condition

Conversation

@juliobrasa
Copy link

Summary

wait --download always times out if the download was triggered before the command is sent (e.g., by a prior click). This is because page.waitForEvent('download') is called lazily and misses events that already fired.

Fix

  • Register page.on('download') eagerly in setupPageTracking() to queue downloads as they occur
  • New waitForDownload() method checks the pending queue first, then falls back to page.waitForEvent()
  • Same pattern as the network request tracking fix

Before

agent-browser click @e5          # triggers download
agent-browser wait --download    # ✗ Timeout — event already fired

After

agent-browser click @e5          # triggers download (queued)
agent-browser wait --download    # ✓ Returns immediately from queue

Test plan

  • TypeScript compiles without errors
  • Download triggered by click is captured by subsequent wait --download
  • wait --download still works when called before the download starts

Closes #561

🤖 Generated with Claude Code

Previously, `wait --download` called `page.waitForEvent('download')`
lazily — only when the command arrived. If the download was triggered
by a prior `click` command, the event had already fired and the
listener missed it, causing a timeout.

Fix: register a `page.on('download')` listener eagerly in
`setupPageTracking()` to queue downloads as they occur. The new
`waitForDownload()` method checks the queue first before waiting
for a new event, eliminating the race condition.

Closes vercel-labs#561

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 6, 2026

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

* Take a pending download from the queue, or wait for the next one.
*/
async waitForDownload(timeout?: number): Promise<Download> {
if (this.pendingDownloads.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race condition causes the same download event to be both returned from waitForDownload() and left in the pendingDownloads queue, leading to duplicate processing on subsequent calls.

Fix on Vercel

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.

wait --download times out even when download already started (race condition)

1 participant