Skip to content

Conversation

@ergunsh
Copy link
Contributor

@ergunsh ergunsh commented Jan 15, 2026

This PR implements the watchdog process architecture for the telemetry system. It moves the ClearcutSender execution to a dedicated child process, ensuring that events—especially shutdown events—are reliably transmitted even if the main server process terminates abruptly.

Added an e2e test that runs the server, checks the log file and confirms the telemetry logs exist and that the watchdog process is correctly killed after sending the shutdown event once the main process is killed.

Implementation Roadmap:
This is the fourth in a series of PRs designed to implement the telemetry system:

  1. CLI & Opt-out Mechanism (Merged):
    • Added --usage-statistics flag and transparency logging.
  2. Logger Scaffolding & Integration (Merged):
    • ClearcutLogger: Implemented the main logging entry point.
    • One-way Data Flow: Integrated logToolInvocation and logServerStart hooks into main.ts to capture events.
    • ClearcutSender: Introduced a transport abstraction.
    • Type Definitions: Added TypeScript definitions for the telemetry Protocol Buffer messages.
  3. Persistence Layer (Merged):
    • FilePersistence: Implemented a local file-based state manager to persist the lastActive timestamp.
    • Daily Active Logic: Integrated persistence into ClearcutLogger to automatically detect and log daily_active events (with days_since_last_active calculation) via logDailyActiveIfNeeded.
  4. Watchdog Process Architecture (This PR):
    • WatchdogClient: Added a client-side wrapper to spawn and communicate with the watchdog process via stdin.
    • watchdog/main.ts: Created the entry point for the watchdog process. It listens for IPC messages and uses ClearcutSender to transmit events.
    • Reliable Shutdown: The watchdog monitors the parent process and guarantees a shutdown event is sent when the parent exits or crashes (detecting stdin closure).
    • Refactoring: Moved ClearcutSender to the watchdog directory and updated ClearcutLogger to delegate event sending to the WatchdogClient.
  5. Transport, Batching & Retries (Next):
    • Finalize ClearcutSender with actual HTTP transport logic, including event batching and exponential backoff retries.

@ergunsh ergunsh force-pushed the telemetry/multi-process-04 branch 3 times, most recently from 313dccb to 519cd13 Compare January 16, 2026 10:56
@ergunsh ergunsh changed the title WIP: Implement watchdog mechanism for shutdown detection and move Clearcut transport scaffolding to that process chore: Implement Watchdog process for reliable telemetry Jan 16, 2026
- Introduce WatchdogClient to spawn and communicate with a sidecar process
- Implement watchdog entry point and sender to handle event transmission and detect parent death
- Refactor ClearcutLogger to delegate event sending to the watchdog client
- Add E2E tests for process termination handling (SIGTERM, SIGKILL)
@ergunsh ergunsh force-pushed the telemetry/multi-process-04 branch from 519cd13 to 931dde4 Compare January 19, 2026 09:02
@ergunsh ergunsh marked this pull request as ready for review January 19, 2026 09:06
@ergunsh ergunsh requested a review from OrKoN January 19, 2026 09:07
@ergunsh ergunsh force-pushed the telemetry/multi-process-04 branch from ae4eb0c to 80d328c Compare January 19, 2026 10:24
@ergunsh ergunsh added this pull request to the merge queue Jan 19, 2026
Merged via the queue into main with commit ee35f20 Jan 19, 2026
20 checks passed
@ergunsh ergunsh deleted the telemetry/multi-process-04 branch January 19, 2026 13:47
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.

2 participants