Skip to content

fix: AI options on streaming connect errors; benchmark baseline route; review follow-ups - #1264

Open
eli-r-ph wants to merge 6 commits into
v1from
eli/v1-ai-connect-error-options
Open

eli-r-ph wants to merge 6 commits into
v1from
eli/v1-ai-connect-error-options

Conversation

@eli-r-ph

@eli-r-ph eli-r-ph commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

When a streaming AI call fails before the stream starts (for example a bad API key), the error event is sent without the caller's posthog_options. A call with posthog_options={"process_person_profile": False} or {"cookieless_mode": True} then sends its error event without those controls. Every other AI event carries them, as the 8.0 ai-posthog-options changeset promises.

This adds options= to the 10 connect-error paths: OpenAI chat and responses, Anthropic messages.create(stream=True) and messages.stream(), and Gemini, sync and async.

Also in this PR, from the review of #1016:

  • Benchmarks: the paired benchmark runs the merge-base SDK through this branch's receiver, which only accepted capture v1, so every baseline capture case failed with 404. It accepts legacy /batch again, answering in the legacy format. A local paired capture run (main vs this branch, 2 repetitions) completes all 56 cases.
  • Changeset: invalid-events-and-sizes no longer says a NaN event is dropped. A non-finite float is sent as null (request.py:457-490).
  • Migration guide: a None $geoip_disable blocks the SDK's True marker, like False.
  • Flaky test: the flag cache check in test_evaluate_flags.py now counts only calls made with the client's own key. Pollers left running by other test modules share the patched get, and one failed this check on CI.

💚 How did you test it?

  • The 10 existing connect-error tests now pass posthog_options and assert the options capture_ai receives: the caller's, plus process_person_profile: False for the 8 without a distinct id. All 10 fail without the fix and pass with it, and every earlier assertion is kept.
  • A new smoke case (a streamed call that fails before the stream starts) fails on v1 and passes on this branch.
  • The benchmark receiver test covers both routes and their reply formats; it fails without the fix (404).
  • A mutation that makes the flag cache path call the API fails 20 cases of the narrowed check.
  • The full suite passes, except 3 fork tests in test_metrics_autocapture.py that fail the same way on unchanged v1 on macOS.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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. Not needed: the unreleased ai-posthog-options changeset already covers this.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Written with Claude Code (Claude Opus 5.5) after a review comment on #1016. The fix copies the options= argument the success and mid-stream paths already pass.

🤖 Generated with Claude Code

The error event for a streaming call that fails before the stream starts (OpenAI chat and responses, Anthropic create and messages.stream, Gemini; sync and async) now carries the caller's posthog_options, like the other AI events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eli-r-ph
eli-r-ph requested a review from a team as a code owner November 16, 2026 21:17
@eli-r-ph eli-r-ph self-assigned this Nov 16, 2026
@veria-ai

veria-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

Benchmarks completed. No changes flagged for review.

Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.

