Ë
    tPêjˆ  ã            	       ój  — U d Z ddlmZmZmZ ddlmZ erddlmZ ed   Z	dZ
eee	df      ed<   i Zeeee	ef   f   ed<   d	j#                  d
„  e ee
«      «      D «       «      Zeed<   dd	j#                  e
«      › de› dd	j#                  d„ e
D «       «      › d�Zeed<   defd„Zdede	ddfd„Zdd„Zy)aF  Pod-local queue of shadow-eval funnel increments, drained by the spend-update job.

The shadow-eval success hook counts the sampled-traffic outcomes that never produce an
attempt row (a lost sampling dice roll, an unjudgeable request shape, a concurrency
shed), so a job's results can state what share of its eligible traffic the judged rows
represent. Counters are advisory coverage stats: a pod dying loses at most one flush
interval, and a failed flush drops its batch because a repeated increment is worse
than an undercount (same call as the auto-router session rollup flush).
é    )ÚTYPE_CHECKINGÚFinalÚLiteral)Úverbose_proxy_logger)ÚPrismaClient)Únot_sampledÚunjudgeableÚshedÚwithheld.ÚFUNNEL_STAGESÚ_pendingz, c              #   ó,   K  — | ]  }d |dz   › �–— Œ y­w)ú$é   N© )Ú.0Úns     úh/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/db/shadow_eval_funnel.pyú	<genexpr>r      s   è ø€ Ò'W¸¨!¨A°©E¨7¬Ñ'Wùs   ‚Ú_FUNNEL_PLACEHOLDERSz1
INSERT INTO "LiteLLM_ShadowEvalFunnel" (job_id, z)
VALUES ($1, z))
ON CONFLICT (job_id) DO UPDATE SET
    c              #   ó0   K  — | ]  }|› d |› d|› �–— Œ y­w)z = "LiteLLM_ShadowEvalFunnel".z + EXCLUDED.Nr   )r   Ústages     r   r   r      s#   è ø€ ÒmÐV[�%�Ð6°u°g¸\È%ÈÔQÑmùs   ‚ú
Ú_UPSERT_FUNNEL_SQLÚreturnc                  óJ   — t        d„ t        j                  «       D «       «      S )z Queue census for the drain triggers: entries not yet flushed, so a funnel-only
    batch still wakes the spend job that would otherwise skip an empty-queue run.c              3   óN   K  — | ]  }t        |j                  «       «      –— Œ y ­w©N)ÚsumÚvalues)r   Úcounterss     r   r   z4pending_shadow_eval_funnel_events.<locals>.<genexpr>%   s   è ø€ ÒH¨(Œs�8—?‘?Ó$×%ÑHùs   ‚#%)r   r   r    r   ó    r   Ú!pending_shadow_eval_funnel_eventsr#   "   s   € ô ÑH´h·o±oÓ6GÔHÓHÐHr"   Újob_idr   Nc                 óz   — t         j                  | t        j                  t        d«      «      }||xx   dz  cc<   y)z¡Count one skipped request for one job leg; synchronous so the hook's read-modify-
    write cannot interleave with the flush's snapshot on the shared event loop.r   é   N)r   Ú
setdefaultÚdictÚfromkeysr   )r$   r   r!   s      r   Úrecord_shadow_eval_funnel_eventr*   (   s/   € ô ×)Ñ)¨&´$·-±-ÄÈqÓ2QÓR€HØˆUƒO�qÑ„Or"   c              ƒ   ób  ‡K  — t         sy t        t         «      }t         j                  «        |j                  «       D ]=  \  }Š	  | j                  j
                  t        |gˆfd„t        D «       ¢­Ž ƒ d {  –—†  Œ? y 7 Œ# t        $ r"}t        j                  d|‰|«       Y d }~Œid }~ww xY w­w)Nc              3   ó(   •K  — | ]	  }‰|   –— Œ y ­wr   r   )r   r   r!   s     €r   r   z+flush_shadow_eval_funnel.<locals>.<genexpr>9   s   øè ø€ Ò= e�(˜5•/Ñ=ùs   ƒzKSpend tracking - shadow eval funnel flush failed for job %s, %s dropped: %s)r   r(   ÚclearÚitemsÚdbÚexecute_rawr   r   Ú	Exceptionr   Úerror)Úprisma_clientÚbatchr$   Ú	flush_errr!   s       @r   Úflush_shadow_eval_funnelr6   /   s©   øè ø€ ÝØÜœ“>€EÜ‡N�NÔØ!ŸK™K›Mò Ñˆ�ð	Ø.�-×"Ñ"×.Ñ.Ü"Øðó >¬}Ô=ò÷ ñ ñðùô
 ò 	Ü ×&Ñ&Ø]ØØØ÷	ñ ûð	üsB   ƒAB/Á2BÁ7A?Á8BÁ<B/Á?BÂ	B,Â
B'Â"B/Â'B,Â,B/)r3   r   r   N)Ú__doc__Útypingr   r   r   Úlitellm._loggingr   Úlitellm.proxy.utilsr   ÚShadowEvalFunnelStager   ÚtupleÚ__annotations__r   r(   ÚstrÚintÚjoinÚrangeÚlenr   r   r#   r*   r6   r   r"   r   ú<module>rC      s  ðò÷ 1Ñ 0å 1áÝ0àÐ PÑQÐ à:l€ˆu�UÐ0°#Ð5Ñ6Ñ7Ó là8:€ˆ$ˆs�DÐ.°Ð3Ñ4Ð4Ñ
5Ó :à"Ÿi™iÑ'W¹UÁ3À}ÓCUÓ=VÔ'WÓWÐ �eÓ Wð!1Ø15·±¸=Ó1IÐ0Jð KØ!Ð"ð #à	‡Y�YÑmÐ_lÔmÓmÐnð oð	Ð �Eó ðI¨3ó Ið¨Cð Ð8Mð ÐRVó ôr"   