Skip to content

[kernel 1116] browser logging: cdp pipeline#194

Open
archandatta wants to merge 21 commits intomainfrom
archand/kernel-1116/cdp-pipeline
Open

[kernel 1116] browser logging: cdp pipeline#194
archandatta wants to merge 21 commits intomainfrom
archand/kernel-1116/cdp-pipeline

Conversation

@archandatta
Copy link
Copy Markdown
Contributor

@archandatta archandatta commented Apr 1, 2026

Note

Medium Risk
Introduces a new capture-control surface (/events/start//events/stop) and wires in a new events pipeline/monitor lifecycle, which can affect runtime behavior and shutdown ordering. The CDP monitor implementation is currently stubbed, so follow-up changes may be needed to ensure capture actually works and doesn’t leak resources.

Overview
Adds a browser logging capture path by wiring an events.Pipeline and new cdpmonitor.Monitor into ApiService, including lifecycle management during Shutdown.

Introduces non-OpenAPI HTTP endpoints POST /events/start and POST /events/stop to start/stop capture sessions (generating a new session ID and restarting the monitor when needed), and updates main.go to construct the pipeline (ring buffer + file writer) and pass it into the API service.

Extends the events schema with events.CategoryFor to derive EventCategory from event type prefixes, and updates tests to use the new ApiService.New(...) signature with an events pipeline and display number.

Written by Cursor Bugbot for commit 1e544a7. This will update automatically on new commits. Configure here.

Event is the agreed portable name. DetailStandard avoids Go keyword
ambiguity with "default".
Moves CDP-specific fields (target_id, cdp_session_id, frame_id,
parent_frame_id) under source.metadata. Top-level Event schema now
contains only stable cross-producer fields.
…ut of Event

Event is now purely producer-emitted content. Pipeline-assigned metadata
(seq, capture_session_id) lives on the Envelope. truncateIfNeeded
operates on the full Envelope. Pipeline type comment now documents
lifecycle semantics.
Ring buffer now indexes by envelope.Seq directly, removing the separate
head/written counters. NewReader takes an explicit afterSeq for resume
support. Renamed notify to readerWake for clarity.
Drops are now stream metadata (ReadResult.Dropped) rather than fake
events smuggled into the Event schema. Transport layer decides how to
surface gaps on the wire.
truncateIfNeeded now warns if the envelope still exceeds the 1MB limit
after nulling data (e.g. huge url or source.metadata). Pipeline.Publish
skips the file write when marshal returns nil to avoid writing corrupt
bare-newline JSONL lines.
xvfbResizeMu sync.Mutex

// CDP event pipeline and cdpMonitor.
eventsPipeline *events.Pipeline
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.

Will change this to CaptureSession once #184 is merged

@archandatta archandatta marked this pull request as ready for review April 2, 2026 15:19
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 2 potential issues.

Fix All in Cursor

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


s.eventsPipeline.Start(uuid.New().String())

if err := s.cdpMonitor.Start(r.Context()); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

HTTP request context will cancel long-running CDP monitor

High Severity

s.cdpMonitor.Start(r.Context()) passes the HTTP request context to a long-running CDP WebSocket monitor. An HTTP request context is cancelled as soon as the handler returns (after sending the 200 OK response), which means the monitor's context will be cancelled almost immediately. A detached or server-scoped context (like context.Background()) is needed so the monitor survives beyond the request lifecycle. For reference, main.go uses a signal-based context for similarly long-lived operations like upstreamMgr.Start(ctx).

Fix in Cursor Fix in Web

default:
return CategorySystem
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CategoryFor omits liveview and captcha category mappings

Low Severity

The new CategoryFor function maps event-type prefixes to EventCategory values but omits "liveview"CategoryLiveview and "captcha"CategoryCaptcha, even though both constants are defined in the same file. Any event type with a liveview_* or captcha_* prefix will silently fall through to the default branch and be mis-categorized as CategorySystem. This could route events to the wrong log file via FileWriter.

Fix in Cursor Fix in Web

Base automatically changed from archand/kernel-1116/browser-logging to main April 2, 2026 15:34
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