View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation 133.68 KiB/op 133.68 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.49 count/op 1,345.49 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 61.51 µs/op 63.34 µs/op 3% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.74 MiB 37.69 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.2 MiB 40.14 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.2 MiB 40.14 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 61.9 µs/op 63.49 µs/op 2.6% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.36 MiB 40.33 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 185.76 KiB/op 185.76 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,337.52 count/op 1,337.52 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 85.4 µs/op 84.42 µs/op 1.1% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.4 MiB 41.35 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.19 MiB 47.13 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.19 MiB 47.13 MiB 0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 79.69 µs/op 78.79 µs/op 1.1% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.54 MiB 51.44 MiB 0.2% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.75 KiB/op 138.75 KiB/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.42 count/op 1,390.42 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 75.59 µs/op 73.46 µs/op 2.8% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.72 MiB 37.71 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.89 MiB 37.86 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.89 MiB 37.86 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 72.26 µs/op 70.83 µs/op 2% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.32 MiB 40.32 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 190.93 KiB/op 190.93 KiB/op <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.36 count/op 1,382.38 count/op <0.1% more Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 84.51 µs/op 87.86 µs/op 4% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.1 MiB 41.12 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.56 MiB 41.57 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.16 MiB 41.17 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 80.57 µs/op 82.96 µs/op 3% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.41 MiB 41.52 MiB 0.3% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 46.41 µs/op 46.6 µs/op 0.4% more time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 46.41 µs/op 46.59 µs/op 0.4% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 47.41 µs/op 45.1 µs/op 4.9% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 47.4 µs/op 45.09 µs/op 4.9% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 225.43 KiB/op 225.43 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,279.42 count/op 2,279.42 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 83.08 µs/op 82.75 µs/op 0.4% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 83.09 µs/op 82.75 µs/op 0.4% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.17 MiB/op 2.17 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 22,413.69 count/op 22,413.69 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 777.83 µs/op 771.4 µs/op 0.8% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 777.9 µs/op 771.42 µs/op 0.8% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 21.63 MiB/op 21.63 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 223,655.44 count/op 223,655.44 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 7.75 ms/op 7.75 ms/op <0.1% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 7.75 ms/op 7.75 ms/op <0.1% more time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.95 MiB 44.02 MiB 0.2% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.29 MiB 44.37 MiB 0.2% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.29 MiB 44.37 MiB 0.2% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 44.08 MiB 44.07 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.12 MiB 43.11 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.12 MiB 43.12 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.12 MiB 43.12 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 42.9 MiB 43.46 MiB 1.3% more memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.74 KiB/op 15.74 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 162.77 count/op 162.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 14.31 µs/op 14.18 µs/op 0.9% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 14.31 µs/op 14.18 µs/op 0.9% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 24.6 KiB/op 24.6 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 239.28 count/op 239.28 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 22.83 µs/op 22.94 µs/op 0.5% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 22.83 µs/op 22.94 µs/op 0.5% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 39.81 KiB/op 39.81 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 388.27 count/op 388.27 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 28.37 µs/op 28.55 µs/op 0.6% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 28.37 µs/op 28.55 µs/op 0.6% more time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 60.59 KiB/op 60.59 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 584.27 count/op 584.27 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 39.98 µs/op 39.84 µs/op 0.3% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 39.97 µs/op 39.84 µs/op 0.3% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 59.22 KiB/op 59.22 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 567.77 count/op 567.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 36.04 µs/op 36.4 µs/op 1% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 36.04 µs/op 36.4 µs/op 1% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.04 KiB/op 19.04 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 192.27 count/op 192.27 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 16.98 µs/op 17.25 µs/op 1.6% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 16.98 µs/op 17.25 µs/op 1.6% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 20.66 KiB/op 20.66 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 197.77 count/op 197.77 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 17.96 µs/op 18.07 µs/op 0.6% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 17.96 µs/op 18.07 µs/op 0.6% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.89 KiB/op 14.89 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 152.77 count/op 152.77 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 13.44 µs/op 13.43 µs/op <0.1% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 13.44 µs/op 13.43 µs/op <0.1% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.9 KiB/op 15.9 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 166.77 count/op 166.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 14.92 µs/op 15.05 µs/op 0.9% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 14.92 µs/op 15.05 µs/op 0.9% more time Not flagged

Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals.

Each shard uses its own runner; compare Before PR against With PR within a row, not across shards.

Compared 018d15de54954282867f1e3ea65313a282c96419 → 2f0cd843eedf5366a53d5c31f1657b1e535e4880.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eli-r-ph and others added 4 commits November 16, 2026 15:27
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The paired benchmark runs the merge-base SDK through this branch's receiver. It now accepts legacy /batch posts again, answering in the legacy format, beside capture v1 posts, so the baseline is measured instead of failing with 404. The receiver test covers both routes and their reply formats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pollers left running by other test modules share the patched module-level get, and one of them failed this check on CI. The check now ignores calls made with another client's key; a mutation that makes this client fetch still fails 20 cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eli-r-ph eli-r-ph changed the title fix(ai): send posthog_options on streaming connect errors fix: AI options on streaming connect errors; benchmark baseline route; review follow-ups Nov 17, 2026

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