Skip to content

[kernel 1116] browser logging: cdp pipeline#194

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

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

Conversation

@archandatta
Copy link
Copy Markdown
Contributor

@archandatta archandatta commented Apr 1, 2026

Note

Medium Risk
Introduces new HTTP endpoints and lifecycle management for an event-capture pipeline, adding concurrency/locking and new background monitor shutdown behavior. Risk is moderate because it touches server startup/shutdown and writes event logs to disk, but the CDP monitor implementation is currently minimal.

Overview
Adds an event-capture pipeline to the API service by wiring in a new events.CaptureSession and a cdpmonitor.Monitor, including lifecycle management in ApiService.New and Shutdown.

Exposes new non-OpenAPI endpoints POST /events/start and POST /events/stop to (re)seed a fresh capture session ID and start/stop the CDP monitor under a mutex.

Refactors events.CaptureSession to be startable via Start(sessionID) (constructor no longer takes an ID), switches timestamps to milliseconds, makes sequencing atomic, and adds events.CategoryFor plus a ring-buffer reader start-position fix; tests are updated accordingly.

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

@archandatta archandatta marked this pull request as ready for review April 2, 2026 15:19
Base automatically changed from archand/kernel-1116/browser-logging to main April 2, 2026 15:34
@archandatta archandatta force-pushed the archand/kernel-1116/cdp-pipeline branch from 1e544a7 to 6d929c8 Compare April 2, 2026 17:39
@archandatta archandatta force-pushed the archand/kernel-1116/cdp-pipeline branch from 6d929c8 to 76d837f Compare April 2, 2026 17:44
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.

logger.FromContext(r.Context()).Error("failed to start CDP monitor", "err", err)
http.Error(w, "failed to start capture", http.StatusInternalServerError)
return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Session ID changed before monitor restart causes misattribution

Medium Severity

captureSession.Start(newID) is called before cdpMonitor.Start(), which atomically changes the session ID while the old monitor may still be publishing events. Since captureSessionID is an atomic.Pointer readable without holding monitorMu, any events published by the old monitor's goroutines during the transition window will be incorrectly tagged with the new session ID. The session ID change needs to happen after the old monitor is fully stopped, not before.

Fix in Cursor Fix in Web

nextSeq := afterSeq + 1
if afterSeq == 0 {
nextSeq = 1
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Redundant branch duplicates general-case logic in NewReader

Low Severity

The special case if afterSeq == 0 { nextSeq = 1 } is redundant because the general computation nextSeq := afterSeq + 1 already produces 1 when afterSeq is 0. This no-op branch adds cognitive overhead and may mislead future readers into thinking the afterSeq == 0 case is somehow special.

Fix in Cursor Fix in Web

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