Skip to content

Commit a19154d

Browse files
committed
review: update
1 parent 71e1975 commit a19154d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

plans/external-events.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,28 @@ Accepts a JSON `events.Event` body and publishes it into the currently active `C
4343

4444
**Defaults applied server-side when caller omits them:**
4545

46-
- `category` — derived from `type` via `cdpmonitor.CategoryFor()`. Splits `type` on the first `_` and maps the prefix to a category.
4746
- `source.kind` — stamped to `kernel_api` when absent, so downstream consumers can distinguish external traffic from CDP traffic.
4847

4948
**Validation and status codes:**
5049

5150
- `400` on invalid JSON body.
5251
- `400` when `type` is empty.
53-
- `400` when `category` is present but not in the known set (`events.ValidCategory`).
52+
- `400` when `category` is absent or not in the known set (`events.ValidCategory`). External callers always know their category; derivation is not performed.
5453
- `404` when no capture session is active (consistent with the resource model — publish has no implicit session).
5554
- `200` on successful publish.
5655

5756
The handler does not take `monitorMu``CaptureSession.Publish` is serialised internally and guarantees monotonic seq delivery.
5857

59-
**Request**only `type` is required:
58+
**Request**`type` and `category` are required:
6059

6160
```json
62-
POST /events/publish
61+
POST /events/capture_session/publish
6362
Content-Type: application/json
6463

6564
{
6665
"type": "network_request",
67-
"ts": 1713100000000000,
6866
"category": "network",
67+
"ts": 1713100000000000,
6968
"source": {
7069
"kind": "kernel_api",
7170
"event": "fetch",
@@ -80,7 +79,7 @@ Content-Type: application/json
8079
Minimal valid request:
8180

8281
```json
83-
{ "type": "network_request" }
82+
{ "type": "network_request", "category": "network" }
8483
```
8584

8685
**Response** `200` — pipeline stamps `seq` and `capture_session_id`, returns the full `Envelope`:
@@ -133,7 +132,7 @@ data: {envelope-json}
133132
## 3. Key Design Decisions
134133

135134
1. **Shared pipeline, not a new queue.** External events flow through the same `CaptureSession` as CDP events, so `seq` is globally monotonic across all sources. Consumers never have to merge streams.
136-
2. `**source.kind` is the fan-out key.\*\* `kernel_api` for publish, `cdp` for the monitor, `extension` / `local_process` reserved for future producers. Category is a coarse bucket derived from `type`; source is the precise provenance.
135+
2. `**source.kind` is the fan-out key.\*\* `kernel_api` for publish, `cdp` for the monitor, `extension` / `local_process` reserved for future producers. Category is a required caller-supplied field; source is the precise provenance.
137136
3. **Publish does not honour** `CaptureConfig.Categories`**.** The config is a filter on what the CDP monitor records — an explicit publish is a deliberate caller action and bypasses it.
138137
4. **SSE over WebSocket.** SSE is one-way, proxy-friendly, and has built-in reconnection semantics (`Last-Event-ID`) that map cleanly to our `seq` cursor. No extra framing library.
139138
5. **Direct writes, no goroutine.** `StreamEvents` writes straight to the `ResponseWriter` from the request goroutine. No `io.Pipe`, no background worker — correct for HTTP/1.1 SSE and simpler to reason about on disconnect.
@@ -148,7 +147,7 @@ data: {envelope-json}
148147
### Added
149148

150149
- `server/cmd/api/api/events.go``PublishEvent`, `StreamEvents`, `writeSSEEnvelope` helper. (Re-introduced; the base branch folded the prior `events.go` handlers into `capture_session.go`.)
151-
- `server/cmd/api/api/events_publish_test.go` — subtests: happy path + ring read, invalid JSON, missing type, unknown category, no-session 404, liveview routing, captcha routing, category derivation from type, default `source.kind` = `kernel_api`.
150+
- `server/cmd/api/api/events_publish_test.go` — subtests: happy path + ring read, invalid JSON, missing type, missing category, unknown category, no-session 404, liveview routing, captcha routing, default `source.kind` = `kernel_api`.
152151
- `server/cmd/api/api/events_stream_test.go` — subtests: `no_flusher_returns_500`, no-session 404, live streaming, `Last-Event-ID` resume across gaps, context cancellation on client disconnect.
153152

154153
---

0 commit comments

Comments
 (0)