Skip to content

fix: respect tool timeouts in CLI daemon responses - #3443

Open
lisa0314 wants to merge 2 commits into
ChromeDevTools:mainfrom
lisa0314:fix/2983-cli-timeout
Open

lisa0314 wants to merge 2 commits into
ChromeDevTools:mainfrom
lisa0314:fix/2983-cli-timeout

Conversation

@lisa0314

@lisa0314 lisa0314 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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 #3110.

Fixes #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.

@vathuluri

Copy link
Copy Markdown

Found a platform gap in the new deadline-test fixture at 0c65963.

On Linux with /proc available, getProcessCommandLine() reads /proc/<pid>/cmdline instead of calling execFileSync. The fixture uses process.pid, so it sees the test runner's command line and sendCommand() rejects with Daemon is not running before opening a socket or testing the deadline.

I reproduced this using the actual client/utils source in an isolated harness on Node 24.15.0 / Windows, selecting the Linux branch with a representative test-runner /proc command line:

  • Current fixture: rejects; zero socket connections and zero execFileSync calls.
  • With a /proc read stub returning a daemon command line: the same delayed response succeeds at 75 seconds.
  • Native Windows control: succeeds at 75 seconds.

Could the fixture also stub fs.readFileSync(/proc/${process.pid}/cmdline, 'utf-8') to a NUL-separated daemon command line? Keep the existing execFileSync stub for Windows/macOS.

Scope: simulated Linux branch, not a full Linux suite run. npm run sync completed; the official test command stopped before tests because buildtools/win/gn.exe was missing. I attempted the repo's toolchain setup and stopped the lengthy bootstrap. No full-suite pass claimed. AI-assisted review and reproduction.

@nattallius nattallius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good, with small comments

Comment thread src/daemon/client.ts
const SEND_COMMAND_TIMEOUT = 60_000; // ms

function getCommandResponseTimeout(command: DaemonMessage): number {
if (command.method !== 'invoke_tool') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No test covers this branch (commands other than invoke_tool). Could you add a test that sendCommand({method: 'status'}, '') still times out at exactly 60 s?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a status-command case that remains pending at 59,999 ms and times out at 60,000 ms, preserving the default deadline for non-tool commands.

Comment thread src/daemon/client.ts Outdated
return SEND_COMMAND_TIMEOUT;
}
// Leave time for the daemon to return the tool result without overflowing timers.
return Math.min(toolTimeout + SEND_COMMAND_TIMEOUT, 2 ** 31 - 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two small things here:

  1. Could you give both numbers a name, e.g. MAX_TIMER_DELAY_MS = 2 ** 31 - 1 and RESPONSE_GRACE_MS = 60_000 (the extra time added to the tool timeout)? A one-line comment on why the grace period exists would help: the tool call can also spend time connecting to the browser (up to TOOL_CALL_TIMEOUT_MS) and building the response, which the tool timeout does not cover.

  2. Behavior change for short timeouts: with --timeout 5000 the CLI now waits 65 s instead of 60 s (before this PR stayed 60 s). I think this is fine and avoids the jump at 60 s, but please mention it in the description and add a test for a short tool timeout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Named the timer cap MAX_TIMER_DELAY_MS and the extra allowance RESPONSE_GRACE_MS, with a comment explaining browser connection and response construction. Added the 5,000 ms tool-timeout case with a 65,000 ms response deadline, and documented that short-timeout behavior in the PR description.

Comment thread tests/daemon/client.test.ts Outdated
await assertion;
});

for (const timeout of [undefined, 0, -1, NaN, Infinity, '120000']) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: '120000' (a string) cannot come from the CLI, because yargs parses options with type: number as numbers. Could you remove this case? NaN (--timeout foo) and Infinity (--timeout Infinity) are real inputs, so those are good to keep.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the string timeout case, keeping NaN and Infinity as possible numeric CLI inputs.

@lisa0314

Copy link
Copy Markdown
Contributor Author

Updated the deadline fixture to return a NUL-separated daemon command line for /proc/${process.pid}/cmdline, while retaining the execFileSync stub for macOS and Windows. This lets Linux daemon validation reach the socket deadline logic.

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

3 participants