Skip to content

fix(ai): use context distinct_id for OpenAI and Gemini embedding events - #1290

Open
pcbeingused333 wants to merge 2 commits into
PostHog:mainfrom
pcbeingused333:fix/embeddings-context-distinct-id
Open

pcbeingused333 wants to merge 2 commits into
PostHog:mainfrom
pcbeingused333:fix/embeddings-context-distinct-id

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Related to #1284 (same bug in the embedding path; #1284 itself covers streaming and is addressed by #1286)

💡 Motivation and Context

The OpenAI (_embeddings.py) and Gemini (gemini/_shared.py) embedding wrappers built $ai_embedding events from the posthog_distinct_id argument only. A distinct ID set with identify_context() was ignored, so the event was captured personless under the trace ID. The chat/generation path already reads get_context_distinct_id().

Both wrappers now resolve the ID through a small _resolve_distinct_id helper in posthog/ai/utils.py: the explicit argument first, then the active context's ID, then the existing trace-ID fallback (still personless).

💚 How did you test it?

  • Two new tests (OpenAI embeddings.create, Gemini embed_content) that call the wrapper inside new_context() after identify_context("context-user") and assert the captured distinct_id. Both fail on main (the trace ID is used) and pass with the fix.
  • posthog/test/ai/openai and posthog/test/ai/gemini: 404 passed, 6 skipped. ruff format --check is clean.
  • Tests use the mocked client; nothing ran against a live API.

📝 Checklist

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

If releasing new changes

  • Ran sampo add to generate a changeset file (added .sampo/changesets/embeddings-context-distinct-id.md in the same format)

🤖 Agent context

Autonomy: Fully autonomous

Embedding wrappers only looked at the posthog_distinct_id argument, so a distinct_id set via identify_context() was ignored and the $ai_embedding event was captured personless under the trace id. Resolve the id from the argument first, then the active context, matching the chat/generation path.

Signed-off-by: Alex <alex.castillog33@gmail.com>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 22, 2026 05:11

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime fix looks solid — we verified OpenAI and Gemini sync/async embedding events (including explicit override, blank-context fallback, and error paths) end-to-end against sdk-mock-server over /i/v1/ai/events, along with local ruff, mypy, check_public_api.py, and the OpenAI/Gemini/utils test suites.

One test coverage concern to address before approval: both new tests check distinct_id and event, but neither asserts that options is absent (so personless=resolved_distinct_id is None is currently unguarded), and _resolve_distinct_id precedence / whitespace-context cases aren't covered yet. Left details inline along with two optional suggestions.

AI-assisted review.


call_args = mock_client.capture_ai.call_args[1]
assert call_args["distinct_id"] == "context-user"
assert call_args["event"] == "$ai_embedding"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concern: Neither new test asserts that options is absent when the embedding event resolves distinct_id from identify_context(), leaving the personless=resolved_distinct_id is None half of the production change in posthog/ai/openai/_embeddings.py (line 66) and posthog/ai/gemini/_shared.py (line 285) unguarded, along with _resolve_distinct_id's precedence and blank-context branches.

