Repository navigation
Conversation
…ai/events Capture v1 is now the default capture mode. The AI lane always posts capture v1 to /i/v1/ai/events, uncompressed, regardless of the analytics capture_mode. Tests move to a shared capture v1 send seam (posthog/test/capture_helpers.py); v0-only tests are pinned to CaptureMode.V0 until v0 removal.
posthog-python Compliance ReportDate: 2026-10-06T19:32:08.842651+00:00 ✅ All Tests Passed!116/116 tests passed Capture_V1 Tests✅ 95/95 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
Feature_Flags_Local_Evaluation Tests✅ 4/4 tests passed View Details
|
|
@greptileai review |
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
| raw = os.environ.get(CAPTURE_MODE_ENV_VAR) | ||
| if raw is None or raw.strip() == "": | ||
| return CaptureMode.V0 | ||
| return CaptureMode.V1 |
There was a problem hiding this comment.
With v1 becoming the default, replaying an event with its original UUID and timestamp before flushing can reject unrelated events too. If both copies share a request, the backend rejects the entire batch with HTTP 400, and the SDK drops every entry.
#1030 already documents this behavior. Consider discarding identical replay entries before submission, preserving their UUID/timestamp, so they cannot take unrelated events down with them.
Regression sketch: enqueue A, unrelated B, then an identical replay of A. Verify the outgoing batch contains A once and B is delivered. This sketch was not executed.
AI-assisted review.
💡 Motivation and Context
First PR in the capture v1 series, stacked on
v1(#1016).capture_mode. A blank or unrecognizedPOSTHOG_CAPTURE_MODEfalls back to v1. v0 stays opt-in until it is removed in a later PR.capture_aialways posts capture v1 to/i/v1/ai/events, uncompressed, whatever the analyticscapture_modeandcapture_compressionare. This keeps multi-MB AI events off the analytics endpoint's smaller caps._send_v1_batch/_post_v1take apathargument, and the consumer sends to its lane's endpoint.$liband$lib_versionfrom the request'sPostHog-Sdk-Infoheader and overwrites any value in the event. A$libset in a call, insuper_propertiesor inbefore_senddoes not reach PostHog. feat!: keep the posthog-python identity when instrumenting MCP #1034 fixes the header atposthog-python/<version>, so MCP instrumentation no longer relabels the client.capture/capture_aitests only change once.Test plumbing:
posthog/test/capture_helpers.pygives one seam for asserting on sent batches (patch_capture_send,patch_async_capture_send,sent_batch,sent_events), plusoffline_v1_postfor the subprocess tests. v1 never logs payloads, so those tests can no longer read the batch from the debug log.CaptureMode.V0for now. They get deleted along with v0.Compliance adapter:
_post_v1forwards the newpathargument.capture_ai_v0. Harness 1.1.1 only has an AI suite for/i/v0/ai/batch/, so it would fail now. AI compliance comes back ascapture_ai_v1with the harness 1.13.1 bump later in the series. Until then, the AI lane is covered by unit tests only.No new changeset: the major changeset on
v1already covers this.💚 How did you test it?
pytestsuite,ruff format --check,ruff check,mypywith the baseline filter,python -W error -c "import posthog", and the public API snapshot check, all locally.test_ai_capture_lane.pyasserts that the AI lane sends v1 to/i/v1/ai/eventswith no compression, even when analytics is pinned to v0 with gzip, in both async andsync_mode.test_capture_v1.pyasserts thatpathreaches the URL and is forwarded by_send_v1_batch.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Written with Cursor (Claude Opus) under the direction of the assignee. The test ports were mostly mechanical codemods from the v0
batch_postseam to the v1 send seam, followed by manual fixes. We chose to pin v0-only tests rather than delete them yet, so this diff stays reviewable before the v0 removal PR.