Skip to content

feat!: AI wrappers always send through capture_ai - #1027

Draft
eli-r-ph wants to merge 1 commit into
v1-capture-harnessfrom
v1-capture-ai-wrappers
Draft

eli-r-ph wants to merge 1 commit into
v1-capture-harnessfrom
v1-capture-ai-wrappers

Conversation

@eli-r-ph

@eli-r-ph eli-r-ph commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

This PR sends every wrapper event through capture_ai. enable_full_ai_capture now controls only content: truncation and media redaction.

Changes

  • The OpenAI, Anthropic, Gemini, LangChain, Claude Agent SDK and OpenAI Agents integrations always send through capture_ai, with or without enable_full_ai_capture. They all use one helper, _capture_ai_event.
  • A client object without a capture_ai method, such as a custom stand-in, still receives capture calls.
  • The enable_full_ai_capture docstrings no longer say the flag routes events.
  • _use_ai_lane and _enable_multimodal_capture stay deprecated aliases of enable_full_ai_capture. Their names are now misleading, but callers that set them get the same result as before.
  • MCP events stay on capture, because they are not $ai_* events.

Warning

Two breaking effects for users:

  • A test suite that passes a Mock client to a wrapper and asserts on mock.capture now sees the call on mock.capture_ai. The old helper tests kept Mock clients on capture on purpose; those tests are replaced.
  • A deployment that does not serve /i/v1/ai/events now drops wrapper events. Before this PR, wrapper events without the opt-in used /i/v1/batch/.

Divergence from sdk-specs

The capture-ai spec in PostHog/sdk-specs ties wrapper routing to the flag. This PR diverges from it. Proposed spec change:

-accepts much larger payloads than analytics capture. PostHog's own AI wrapper
-libraries route through it when the client opts in; users call it directly for
-manual AI capture.
+accepts much larger payloads than analytics capture. PostHog's own AI wrapper
+libraries always route through it; users call it directly for manual AI capture.
@@ ## Configuration
-Node — client option), default false. When true, PostHog's AI wrapper
-libraries:
-
-1. route their events through the dedicated AI path instead of analytics
-   `capture`,
-2. skip string truncation (a cut through base64 corrupts media; large text
+Node — client option), default false. It governs content only, not routing.
+When true, PostHog's AI wrapper libraries:
+
+1. skip string truncation (a cut through base64 corrupts media; large text
    contexts stay intact), and
-3. pass media (raw bytes, base64, data URIs) through unredacted instead of
+2. pass media (raw bytes, base64, data URIs) through unredacted instead of
    replacing it with type-aware placeholders.

Plus a new requirement: "AI wrappers send through capture_ai", with one scenario per flag value that asserts the wrapper event arrives on the AI endpoint only. The spec PR is not opened yet.

💚 How did you test it?

  • The wrapper suites now assert on capture_ai (about 465 assertions, renamed by a script). Every wrapper test therefore checks the default routing, with the flag off.
  • test_routes_only_through_ai_lane sends through a real client, with the flag off and on. It asserts the AI path is the only path posted, so it also catches an event sent on both lanes.
  • test_client_without_capture_ai_falls_back_to_capture covers a client object with no capture_ai, with the flag off and on.
  • The per-wrapper "opt-in routes through capture_ai" tests, the Mock client tests and one duplicate lane test are removed. The tests above cover them.
  • Break-on-purpose, each with failing tests: the old flag gate restored (311 failures), events sent on both lanes (12), the fallback removed (16).
  • The public API snapshot is unchanged.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

Covered by the existing capture-v1-major changeset; the migration guide lands later in this stack.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Written with Cursor (Claude Opus) under the direction of the assignee. Skills used: writing-tests, writing-pr-descriptions.

Agreed before implementation: wrappers always use capture_ai, the flag controls only content, and the PR calls out the spec divergence.

Agent calls worth review:

  • The duck-typed fallback to capture stays. Removing it would break custom client objects that have no capture_ai.
  • The deprecated aliases stay, because the posthog monorepo still sets them.

@eli-r-ph eli-r-ph self-assigned this Oct 7, 2026
enable_full_ai_capture now controls only truncation and media redaction. A client object without capture_ai still gets capture calls.
@eli-r-ph
eli-r-ph force-pushed the v1-capture-ai-wrappers branch from fde9c61 to 31c13ba Compare October 7, 2026 03:56

This branch has not been deployed

No deployments
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.

1 participant