Skip to content

feat(telemetry): send server_shutdown without a watchdog - #3514

Closed
yulunz wants to merge 4 commits into
perf/telemetry-lazy-watchdogfrom
feat/telemetry-shutdown-without-watchdog
Closed

yulunz wants to merge 4 commits into
perf/telemetry-lazy-watchdogfrom
feat/telemetry-shutdown-without-watchdog

Conversation

@yulunz

@yulunz yulunz commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Refs #3427

Part 4 of 4, stacked on #3513. Should land together with #3513.

Summary

The watchdog sends server_shutdown when the server exits. Since the
previous change, the watchdog starts only on the first tool call or server
error, so idle sessions sent no server_shutdown. This change adds
ClearcutLogger.logServerShutdownIfNoWatchdog():

  • If a watchdog was started, it does nothing. The watchdog still sends
    server_shutdown after the parent exits.
  • Otherwise it sends {server_shutdown: {}} with session_id,
    app_version, and os_type through sendClearcutBatch. This is the same
    shape as the watchdog's sendShutdownEvent(), so there is no
    mcp_client. The request timeout is 2.5 s (SHUTDOWN_REQUEST_TIMEOUT_MS,
    declared once in ClearcutLogger.ts). The method never throws.
  • It sets a #shutDown flag. After that, #getWatchdog() never spawns a
    watchdog. Events that need one, such as a tool call that finishes during
    shutdown, are dropped and logged. This prevents a second
    server_shutdown. A dropped tool_active event does not update
    lastToolCall.

sendClearcutBatch() takes a new optional requestTimeoutMs. The default is
still 30 s.

Callers:

  • shutdown() in src/bin/chrome-devtools-mcp-main.ts starts the call,
    awaits server.close(), then awaits the call. Both run concurrently
    within the existing 5 s backstop, and a server.close() error behaves as
    before.
  • cleanup() in src/daemon/daemon.ts does the same around
    mcpServer?.close().

User-visible behavior changes

  • Idle sessions that exit through SIGTERM, SIGINT, SIGHUP, or stdin EOF
    send server_shutdown again. The server process sends it, without the
    X-Watchdog-Pid header.
  • Shutdown can take up to 2.5 s longer when Clearcut is slow and no watchdog
    is running. It stays within the existing 5 s backstop.
  • An idle server killed with SIGKILL still sends no server_shutdown. Only
    a watchdog can report that, and none is running.
  • Daemon: same behavior on daemon cleanup.

Test plan

  • tests/telemetry/ClearcutLogger.test.ts:
    • With no watchdog, sendClearcutBatch is called once with the exact
      shutdown event and {clearcutEndpoint, requestTimeoutMs: 2500}, and the
      factory is not called.
    • After a tool call, sendClearcutBatch is not called, and the method
      does not call watchdog.send.
    • After shutdown, logToolInvocation() does not call the watchdog factory.
  • tests/telemetry/watchdog/ClearcutSender.test.ts: sendClearcutBatch
    aborts at requestTimeoutMs.
  • tests/e2e/telemetry.test.ts: new idle case (Linux/macOS) where SIGTERM
    delivers server_shutdown with the session_id of server_start and
    without X-Watchdog-Pid. SIGKILL, SIGTERM, and process-group coverage
    stays on the after-tool-call path, where the watchdog sends
    server_shutdown.
  • Full npm run test: 2029 tests, 2027 pass, 2 skipped (Windows-only),
    0 fail. npm run format: clean.

`server_start` and `daily_active` are now sent with `sendClearcutBatch`
from the server process instead of through the watchdog. The session id
is generated in `ClearcutLogger` and passed to the watchdog with
`--session-id`, so watchdog events keep the same `session_id`.
The watchdog sends `server_shutdown` when the server exits. If no watchdog
was started, `ClearcutLogger.logServerShutdownIfNoWatchdog()` sends it from
the server process during shutdown, with a 2.5 s request timeout. After
this call, the logger never starts a watchdog.
@yulunz

yulunz commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Dropping: not logging server_shutdown for idle sessions is acceptable; see #3427.

@yulunz yulunz closed this Nov 17, 2026
@yulunz
yulunz deleted the feat/telemetry-shutdown-without-watchdog branch November 17, 2026 20:21
@yulunz
yulunz removed this pull request from stack #3515 November 17, 2026 21:46
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.

1 participant