[Bug]: Agent-started preview download is treated as the user's after 5 s without agent input and opens the file manager #47934
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/desktop
Steps to reproduce#
Serve a page that links to an attachment (POSIX shell):
node -e 'require("http").createServer((req, res) => req.url === "/f" ? (res.writeHead(200, { "content-type": "text/plain", "content-disposition": "attachment; filename=a.txt" }), res.end("hi")) : res.end("<a id=d href=/f>x</a>")).listen(8123)'Ask the agent to open http://127.0.0.1:8123 in the built-in Browser.
Ask the agent to run this page script, with no other browser command while it runs:
new Promise((r) => setTimeout(() => { document.getElementById("d").click(); r(); }, 6000))
Control: the same script with a 1 second delay.
Expected behavior#
The agent started the download, so the download stays with the agent. Nothing is copied to Downloads, and no file manager window opens.
Actual behavior#
With the 6 second script, a.txt is copied into the system Downloads folder. This was seen on two runs. On the second, with every Explorer window closed first, one File Explorer window opened on Downloads, in front of everything else, and stayed open.
With the 1 second control, nothing is copied, and no PreviewManager.copyToDownloads span is logged.
The cause, from the source:
DesktopBrowserHost.ts:AGENT_INPUT_WINDOW_MS = 5_000.handleCommandLinesetstab.agentInputAt = performance.now()when anInput.*,Page.navigate,Runtime.evaluate, orRuntime.callFunctionOncommand arrives.humanStartedDownloadreturnsperformance.now() - tab.agentInputAt > AGENT_INPUT_WINDOW_MS. It is checked whenwill-downloadfires, not when the command was sent.Manager.ts: a download counted as the user's goes throughcopyToDownloads, which copies the file intoapp.getPath("downloads")and callsshell.showItemInFolder(target).
So an agent download that fires more than 5 seconds after the agent's last input, navigation, or evaluate command takes the user's path, unless another such command arrives in between. A setTimeout did this in the run above. By the same logic, a long page script or a page that renders slowly before it downloads would too.
This matters because an agent working in the background opens a window in front of whatever the user is doing, and it would show on a shared screen in a call or a stream.
Related: #47365 and #47366 are about the same copy step failing for a download the user clicked. This report is the other side: an agent download treated as the user's.
Suggested fix: start the 5 seconds when the agent's command settles, not when it arrives.
Impact#
Minor bug or occasional failure
Version or commit#
0.1.14-nightly.20261202.5624 (desktop). The same code is on main at f1da8a0348.
Environment#
Windows 11, desktop app. The page was open in a background preview tab.
Logs or stack traces#
From desktop.trace.ndjson during a 6 second run, trimmed to name, duration, and exit (the 1 second control logged no PreviewManager.copyToDownloads span):
{"type":"effect-span","name":"PreviewManager.copyToDownloads","durationMs":4.2179,"exit":{"_tag":"Success"}}
Workaround#
Have the agent return the file's data from the page in the script result instead of triggering a download.
Drafted by Claude Opus 5.5 in T3 Code.
tanstack-source added labelsbug
maxwellyoung(GitHub profile, opens in a new tab) linked this to #47980
Sign in to join this conversation.