Gate external event producers through telemetry config#258
Conversation
POST /telemetry/events and sysmon previously published directly to the event stream, so events flowed even with no telemetry session active or the category disabled. Route both through TelemetrySession so callers that explicitly turn telemetry off (or omit a config) no longer see external producers leak into the stream. Filtered publishes still ack the request but return seq=0 to signal the drop.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 049b98c. Configure here.
Monitoring Plan: Route In-VM Telemetry Through TelemetrySessionWhat this PR does: Enforces a rule that all in-VM telemetry producers publish through the Intended effect:
Risks:
Status updates will be posted automatically on this PR as monitoring progresses. |

Overview
External event producers (
POST /telemetry/events, sysmon's kmsg reader, the CDP proxy, theapi_callmiddleware, cdpmonitor) used to publish directly to the rawEventStream, which bypassed the activeTelemetrySessionand leaked events into the stream even when telemetry was unconfigured or the category was disabled. This PR routes every producer throughTelemetrySessionso they all honor the same gating.Concretely:
POST /telemetry/eventsnow returns204 No Contentwhen filtered, and200with the assigned envelope when admitted (previously:200withseq: 0to signal a drop, which violated the schema)TelemetrySessionis documented as a non-nil invariant:NewTelemetrySessionpanics on a nilEventStream,ApiServiceconstruction rejects a nil session, and methods don't tolerate a nil receiverTelemetrySession, never directly toEventStream.AGENTS.mddocuments the rule.System events still flow whenever a telemetry session is active: the
events.Systemforce-include inStart/UpdateConfigis unchanged. Only the bypass paths are closed.Pls don't review this PR by commit. I had opus rewrite whatever another agent initially came up with (which was just not good)
Testing
CI + smoke tests
POST /telemetry/eventswith no active session → expect204204 0B, body empty204for shim postsservice_crashedphase=running (supervisorctl signal KILL chromium)phase=running,pid=273,service_name=chromiumservice_crashedphase=gave_up (flaky service exhaustingstartretries)phase=gave_up,service_name=flaky, nopidfieldsupervisorctl stop chromium)service_crashedevents in the 4 s windowsystem_oom_kill(synthetic kmsg dump)constraint=none,mem_total_kb=2097152,mem_free_kb=18240,top_tasks[0].name=chromium,trigger_process_name=chromiumsystem_oom_kill(real cgroup OOM under--memory 512m)constraint=memcgevents (python3+chromium);mem_total_kb/mem_free_kbcorrectly omitted;top_tasksnames clean (python3,Xvfb,chromium,kernel-images-a,chromedriver)service_crashedphase=runningchromium-headful-test:latestAll events carry
category: "system"andmetadata.telemetry_session_idcorrectly.api_callevents also flow onceapiis captured (visible in T1 as a side-effect of the shim's POST).Note
Medium Risk
Changes which events reach the stream and the POST /telemetry/events contract; misconfiguration could drop expected telemetry until PUT /telemetry starts a session.
Overview
External telemetry producers no longer write to the raw
EventStream.TelemetrySession.Publishis now the single gate: it applies the active session, category filter, andtelemetry_session_idmetadata before anything reaches SSE/S2.POST /telemetry/events, sysmon (kmsg OOM), CDP monitor/proxy, andapi_callHTTP middleware all use a sharedfunc(Event) (Envelope, bool)callback wired totelemetrySession.Publishinmain.go. Filtered publishes return204 No Content; admitted events return200with the real envelope (replacing the old200+seq: 0drop signal). OpenAPI and generated clients were updated accordingly.TelemetrySessionis documented as a required non-nil dependency; producer callback types and tests were updated.AGENTS.mdandlib/sysmondocs now state that producers must not bypass the session.Reviewed by Cursor Bugbot for commit 049b98c. Bugbot is set up for automated code reviews on this repo. Configure here.