Skip to content

feat(cli): add --rpc-timeout and cancel tool calls on timeout - #3639

Open
flavio-cesar wants to merge 4 commits into
ChromeDevTools:mainfrom
flavio-cesar:feat/cli-rpc-timeout-3604
Open

flavio-cesar wants to merge 4 commits into
ChromeDevTools:mainfrom
flavio-cesar:feat/cli-rpc-timeout-3604

Conversation

@flavio-cesar

@flavio-cesar flavio-cesar commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #3604

Tools without a timeout argument, such as lighthouse_audit and the heap snapshot tools, were cut off by the CLI after 60s. The daemon kept working, but the result was lost. Following the direction in the issue, the CLI now has its own --rpc-timeout, waits 180s by default, and cancels the tool call when the time runs out.

User-visible changes:

  • --rpc-timeout (for example 90s, 5m or 1h) sets how long the CLI waits for a tool call. The default is 180s instead of 60s. start, status and stop do not take this option, and status and stop still wait up to 60s for a response.
  • --rpc-timeout is now an option on every tool command. To pass it as literal text, put it after --.
  • A tool's own --timeout no longer changes how long the CLI waits. This replaces the behavior from fix: respect tool timeouts in CLI daemon responses #3443. With a --timeout close to or above 180s, you now also need a longer --rpc-timeout.
  • The timeout error shows the limit. For tool calls, it also suggests increasing --rpc-timeout.
  • If the CLI times out or exits before the response, the daemon cancels the call through the existing ToolHandler cancellation (fix: preserve task serialization on request cancellation #3079). A call that is waiting in the queue does not run, and a call that is waiting for the browser stops waiting. A handler that is already running is not interrupted: its result is discarded, and it keeps its queue, if it has one, until it finishes.
  • Cancelling a call also stops its 60s limit on waiting for the browser. If browser setup gets stuck after connecting and every client leaves earlier (for example, with --rpc-timeout=30s), the daemon no longer drops that connection on its own. On main, the abandoned call dropped it after 60s. A call that waits the full 60s still drops it.
  • With the default limit, if the browser connection is not ready within 60s, the CLI now prints the daemon's error and exits with code 0, like other tool errors. On main, the CLI timed out first in testing and exited with code 1.
  • With --idleTimeout, a cancelled call no longer counts as activity, so the daemon can exit while the cancelled handler is still running. As on main, the daemon cannot finish exiting while a browser connection attempt is stuck.

docs/cli.md and the CLI skill describe the new option.

Tests:

  • The new daemon test needs no browser. The first call holds the queue while it connects to a local endpoint that never answers. After the client times out, the next call must get the queue. The test fails on main. It also fails if the client does not close the socket, if the daemon does not abort when the socket closes, or if the signal does not reach the tool handler.
  • A McpServer test checks that callTool forwards the signal. CLI tests cover the 180s default, the option before and after the command, invalid values, and that a tool's --timeout does not change the limit.
  • On Windows with Node 24, in an isolated environment, the full suite had 2267 passes, 18 skips and 5 failures (4 in pwa.test.ts and 1 in screenshot.test.ts). The same 5 tests fail on main in that environment. The daemon status test that uses port 9222 was left out and passed separately with another port. npm run gen made no changes.
  • After that run, the changes were to docs, tests, a comment, and how the daemon calls the tool handler. The tests for the affected modules were then rerun without a browser: 463 passed and 4 were skipped, including one that needs a browser. All 24 tests in a copy of daemon/client.test.ts also passed. The copy used a closed local browser endpoint and a port other than 9222.
  • The real lighthouse_audit ran three times on each version. Only one pair is comparable: the same 10,000-block local page, one version at a time. On main, the CLI exited with the timeout error after 61s and the reports appeared later. With this change, it printed the audit after 84s. When both versions ran at the same time on that page, main timed out after 62s, and with this change Lighthouse returned its own PROTOCOL_TIMEOUT error after 144s. On a lighter page, both finished (52s on main, 82s with this change). Other jobs were running on the machine, so those times are not a speed comparison. These runs were before the last round of changes.

@OrKoN
OrKoN requested a review from yulunz November 26, 2026 13:27
@flavio-cesar
flavio-cesar force-pushed the feat/cli-rpc-timeout-3604 branch from 5412981 to 9c222a5 Compare November 26, 2026 14:04

@yulunz yulunz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This changes what --timeout does for CLI users: since #3443 (shipped in 1.14.0), wait_for --timeout=300000 made the CLI wait, but now the CLI cancels the call at 180s unless --rpc-timeout is passed too. The release notes only use the commit subject, so could the title say so? For example:

feat(cli): add --rpc-timeout; tool --timeout no longer extends the CLI wait

Comment thread src/daemon/client.ts
: '';
reject(
new Error(
`Timeout waiting for daemon response after ${timeout}ms${hint}`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Since users pass --rpc-timeout as 90s/5m, it might read better to report seconds here (after 300s) instead of after 300000ms.

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.

CLI: fixed 60 s daemon deadline still applies to tools with no timeout argument

2 participants