Evidence and impact:

  • Inside with new_context(): identify_context("context-user"), this PR changes two user-visible behaviors: distinct_id switches from trace_id to "context-user", and personless switches from True (options={"process_person_profile": False}) to False (options omitted).
  • Both test_embeddings_use_context_distinct_id (posthog/test/ai/openai/test_openai.py:480-482) and test_embed_content_uses_context_distinct_id (posthog/test/ai/gemini/test_gemini.py:1388-1390) assert only call_args["distinct_id"] and call_args["event"]. Reverting personless=resolved_distinct_id is None back to personless=_user_distinct_id(distinct_id) is None in both production files would silently emit personless $ai_embedding events (options={"process_person_profile": False}) for identified users while all 404 OpenAI and Gemini tests still pass.
  • Sibling context tests in this repo (test_streaming_uses_outer_context_distinct_id from fix(ai): use the context distinct id for streamed generations #1286 and test_outer_context_distinct_id_is_used in posthog/test/ai/anthropic/test_anthropic.py) assert assert "options" not in call_args to guard this contract (capture-ai spec: only fallback trace IDs force options.process_person_profile: false).

Recommendation:
Consider adding assert "options" not in call_args to both test_embeddings_use_context_distinct_id (here) and test_embed_content_uses_context_distinct_id (posthog/test/ai/gemini/test_gemini.py:1390), plus a focused test covering explicit posthog_distinct_id overriding identify_context and a whitespace-only context falling back to a personless trace_id.

Test sketch (not executed as a committed test; equivalent scenarios passed on head f3c8d48b via local mock-server smoke testing):

# In both test_embeddings_use_context_distinct_id and test_embed_content_uses_context_distinct_id:
assert call_args["distinct_id"] == "context-user"
assert call_args["event"] == "$ai_embedding"
assert "options" not in call_args

# Plus in posthog/test/ai/test_utils.py (or alongside the embedding tests):
def test_resolve_distinct_id_precedence_and_blank_values():
    from posthog import identify_context, new_context
    from posthog.ai.utils import _resolve_distinct_id

    with new_context(fresh=True):
        assert _resolve_distinct_id(None) is None
        identify_context("   ")
        assert _resolve_distinct_id(None) is None
        identify_context("context-user")
        assert _resolve_distinct_id(None) == "context-user"
        assert _resolve_distinct_id("   ") == "context-user"
        assert _resolve_distinct_id("explicit-user") == "explicit-user"

Comment thread posthog/ai/utils.py Outdated

def _resolve_distinct_id(distinct_id: Any) -> Any:
"""The caller's distinct id, else the one from the active PostHog context, else None."""
return _user_distinct_id(distinct_id) or _user_distinct_id(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: _resolve_distinct_id and its callers mix or truthiness with is None, which mishandles falsy non-string distinct IDs such as integer 0.

Evidence and reachability:

  • _user_distinct_id(0) returns 0 (not None) because _explicit_distinct_id(0) uses stringify_id(0) == "0".
  • In _resolve_distinct_id (posthog/ai/utils.py:77) and the callers (posthog/ai/openai/_embeddings.py:63-66, posthog/ai/gemini/_shared.py:282-285), resolved_distinct_id or trace_id treats 0 as falsy while personless=resolved_distinct_id is None treats 0 as present.
  • Executed base (84fc9e06) vs head (f3c8d48b) comparison:
    • with new_context(): identify_context(0); client.embeddings.create(..., posthog_trace_id="t4"):
      • Base: distinct_id="t4", options={"process_person_profile": False}
      • Head: distinct_id="t4", options=None (emits a random trace UUID without process_person_profile: False)
    • with new_context(): identify_context("context-user"); client.embeddings.create(..., posthog_distinct_id=0, posthog_trace_id="t5"):
      • Base: distinct_id="t5", options=None
      • Head: distinct_id="context-user", options=None (explicit 0 is overridden by the context user)
  • Reachability is low because identify_context(distinct_id: str) and posthog_distinct_id: Optional[str] are typed str, so only untyped/dynamic callers passing integer 0 hit this.

Recommendation:
Consider using explicit is not None checks so truthiness and personless cannot disagree:

def _resolve_distinct_id(distinct_id: Any) -> Any:
    """The caller's distinct id, else the one from the active PostHog context, else None."""
    resolved = _user_distinct_id(distinct_id)
    if resolved is not None:
        return resolved
    return _user_distinct_id(contexts.get_context_distinct_id())

and in posthog/ai/openai/_embeddings.py:63 / posthog/ai/gemini/_shared.py:282:

distinct_id=resolved_distinct_id if resolved_distinct_id is not None else trace_id,

Comment thread posthog/ai/utils.py
return distinct_id if _explicit_distinct_id(distinct_id) is not None else None


def _resolve_distinct_id(distinct_id: Any) -> Any:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Now that #1286 (470a6413) has landed on main with the identical _user_distinct_id(...) or _user_distinct_id(contexts.get_context_distinct_id()) expression in capture_streaming_event (posthog/ai/utils.py:1321-1323 on main), consider reusing _resolve_distinct_id(event_data.get("distinct_id")) there if you rebase onto main, so both streaming and embedding paths share one helper. (No merge conflict exists either way.)

@dustinbyrne
dustinbyrne requested a review from a team November 23, 2026 21:10
…checks

Address review: assert options are absent for context-resolved embedding events, add _resolve_distinct_id precedence/blank tests, and compare resolved ids with 'is not None' so a falsy id such as 0 cannot disagree between distinct_id and personless.

Signed-off-by: Alex <alex.castillog33@gmail.com>
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. Pushed 01feddc:

  • both embedding tests now assert "options" not in call_args;
  • added test_resolve_distinct_id_precedence_and_blank_values (precedence, blank context, explicit override, falsy 0);
  • _resolve_distinct_id and the OpenAI/Gemini callers use is not None checks, so distinct_id and personless cannot disagree for falsy ids.

I left the capture_streaming_event reuse for a separate change to keep this PR scoped.

This reply was drafted with an AI coding assistant (Claude); the change was tested with the OpenAI/Gemini/utils suites.

@github-actions

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.67 KiB/op 133.67 KiB/op <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.53 count/op 1,345.52 count/op <0.1% fewer Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 139.64 µs/op 134.89 µs/op 3.4% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.72 MiB 37.67 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.17 MiB 40.12 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.17 MiB 40.12 MiB 0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 140.18 µs/op 134.32 µs/op 4.2% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.4 MiB 40.34 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.57 count/op 1,337.57 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 169.9 µs/op 178.19 µs/op 4.9% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.34 MiB 41.37 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.12 MiB 47.16 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.12 MiB 47.16 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 161.85 µs/op 171.71 µs/op 6.1% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.51 MiB 51.6 MiB 0.2% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.74 KiB/op 138.74 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.44 count/op 1,390.44 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 161.58 µs/op 152.01 µs/op 5.9% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.59 MiB 37.61 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.77 MiB 37.76 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.77 MiB 37.76 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 160.87 µs/op 149.37 µs/op 7.1% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.11 MiB 40.11 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 190.92 KiB/op 190.92 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.38 count/op 1,382.36 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 173.71 µs/op 191.1 µs/op 10% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.22 MiB 41.15 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.68 MiB 41.59 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.28 MiB 41.2 MiB 0.2% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 164.64 µs/op 186.78 µs/op 13.5% more time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.63 MiB 41.58 MiB 0.1% less memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 105.47 µs/op 108.29 µs/op 2.7% more time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 105.48 µs/op 113.36 µs/op 7.5% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 114.21 µs/op 110.59 µs/op 3.2% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 116.9 µs/op 113.81 µs/op 2.6% 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 68.17 µs/op 67.26 µs/op 1.3% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 68.17 µs/op 67.27 µs/op 1.3% 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 662.59 µs/op 663.05 µs/op <0.1% more time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 662.5 µs/op 662.97 µs/op <0.1% more 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 6.8 ms/op 6.72 ms/op 1.2% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 6.8 ms/op 6.72 ms/op 1.2% less time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.81 MiB 43.91 MiB 0.2% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.16 MiB 44.21 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.16 MiB 44.21 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 43.96 MiB 43.95 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 42.95 MiB 42.97 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 42.96 MiB 42.97 MiB <0.1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 42.96 MiB 42.94 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 42.73 MiB 43.29 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.22 µs/op 14.17 µs/op 0.3% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 14.22 µs/op 14.17 µs/op 0.3% 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.76 µs/op 22.52 µs/op 1.1% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 22.76 µs/op 22.52 µs/op 1% less 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.23 µs/op 28.44 µs/op 0.7% more time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 28.23 µs/op 28.44 µs/op 0.7% 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.55 µs/op 39.53 µs/op <0.1% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 39.54 µs/op 39.52 µs/op <0.1% 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 35.78 µs/op 35.55 µs/op 0.6% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 35.78 µs/op 35.55 µs/op 0.6% less 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.94 µs/op 16.91 µs/op 0.2% less time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 16.94 µs/op 16.9 µs/op 0.2% less 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 18.17 µs/op 17.86 µs/op 1.7% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 18.17 µs/op 17.86 µs/op 1.7% less 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.38 µs/op 0.5% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 13.44 µs/op 13.38 µs/op 0.5% 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.95 µs/op 14.97 µs/op 0.1% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 14.95 µs/op 14.97 µs/op 0.1% 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 84fc9e06bd898fe090e7443138e32010b9aa91db → 01feddcf46364e70c93040b5e2c18978ae3e8c26.

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.

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following up — the "options" not in call_args assertions, _resolve_distinct_id precedence/blank/falsy-0 tests, and is not None checks address the earlier feedback cleanly, and deferring the capture_streaming_event cleanup keeps this well-scoped. Verified locally with ruff, mypy, check_public_api.py, the AI unit tests, and both synthetic and live OpenAI (text-embedding-3-small) + Gemini (gemini-embedding-001) embedding calls captured by sdk-mock-server over /i/v1/ai/events. LGTM!

AI-assisted review.

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.

2 participants