Skip to content

[kernel-1116] browser events: add external events#227

Open
archandatta wants to merge 7 commits intoarchand/kernel-1116/cdp-foundationfrom
archand/kernel-1116/external-events
Open

[kernel-1116] browser events: add external events#227
archandatta wants to merge 7 commits intoarchand/kernel-1116/cdp-foundationfrom
archand/kernel-1116/external-events

Conversation

@archandatta
Copy link
Copy Markdown
Contributor

@archandatta archandatta commented Apr 24, 2026

As per plan -> #217


Note

Medium Risk
Adds new public API endpoints that inject and stream capture-session events, plus changes capture-session stop/publish behavior to emit terminal/system events; incorrect validation or streaming behavior could impact clients and event pipeline reliability.

Overview
Adds an external events API: POST /events/publish to inject validated caller-supplied events into the active capture session (with reserved types blocked and source.kind forced), and GET /events/stream to stream envelopes over SSE with Last-Event-ID resume support, keepalives, and explicit events_dropped/session_ended signaling.

Updates the events pipeline to support this: CaptureSession now exposes Active(), publishes a synthetic session_ended event on Stop(), and adds PublishUnfiltered() to bypass category filtering for externally-initiated events. OpenAPI/generated client/server code is regenerated for the new endpoints and enums, and SSE responses now include Cache-Control: no-cache and X-Accel-Buffering: no headers; tests are updated/added to cover the new event lifecycle and enum rename.

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

@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 title and branch suggest browser events feature work, but no file changes are provided to confirm modifications to API endpoints or Temporal workflows.

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

@archandatta archandatta force-pushed the archand/kernel-1116/external-events branch from 809321b to ca437c0 Compare April 24, 2026 14:06
Comment thread server/cmd/api/api/events.go
Comment thread server/lib/events/capturesession.go
Comment thread server/cmd/api/api/events.go
Comment thread server/lib/events/capturesession.go Outdated
@archandatta archandatta force-pushed the archand/kernel-1116/external-events branch from 7139fb3 to 0a89c58 Compare April 24, 2026 15:42
Comment thread server/cmd/api/api/events.go
@archandatta archandatta requested review from Sayan- and rgarcia April 24, 2026 16:23
Copy link
Copy Markdown
Contributor

@Sayan- Sayan- left a comment

Choose a reason for hiding this comment

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

matches plan well and deviations from it are reasonable!

return s.captureSessionID != ""
}

// Stop ends the current session. It publishes a synthetic session_ended
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should seq be monotonic across start/stop cycles? If so, I think Start shouldn't reset it here. That would make seq represent the process-wide event stream position rather than the position within a single capture session.

Copy link
Copy Markdown
Contributor Author

@archandatta archandatta May 1, 2026

Choose a reason for hiding this comment

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

I see your point, here are things to consider with how this works currently

  • every envelope already carries capture_session_id, so i think (session_id, seq) would be sufficient
  • SSE clients don't cross session boundaries, session_ended terminates the stream, so not sure if monotonic seq applies fully

the fix would also require a non-trivial ring buffer refactor to avoid dropped records

// PublishEvent handles POST /events/publish.
// Injects a caller-supplied event into the active capture session. Returns 400
// if no session is active or the event fails validation.
func (s *ApiService) PublishEvent(_ context.Context, req oapi.PublishEventRequestObject) (oapi.PublishEventResponseObject, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we add one lifecycle test for the new event flow? Something like start capture session, publish an event through PublishEvent, read it from StreamEvents, then stop and verify the stream receives session_ended.

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.

@archandatta archandatta requested a review from Sayan- May 1, 2026 13:02
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 4cb8f0e. Configure here.

Type: TypeSessionEnded,
Category: CategorySystem,
Source: Source{Kind: KindKernelAPI},
})
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 response seq off-by-one after session_ended publish

Medium Severity

StopCaptureSession calls buildSessionResponse() (which reads Seq()) before s.captureSession.Stop(). Now that Stop() publishes a synthetic session_ended event via publishLocked — which increments s.seq — the Seq in the returned response is one less than the actual final sequence number. Clients comparing the stop response's Seq with the session_ended envelope's seq on the SSE stream will see an inconsistency.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4cb8f0e. 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.

2 participants