fix(0.9.1): unified LLM-call fingerprint collapses httpx + langchain duplicates#46
Merged
Conversation
…duplicates Pre-0.9.1 the httpx transport and the LangChain callback each computed their own _fingerprint from different inputs (sha256 of body bytes vs sha256 of langchain callback metadata). The two fingerprints never collided, so the dedup LRU at runtime.track() could not collapse the two emissions for the same real call. On a typical app.invoke() with 6 LLM calls the backend saw ~12 llm_call events on the wire (2 per real call), doubling llm_call_count and skewing cost_events aggregates. Both observers now call _fingerprint_for_llm_call(model, provider, response_id) with the three signals reachable from every path: - httpx transport: payload['model'], payload['id'] - LangChain callback: invocation_params.model / response.llm_output['model_name'], response.llm_output['id'] / response.id / AIMessage.id / response.response_metadata['id'] _openai_extractor now also returns 'id' alongside 'model' so the transport has it without re-parsing the body. When any of the three signals is missing the helper falls back to the empty string on that slot — deterministic for the call, just less specific. A missing id (custom chat-model wrappers) still collapses the two observers via the model+provider combination. tests/test_unified_fingerprint.py pins the new contract: deterministic, distinct inputs → distinct fingerprints, both observers converge on the same fingerprint for the same call. Bumps version 0.9.0 → 0.9.1. CHANGELOG entry added above 0.9.0. No public-API break.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…known The 0.9.1 unified-fingerprint commit added an `if not model: return` guard to `_emit_streaming_skipped` as a ghost-event dedup. It was too aggressive — the test_streaming_oom_cap contract pins that the event fires whenever the cap is exceeded, so the backend's coverage denominator (llm_call_count) stays accurate. The test creates a request with no model in the body; the guard dropped the event and runtime.track was never called → 2 tests failed on CI. Remove the guard, keep the _fingerprint attachment (still the right move for dedup with sibling langchain-callback emissions). When model is None the backend's into_track_request_v2 gate may log a cost_pipeline_missing_model_total warning, but that's the same noise pre-0.9.1 produced and is preferable to silently dropping the event and skewing coverage_pct. metadata.streaming_skipped: True tells the backend this is a known-skipped emission, not a real call to bill against.
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.
Patch on top of 0.9.0. Unifies the LLM-call fingerprint scheme so the dedup LRU at
runtime.track()can collapse sibling emissions from the httpx transport and the LangChain callback for the same real call.Fixed
Double-emission of
llm_callevents. Pre-0.9.1 the httpx transport (NullRunSyncTransport._emit) and the LangChain callback (NullRunCallback.on_llm_end) each computed their own_fingerprintfrom different inputs —sha256(host|status|body)vssha256(json({path:"langchain_callback", run_id, response_id, model, provider, invocation_params})). The two fingerprints never collided, so the dedup LRU atruntime.track()could not collapse the two emissions for the same call. On a typicalapp.invoke()with 6 LLM calls the backend saw ~12llm_callevents on the wire (2 per real call), doublingllm_call_countand skewingcost_eventsaggregates.Both observers now call the same helper
_fingerprint_for_llm_call(model, provider, response_id)with the three signals reachable from every path:payload["model"],payload["id"]invocation_params.model/response.llm_output["model_name"],response.llm_output["id"]/response.id/ AIMessage.id /response.response_metadata["id"]_openai_extractornow also returns"id"alongside"model"so the transport has it without re-parsing the body. When any of the three signals is missing the helper falls back to the empty string on that slot — deterministic for the call, just less specific.Tests
tests/test_unified_fingerprint.pypins the new contract: deterministic, distinct inputs → distinct fingerprints, both observers converge on the same fingerprint for the same call.tests/test_llm_call_metadata_flags.pyupdated to match the new extractor shape.Release
Version bump 0.9.0 → 0.9.1 and CHANGELOG entry included in this same PR (no separate bump PR). Once merged, master is ready for
publish-testto ship0.9.1directly.Branch base:
master@f51780a(after 0.9.0 release via PR #45).