Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
76d837f
feat: add CDP pipeline, cdpmonitor, and wire into API service
archandatta Apr 2, 2026
5c0f7ae
refactor: rename Pipeline to CaptureSession and delete pipeline.go
archandatta Apr 2, 2026
ad2dd63
review: fix request context leak in StartCapture, add missing categor…
archandatta Apr 2, 2026
365787c
review: clean up syntax
archandatta Apr 6, 2026
d086571
review: move CategoryFor to cdpmonitor package
archandatta Apr 7, 2026
3339cac
review: internalize ring buffer and file writer in CaptureSession con…
archandatta Apr 7, 2026
64e67b1
review: write logs under /var/log/kernel and ensure dir exists
archandatta Apr 7, 2026
048f9c6
review: add capture config to /events/start and OpenAPI spec
archandatta Apr 7, 2026
e57e58a
review: fix lifecycle context, stop-before-reset ordering, seq reset,…
archandatta Apr 7, 2026
886b893
fix: oapi version
archandatta Apr 7, 2026
06d2470
fix: Shutdown cancels context outside lock, racing with StartCapture
archandatta Apr 7, 2026
6bb5402
review: validate DetailLevel with generated Valid
archandatta Apr 7, 2026
cb45a55
fix: reset ring buffer on session restart to unstrand existing readers
archandatta Apr 7, 2026
02ee74e
chore: remove dead categoryFor function
archandatta Apr 7, 2026
3523994
review: guard zero-capacity ring buffer and fix reader reset after bu…
archandatta Apr 7, 2026
cb1a1a7
review: use t.TempDir in test helper, map-based ValidCategory, avoid …
archandatta Apr 7, 2026
c9e78a3
review: add captureConfigFrom and StartCapture/StopCapture handler tests
archandatta Apr 7, 2026
1cddf53
feat: refactor events API to resource-style capture sessions
archandatta Apr 8, 2026
c6dd362
review: update file writer to be internal to the package
archandatta Apr 9, 2026
ff8bddf
review: tighten to `Write(filename string, data []byte) error`
archandatta Apr 9, 2026
a8bdeaf
review: update panic -> error
archandatta Apr 9, 2026
8f88ed0
review: update oapi and remove detail level
archandatta Apr 9, 2026
3eaacb3
review: remove url
archandatta Apr 9, 2026
214858a
chore: restore server/api on branch
archandatta Apr 9, 2026
b06132a
review: harden captureConfigFromOAPI and clarify stop comment
archandatta Apr 9, 2026
8ebb5e3
review: unexport ringBuffer and drop AllCategories wrapper
archandatta Apr 9, 2026
4bcba48
review: replace event producers with cdp monitor in stop description
archandatta Apr 9, 2026
1295232
remove test line
archandatta Apr 9, 2026
a4fd0d6
review: update uuid to cuid2
archandatta Apr 10, 2026
d6b348b
Merge branch 'main' into archand/kernel-1116/cdp-pipeline
archandatta Apr 10, 2026
3da65c3
Merge branch 'main' into archand/kernel-1116/cdp-pipeline
archandatta Apr 10, 2026
a7b2e54
fix naming
archandatta Apr 10, 2026
85d570a
feat: add cdpmonitor foundation — types, util, computed state machine…
archandatta Apr 13, 2026
bed53f8
self review
archandatta Apr 13, 2026
d73793c
review: cursor feedback
archandatta Apr 13, 2026
348243a
[kernel-1116] CDP monitor core (#214)
archandatta Apr 13, 2026
a62c403
review: update types and sensitive interaction data
archandatta Apr 14, 2026
0605227
feat: add two-layer CDP decode, protocol-faithful types, then monitor…
archandatta Apr 14, 2026
33c07d3
Merge branch 'main' into archand/kernel-1116/cdp-pipeline
archandatta Apr 21, 2026
9c6e066
review: clean up monitor health and types
archandatta Apr 22, 2026
5dd9273
review: add chromium version
archandatta Apr 22, 2026
7550bc1
review: remove dead code
archandatta Apr 22, 2026
f3d3166
Merge branch 'archand/kernel-1116/cdp-pipeline' into archand/kernel-1…
archandatta Apr 22, 2026
1cfbc5e
fix injection script
archandatta Apr 22, 2026
2e0c4a0
review: remove sensitive data from inject
archandatta Apr 22, 2026
bf4b04c
review
archandatta Apr 22, 2026
90a3ae1
review: sensitive data audit interaction.js
archandatta Apr 22, 2026
4feef7e
review: reconnect failure leaks goroutines and deadlocks Stop
archandatta Apr 22, 2026
8e94162
Merge branch 'main' into archand/kernel-1116/cdp-foundation
archandatta Apr 22, 2026
5465e59
review: create cdpMonitorController
archandatta Apr 22, 2026
7c4c654
review: add ctx to monitor and update comment
archandatta Apr 23, 2026
bca495b
review: lift lifeMu to dispatch level to make ctx handling explicit
archandatta Apr 23, 2026
fd4d4d3
review: add readme for cdp monitor
archandatta Apr 23, 2026
ad28202
feat: capturesession: add Active(), publishLocked helper, session_end…
archandatta Apr 23, 2026
1f45379
feat: openapi: add /events/publish and /events/stream paths + Cache-C…
archandatta Apr 23, 2026
ff2a221
chore: regenerate oapi.go with publishEvent + streamEvents endpoints
archandatta Apr 23, 2026
83d118f
feat: add PublishEvent and StreamEvents handlers
archandatta Apr 23, 2026
0a89c58
review: address feedback
archandatta Apr 24, 2026
f97e3a9
review: update comment
archandatta Apr 24, 2026
4cb8f0e
review: add events lifecycle test
archandatta May 1, 2026
55abde4
Merge branch 'main' into archand/kernel-1116/external-events
archandatta May 6, 2026
232eb37
review: add documentation
archandatta May 6, 2026
093d8cc
review: introduce PublishEventRequest, honor caller source.kind
archandatta May 8, 2026
059f929
review: return assigned envelope from publishEvent
archandatta May 8, 2026
7bc3050
review: make seqs process-monotonic across capture sessions
archandatta May 8, 2026
56782c0
review: update SSE type
archandatta May 8, 2026
5362a27
review: extract EventStream from CaptureSession for process-lifetime …
archandatta May 8, 2026
2a4219a
review: remove file writer from EventStream
archandatta May 8, 2026
678df70
review: move kernel_api reservation note to EventSource.kind, clean u…
archandatta May 8, 2026
bc984ab
refactor: move capture_session_id from Envelope into Event.Data, extr…
archandatta May 11, 2026
47ce172
refactor: decouple publish/subscribe API from capture session
archandatta May 11, 2026
e8657e5
review: rename TypeSessionEnded → CaptureSessionEnded, TypeEventsDrop…
archandatta May 11, 2026
1762276
review: serialize Envelope directly in PublishEvent response
archandatta May 11, 2026
f54ba6c
review: move capture_session_id from event data to source.metadata
archandatta May 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ oapi-generate:
openapi-down-convert --input openapi.yaml --output openapi-3.0.yaml
go tool oapi-codegen -config ./oapi-codegen.yaml ./openapi-3.0.yaml
@echo "Fixing oapi-codegen issue https://github.com/oapi-codegen/oapi-codegen/issues/1764..."
go run ./scripts/oapi/patch_sse_methods -file ./lib/oapi/oapi.go -expected-replacements 3
go run ./scripts/oapi/patch_sse_methods -file ./lib/oapi/oapi.go -expected-replacements 4
go fmt ./lib/oapi/oapi.go
go mod tidy

Expand Down
11 changes: 8 additions & 3 deletions server/cmd/api/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"time"

"github.com/kernel/kernel-images/server/lib/capturesession"
"github.com/kernel/kernel-images/server/lib/cdpmonitor"
"github.com/kernel/kernel-images/server/lib/devtoolsproxy"
"github.com/kernel/kernel-images/server/lib/events"
Expand Down Expand Up @@ -81,7 +82,8 @@ type ApiService struct {
xvfbResizeMu sync.Mutex

// CDP event pipeline and cdpMonitor.
captureSession *events.CaptureSession
eventStream *events.EventStream
captureSession *capturesession.CaptureSession
cdpMonitor cdpMonitorController
monitorMu sync.Mutex
lifecycleCtx context.Context
Expand All @@ -96,7 +98,8 @@ func New(
upstreamMgr *devtoolsproxy.UpstreamManager,
stz scaletozero.Controller,
nekoAuthClient *nekoclient.AuthClient,
captureSession *events.CaptureSession,
captureSession *capturesession.CaptureSession,
eventStream *events.EventStream,
displayNum int,
) (*ApiService, error) {
switch {
Expand All @@ -110,6 +113,8 @@ func New(
return nil, fmt.Errorf("nekoAuthClient cannot be nil")
case captureSession == nil:
return nil, fmt.Errorf("captureSession cannot be nil")
case eventStream == nil:
return nil, fmt.Errorf("eventStream cannot be nil")
}

mon := cdpmonitor.New(upstreamMgr, captureSession.Publish, displayNum, slog.Default())
Expand All @@ -125,6 +130,7 @@ func New(
stz: stz,
nekoAuthClient: nekoAuthClient,
policy: &policy.Policy{},
eventStream: eventStream,
captureSession: captureSession,
cdpMonitor: mon,
lifecycleCtx: ctx,
Expand Down Expand Up @@ -352,7 +358,6 @@ func (s *ApiService) Shutdown(ctx context.Context) error {
s.lifecycleCancel()
s.cdpMonitor.Stop()
s.captureSession.Stop()
_ = s.captureSession.Close()
s.monitorMu.Unlock()
return s.recordManager.StopAll(ctx)
}
40 changes: 22 additions & 18 deletions server/cmd/api/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"log/slog"

"github.com/kernel/kernel-images/server/lib/capturesession"
"github.com/kernel/kernel-images/server/lib/devtoolsproxy"
"github.com/kernel/kernel-images/server/lib/events"
"github.com/kernel/kernel-images/server/lib/nekoclient"
Expand All @@ -26,7 +27,7 @@ func TestApiService_StartRecording(t *testing.T) {

t.Run("success", func(t *testing.T) {
mgr := recorder.NewFFmpegManager()
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)

resp, err := svc.StartRecording(ctx, oapi.StartRecordingRequestObject{})
Expand All @@ -40,7 +41,7 @@ func TestApiService_StartRecording(t *testing.T) {

t.Run("already recording", func(t *testing.T) {
mgr := recorder.NewFFmpegManager()
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)

// First start should succeed
Expand All @@ -55,7 +56,7 @@ func TestApiService_StartRecording(t *testing.T) {

t.Run("custom ids don't collide", func(t *testing.T) {
mgr := recorder.NewFFmpegManager()
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)

for i := 0; i < 5; i++ {
Expand Down Expand Up @@ -88,7 +89,7 @@ func TestApiService_StopRecording(t *testing.T) {

t.Run("no active recording", func(t *testing.T) {
mgr := recorder.NewFFmpegManager()
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)

resp, err := svc.StopRecording(ctx, oapi.StopRecordingRequestObject{})
Expand All @@ -101,7 +102,7 @@ func TestApiService_StopRecording(t *testing.T) {
rec := &mockRecorder{id: "default", isRecordingFlag: true}
require.NoError(t, mgr.RegisterRecorder(ctx, rec), "failed to register recorder")

svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)
resp, err := svc.StopRecording(ctx, oapi.StopRecordingRequestObject{})
require.NoError(t, err)
Expand All @@ -116,7 +117,7 @@ func TestApiService_StopRecording(t *testing.T) {

force := true
req := oapi.StopRecordingRequestObject{Body: &oapi.StopRecordingJSONRequestBody{ForceStop: &force}}
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)
resp, err := svc.StopRecording(ctx, req)
require.NoError(t, err)
Expand All @@ -130,7 +131,7 @@ func TestApiService_DownloadRecording(t *testing.T) {

t.Run("not found", func(t *testing.T) {
mgr := recorder.NewFFmpegManager()
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)
resp, err := svc.DownloadRecording(ctx, oapi.DownloadRecordingRequestObject{})
require.NoError(t, err)
Expand All @@ -150,7 +151,7 @@ func TestApiService_DownloadRecording(t *testing.T) {
rec := &mockRecorder{id: "default", isRecordingFlag: true, recordingData: randomBytes(minRecordingSizeInBytes - 1)}
require.NoError(t, mgr.RegisterRecorder(ctx, rec), "failed to register recorder")

svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)
// will return a 202 when the recording is too small
resp, err := svc.DownloadRecording(ctx, oapi.DownloadRecordingRequestObject{})
Expand Down Expand Up @@ -180,7 +181,7 @@ func TestApiService_DownloadRecording(t *testing.T) {
rec := &mockRecorder{id: "default", recordingData: data}
require.NoError(t, mgr.RegisterRecorder(ctx, rec), "failed to register recorder")

svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)
resp, err := svc.DownloadRecording(ctx, oapi.DownloadRecordingRequestObject{})
require.NoError(t, err)
Expand All @@ -200,7 +201,7 @@ func TestApiService_Shutdown(t *testing.T) {
rec := &mockRecorder{id: "default", isRecordingFlag: true}
require.NoError(t, mgr.RegisterRecorder(ctx, rec), "failed to register recorder")

svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)

require.NoError(t, svc.Shutdown(ctx))
Expand Down Expand Up @@ -304,23 +305,26 @@ func newMockNekoClient(t *testing.T) *nekoclient.AuthClient {
return client
}

func newCaptureSession(t *testing.T) *events.CaptureSession {
func newCaptureSession(t *testing.T) (*capturesession.CaptureSession, *events.EventStream) {
t.Helper()
cs, err := events.NewCaptureSession(events.CaptureSessionConfig{
LogDir: t.TempDir(),
RingCapacity: 64,
})
es, err := events.NewEventStream(events.EventStreamConfig{RingCapacity: 64})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { cs.Close() })
return cs
return capturesession.NewCaptureSession(es), es
}

// newSvc constructs an ApiService with a fresh capture session and event stream.
func newSvc(t *testing.T, mgr recorder.RecordManager) (*ApiService, error) {
t.Helper()
cs, es := newCaptureSession(t)
return New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), cs, es, 0)
}

func TestApiService_PatchChromiumFlags(t *testing.T) {
ctx := context.Background()
mgr := recorder.NewFFmpegManager()
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
svc, err := newSvc(t, mgr)
require.NoError(t, err)

// Test with valid flags
Expand Down
17 changes: 9 additions & 8 deletions server/cmd/api/api/capture_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/nrednav/cuid2"
oapi "github.com/kernel/kernel-images/server/lib/oapi"

"github.com/kernel/kernel-images/server/lib/capturesession"
"github.com/kernel/kernel-images/server/lib/events"
"github.com/kernel/kernel-images/server/lib/logger"
)
Expand Down Expand Up @@ -119,26 +120,26 @@ func (s *ApiService) buildSessionResponse() oapi.CaptureSession {
}

// captureConfigFrom converts the optional StartCaptureSessionRequest body
// into an events.CaptureConfig.
func captureConfigFrom(body *oapi.StartCaptureSessionRequest) (events.CaptureConfig, error) {
// into a capturesession.CaptureConfig.
func captureConfigFrom(body *oapi.StartCaptureSessionRequest) (capturesession.CaptureConfig, error) {
if body == nil {
return events.CaptureConfig{}, nil
return capturesession.CaptureConfig{}, nil
}
return captureConfigFromOAPI(body.Config)
}

// captureConfigFromOAPI converts an oapi.CaptureConfig to events.CaptureConfig.
func captureConfigFromOAPI(cfg *oapi.CaptureConfig) (events.CaptureConfig, error) {
// captureConfigFromOAPI converts an oapi.CaptureConfig to capturesession.CaptureConfig.
func captureConfigFromOAPI(cfg *oapi.CaptureConfig) (capturesession.CaptureConfig, error) {
if cfg == nil || cfg.Categories == nil {
return events.CaptureConfig{}, nil
return capturesession.CaptureConfig{}, nil
}
out := events.CaptureConfig{
out := capturesession.CaptureConfig{
Categories: make([]events.EventCategory, 0, len(*cfg.Categories)),
}
for _, c := range *cfg.Categories {
cat := events.EventCategory(c)
if !events.ValidCategory(cat) {
return events.CaptureConfig{}, fmt.Errorf("unknown category: %q", c)
return capturesession.CaptureConfig{}, fmt.Errorf("unknown category: %q", c)
}
out.Categories = append(out.Categories, cat)
}
Expand Down
11 changes: 6 additions & 5 deletions server/cmd/api/api/capture_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCaptureConfigFrom(t *testing.T) {
})

t.Run("valid categories", func(t *testing.T) {
cats := []oapi.CaptureConfigCategories{oapi.Console, oapi.Network}
cats := []oapi.CaptureConfigCategories{oapi.CaptureConfigCategoriesConsole, oapi.CaptureConfigCategoriesNetwork}
body := &oapi.StartCaptureSessionRequest{
Config: &oapi.CaptureConfig{Categories: &cats},
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestStartCaptureSession(t *testing.T) {

t.Run("success with config", func(t *testing.T) {
svc := newTestService(t, newMockRecordManager())
cats := []oapi.CaptureConfigCategories{oapi.Console}
cats := []oapi.CaptureConfigCategories{oapi.CaptureConfigCategoriesConsole}
resp, err := svc.StartCaptureSession(ctx, oapi.StartCaptureSessionRequestObject{
Body: &oapi.StartCaptureSessionRequest{
Config: &oapi.CaptureConfig{Categories: &cats},
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestUpdateCaptureSession(t *testing.T) {
_, err := svc.StartCaptureSession(ctx, oapi.StartCaptureSessionRequestObject{})
require.NoError(t, err)

cats := []oapi.CaptureConfigCategories{oapi.Console}
cats := []oapi.CaptureConfigCategories{oapi.CaptureConfigCategoriesConsole}
resp, err := svc.UpdateCaptureSession(ctx, oapi.UpdateCaptureSessionRequestObject{
Body: &oapi.UpdateCaptureSessionRequest{
Config: &oapi.CaptureConfig{Categories: &cats},
Expand All @@ -152,7 +152,7 @@ func TestUpdateCaptureSession(t *testing.T) {
require.True(t, ok)
require.NotNil(t, r200.Config.Categories)
assert.Len(t, *r200.Config.Categories, 1)
assert.Equal(t, oapi.Console, (*r200.Config.Categories)[0])
assert.Equal(t, oapi.CaptureConfigCategoriesConsole, (*r200.Config.Categories)[0])
})

t.Run("empty body is no-op", func(t *testing.T) {
Expand Down Expand Up @@ -246,7 +246,8 @@ func (m *mockRecordManager) StopAll(_ context.Context) error
// newTestService builds an ApiService with minimal dependencies for capture session tests.
func newTestService(t *testing.T, mgr recorder.RecordManager) *ApiService {
t.Helper()
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
cs, es := newCaptureSession(t)
svc, err := New(mgr, newMockFactory(), newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), cs, es, 0)
require.NoError(t, err)
svc.cdpMonitor = &stubCdpMonitor{}
return svc
Expand Down
3 changes: 2 additions & 1 deletion server/cmd/api/api/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func testFFmpegFactory(t *testing.T, tempDir string) recorder.FFmpegRecorderFact

func newTestServiceWithFactory(t *testing.T, mgr recorder.RecordManager, factory recorder.FFmpegRecorderFactory) *ApiService {
t.Helper()
svc, err := New(mgr, factory, newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), newCaptureSession(t), 0)
cs, es := newCaptureSession(t)
svc, err := New(mgr, factory, newTestUpstreamManager(), scaletozero.NewNoopController(), newMockNekoClient(t), cs, es, 0)
require.NoError(t, err)
return svc
}
Expand Down
Loading
Loading