Skip to content

fix(daemon): honor tool timeouts for CLI responses - #3110

Closed
lorenzozanee wants to merge 1 commit into
ChromeDevTools:mainfrom
lorenzozanee:fix/cli-daemon-timeout
Closed

lorenzozanee wants to merge 1 commit into
ChromeDevTools:mainfrom
lorenzozanee:fix/cli-daemon-timeout

Conversation

@lorenzozanee

Copy link
Copy Markdown

Tool invocations with a longer --timeout could still fail after the CLI's fixed 60-second daemon response deadline. Derive the response deadline from the invocation timeout, adding a 60-second grace period for long operations while retaining the existing default for short or non-tool commands.

Focused daemon-client tests, typecheck, format check, and git diff --check pass. The full suite has Chrome launch failures (TargetCloseError) in this environment.

Fixes #2983

@OrKoN
OrKoN requested a review from yulunz October 14, 2026 08:10
@OrKoN

OrKoN commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@yulunz, please review this PR (automatically distributed)

@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.

Thanks for fixing this! Deriving the daemon socket deadline from command.args?.timeout in src/daemon/client.ts makes sense. One small guard for NaN below.

Comment thread src/daemon/client.ts

const toolTimeout = command.args?.timeout;
if (typeof toolTimeout !== 'number' || toolTimeout <= 0) {
return SEND_COMMAND_TIMEOUT;

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.

When an invalid numeric flag is passed on the CLI (e.g. --timeout foo), yargs parses timeout as NaN. Since typeof NaN === 'number', NaN <= 0 is false, and NaN < SEND_COMMAND_TIMEOUT is false, getCommandResponseTimeout returns NaN (NaN + SEND_COMMAND_TIMEOUT), which causes setTimeout in sendCommand to fire immediately instead of letting the daemon return an input validation error.

Could we disallow NaN here (e.g. Number.isNaN(toolTimeout))?

  const toolTimeout = command.args?.timeout;
  if (
    typeof toolTimeout !== 'number' ||
    Number.isNaN(toolTimeout) ||
    toolTimeout <= 0
  ) {
    return SEND_COMMAND_TIMEOUT;
  }

60_000,
);
assert.strictEqual(getCommandResponseTimeout({method: 'status'}), 60_000);
});

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.

Please also add a test case for args: {timeout: Number.NaN} returning 60_000.

@Lightning00Blade

Copy link
Copy Markdown
Collaborator

Closing as stale. Feel free to resolve the issue and merge conflict we can re-open.

zjdCander pushed a commit to zjdCander/chrome-devtools-mcp that referenced this pull request Nov 16, 2026
The CLI can stop waiting after 60 seconds even when a tool has a longer
explicit timeout, losing the daemon's eventual result. Derive the
default response deadline for `invoke_tool` from a finite positive tool
timeout plus the existing 60-second response allowance.

Missing, nonnumeric, nonfinite, and nonpositive tool timeouts keep the
existing default. Explicit socket deadlines remain authoritative, and
derived deadlines are capped at Node's maximum timer delay to avoid
overflowing into an immediate timeout.

This also applies to short positive timeouts: `--timeout 5000` waits up
to 65 seconds for the daemon response, instead of the previous 60
seconds. Commands other than `invoke_tool` retain the 60-second default.

Follows the timeout approach discussed in ChromeDevTools#3110.

Fixes ChromeDevTools#2983.

Initial validation at `0c65963`: the daemon client tests pass (27/27).
The full suite has 1,815 passes, 3 skips, and one large full-page
screenshot failure (`Page is too large`), also reproduced on unmodified
`main` at `6b056c8`. Format checks pass.

---------

Co-authored-by: Natasha Gorshunova <[email protected]>
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.

Tool commands fail with Timeout waiting for daemon response after 60 s even when the tool's own --timeout is longer

4 participants