fix(llma): use toString zero-UUID guard in generation sampling#60632
Merged
andrewm4894 merged 3 commits intoMay 29, 2026
Conversation
toUUIDOrZero is not in the HogQL function allowlist, so every llma-generation-summarization-coordinator child workflow has been failing inside sample_items_in_window_activity since #59186 with QueryError: Unsupported function call 'toUUIDOrZero(...)'. That collapsed $ai_generation_summary to 0, and (7 days later) $ai_generation_clusters too. Replace the HAVING comparand with toString(...) against the literal zero UUID — both are HogQL-supported. Update the test to assert the new shape and to run the materialized query through prepare_and_print_ast so the next "function not whitelisted" regression fails in CI, not prod.
Contributor
|
Reviews (1): Last reviewed commit: "fix(llma): use toString zero-UUID guard ..." | Re-trigger Greptile |
carlos-marchal-ph
approved these changes
May 29, 2026
toUUID('...') is constant-folded at plan time and gives a UInt128
compare instead of a per-row 36-byte string compare. Same semantics,
cheaper. Test guard updated to match.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
$ai_generation_summaryhas been at 0 since 2026-05-20, which in turn took$ai_generation_clustersto 0 on 2026-05-27 (clustering uses the last 7 days of summary embeddings). Trace summaries were unaffected because the trace-level path doesn't hit the same expression.Root cause: the
HAVINGclause in the generation sampling query usestoUUIDOrZero(''), which is not in the HogQL function allowlist (posthog/hogql/functions/clickhouse/conversions.py). Everyllma-generation-summarization-coordinator-schedulechild workflow has been failing insidesample_items_in_window_activitywithQueryError: Unsupported function call 'toUUIDOrZero(...)'. The existing unit test mockedexecute_hogql_query, so the HogQL validator never ran against this query.Changes
posthog/temporal/ai_observability/trace_summarization/sampling.py: replaceHAVING last_generation_id != toUUIDOrZero('')withHAVING last_generation_id != toUUID('00000000-0000-0000-0000-000000000000').toUUIDis HogQL-allowed and constant-folded at plan time, so the comparand is a singleUInt128value — the per-row work is a 16-byte UUID compare, no string materialization.posthog/temporal/ai_observability/trace_summarization/tests/test_workflow.py: updatetest_generation_filter_is_applied_inside_argmaxifto assert the new HAVING shape, then run the materialized query throughprepare_and_print_ast. This catches the same class of regression (function not whitelisted) at unit-test time instead of in production.How did you test this code?
I'm an agent (Claude Opus 4.7) collaborating with @andrewm4894.
Automated:
hogli test posthog/temporal/ai_observability/trace_summarization/tests/test_workflow.py— all pass, including the updated guard that now exercises the real HogQL printer.Local end-to-end against real ClickHouse:
$ai_generationevents spanning May 18–28 (viaexecute-sql).temporalio.testing.ActivityEnvironmentinmanage.py shell:SampledItems with validtrace_id+generation_id, noQueryError. This is the same code path that's been crashing in prod since 2026-05-20.Negative-case verification (reproducing the bug):
toUUIDOrZero('')and re-ran the same activity.QueryError: Unsupported function call 'toUUIDOrZero(...)'. Perhaps you meant 'toIntOrZero(...)'?git diff HEADconfirms the working tree matches the committed version.Automatic notifications
Docs update
n/a
🤖 Agent context
toUUIDOrZero. Verified independently by grepingposthog/hogql/functions/(toUUIDOrZeroabsent;toStringandtoUUIDpresent inclickhouse/conversions.py).toString(last_generation_id) != '...'. Reviewed the perf shape on a follow-up:toUUID('...')is constant-folded at plan time and reduces the per-row work to aUInt128compare instead of materializing a 36-byte string per group. Swapped to the UUID form — same semantics, strictly less work for ClickHouse.prepare_and_print_aststep in the test needsdatabase_sync_to_async(printer loads the team via Django ORM) andenable_select_queries=True(defaultHogQLContextblocks full SELECTs). Both caught by failing test runs while iterating, not guessed up front.QueryErrorseen in prod. Working tree confirmed clean against HEAD afterwards. Re-ran end-to-end after thetoString→toUUIDswap, same 20-items result.