Repository navigation
fix: invoke _download_complete_callbacks for remote browser downloads - #1
Conversation
When is_local=False and state=='completed', the remote branch in download_progress_handler dispatched FileDownloadedEvent correctly but never called _download_complete_callbacks. This meant any click action registered via DefaultActionWatchdog._execute_click_with_download_detection would wait forever for download_completed.set(), causing a timeout even though the download actually succeeded. Fix: after constructing the completion metadata in the remote branch, iterate over _download_complete_callbacks exactly as _track_download does for local browsers. Fixes browser-use#5132
AdarshJ173
left a comment
There was a problem hiding this comment.
Deep Codebase Review — Findings beyond PR #1
Going all in. I've audited the full watchdog layer, download pipeline, crash detection, and event bus usage. Below are all findings I'm attaching as review comments on individual files.
🔴 Critical
-
crash_watchdog.py— wrongtarget_idinon_TabCreatedEvent(see inline comment)
New tabs are never added to crash monitoring because the handler passesagent_focus_target_idinstead ofevent.target_id. -
downloads_watchdog.py—_cdp_downloads_infoleaks oninterruptedstate (see inline)
The progress handler only cleans_cdp_downloads_infooncompleted. If a download isinterrupted(network cut, user cancel), the guid entry is never removed — unbounded dict growth in long-running sessions.
🟡 Medium
-
downloads_watchdog.py—_initial_downloads_snapshotgrows forever (see inline)
Files are added to the snapshot but never pruned. In a long-running agent with many downloads the set grows without bound. -
crash_watchdog.py—_check_network_timeoutsmutates dict while iterating (see inline)
del self._active_requests[request_id]is called from a loop over_active_requests.items(), separated by a list copy — this is safe as written, but only because of the intermediatetimed_out_requestslist. A comment should make this explicit to prevent future regressions. -
downloads_watchdog.py—download_file_from_url15-second JSfetchtimeout may be too short for large files (see inline)
The CDPRuntime.evaluatecall fetches the entire binary into a JS array before returning. For files >50 MB this will reliably time out. Should be configurable viaBrowserProfile.
🟢 Nits / Improvements
-
crash_watchdog.py—_is_new_tab_pageincludesabout:blankin the redirect list but then navigates toabout:blank— infinite loop risk ifabout:blankis already the URL (see inline). -
downloads_watchdog.py— doubleif not self._download_cdp_session_setup:guard — redundant nested check (see inline). -
downloads_watchdog.py—_handle_download(Playwright path) callsdownload.failure()unconditionally with a TODO comment admitting it always fails — dead code that should be removed.
🔎 Full Autonomous Codebase ReviewDeep-reviewed the entire watchdog layer, download pipeline, event bus, and crash detection. Here are all findings beyond the fix in this PR: 🔴 Critical Bugs1.
|
Previously on_TabCreatedEvent passed agent_focus_target_id to attach_to_target(), which is typically already in _targets_with_listeners so the call was a silent no-op. New tabs (popups, ctrl+click, etc.) were never registered for crash monitoring, meaning TargetCrashedEvent on non-focus tabs would never fire BrowserErrorEvent. Fix: use event.target_id (the actually-new tab), mirroring the correct behaviour in DownloadsWatchdog.on_TabCreatedEvent. Also fix _is_new_tab_page() to exclude 'about:blank' from its match set; the health-check redirect loop already guards against it with an explicit `and target.url != 'about:blank'` but the helper method including it is misleading and error-prone for future callers. Fixes browser-use#2 from review comment on PR #1.
Summary
Fixes a bug where downloads on remote browsers (
is_local=False) would silently succeed but leave any waiting click action permanently blocked, causing a timeout.Root Cause
In
download_progress_handlerinsideattach_to_target, whenstate == 'completed'is received:self._track_download(file_path, guid=guid), which internally iterates_download_complete_callbacksand dispatchesFileDownloadedEvent. ✅FileDownloadedEventcorrectly, but never called_download_complete_callbacks. ❌This meant any caller that registered an
on_completecallback viaregister_download_callbacks()(e.g.DefaultActionWatchdog._execute_click_with_download_detection) would wait forever fordownload_completed.set(), eventually timing out — even though the file downloaded successfully.Fix
In the remote
state == 'completed'branch, build the samecomplete_infodict that_track_downloadproduces and iterate_download_complete_callbacksbefore dispatchingFileDownloadedEvent, making the remote path fully symmetric with the local path.Testing
on_completecallback now fires; click actions no longer time outFixes browser-use#5132