Skip to content

[kernel-1116] CDP monitor core#214

Merged
archandatta merged 3 commits intoarchand/kernel-1116/cdp-foundationfrom
archand/kernel-1116/cdp-monitor-core
Apr 13, 2026
Merged

[kernel-1116] CDP monitor core#214
archandatta merged 3 commits intoarchand/kernel-1116/cdp-foundationfrom
archand/kernel-1116/cdp-monitor-core

Conversation

@archandatta
Copy link
Copy Markdown
Contributor

@archandatta archandatta commented Apr 13, 2026

Second layer of the CDP monitor split. Adds the full Monitor struct, all lifecycle machinery, and the test infrastructure. dispatchEvent is a no-op stub - event handlers land in #213


Note

Medium Risk
Adds substantial new CDP monitoring/reconnect logic plus network event capture (including response bodies/headers), which can impact stability and exposes sensitive data on the event stream if mishandled.

Overview
Implements the core cdpmonitor.Monitor: websocket Start/Stop, request/response correlation via send, auto-attach + attach-existing-targets, upstream-driven reconnect with backoff, state reset/health reporting, and periodic cleanup of stuck network requests.

Adds CDP domain enablement and script injection plus a full event dispatch/handler layer that publishes console, page lifecycle, target, interaction (rate-limited binding), layout-shift, and network request/response events (including optional truncated response bodies), and introduces ffmpeg-based screenshot capture with rate limiting/downscaling.

Updates the API service to pass a slog logger into cdpmonitor.New, and adds a full test harness (fake websocket server/upstream, event collector) with extensive unit tests covering lifecycle, reconnect, auto-attach, computed-state edge cases, handlers, and screenshots.

Reviewed by Cursor Bugbot for commit 9092789. Bugbot is set up for automated code reviews on this repo. Configure here.

@archandatta archandatta changed the title feat: add cdpmonitor monitor core — websocket lifecycle, reconnect, s… [kernel-1116] CDP monitor core Apr 13, 2026
…outine overlap, variable shadowing, duplicate time.Since, ffmpeg stderr capture, base64 threshold comment
@archandatta archandatta force-pushed the archand/kernel-1116/cdp-monitor-core branch from 70361be to bfb6cd7 Compare April 13, 2026 15:15
@archandatta archandatta marked this pull request as ready for review April 13, 2026 15:15
@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR does not clearly modify API endpoints (packages/api/cmd/api/) or Temporal workflows (packages/api/lib/temporal); please opt in manually if this affects the kernel API.

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread server/lib/cdpmonitor/monitor.go
Final layer of the CDP monitor split. Replaces the no-op dispatchEvent
stub with the full handler implementation and completes the test suite.
Merges cleanly on top of #214

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Adds full CDP event dispatch/handling and emits richer network/page
interaction events (including headers and optional response bodies),
which can affect event volume and expose sensitive data to downstream
consumers.
> 
> **Overview**
> Completes the CDP monitor split by replacing the no-op `dispatchEvent`
stub with a full handler implementation that publishes console,
page/navigation, target, interaction binding, timeline layout-shift, and
detailed network request/response events (including optional truncated
response bodies for textual resources).
> 
> Improves lifecycle/computed-state correctness by handling redirects
without inflating pending counters, ignoring subframe lifecycle events
for main-frame settling logic, and standardizing published event
timestamps to microseconds (including screenshots and monitor lifecycle
events). Adds an extensive test suite covering these handlers,
rate-limiting of binding events, auto-attach/attach-existing-targets
flows, and the redirect/subframe edge cases; updates API wiring to pass
a `slog` logger into `cdpmonitor.New`.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b5b3e89. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@archandatta archandatta merged commit 348243a into archand/kernel-1116/cdp-foundation Apr 13, 2026
3 checks passed
@archandatta archandatta deleted the archand/kernel-1116/cdp-monitor-core branch April 13, 2026 18:16
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9092789. Configure here.

m.failPendingCommands()

// pendingRequests is already empty above, so inflight=0 is correct.
m.computed.resetOnNavigation(0)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stop starts spurious timer that fires after shutdown

Medium Severity

clearState() calls m.computed.resetOnNavigation(0), which — when inflight is 0 — starts a 500ms network_idle debounce timer via startNetIdleTimer. When clearState is called from Stop(), this timer fires after the monitor has fully shut down and publishes a spurious network_idle event through the publish function. The downstream consumer (captureSession.Publish) may have already been torn down by then.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9092789. Configure here.

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