Skip to content

fix(0.9.1): unified LLM-call fingerprint collapses httpx + langchain duplicates#46

Merged
maltsev-dev merged 2 commits into
masterfrom
0.9.1
Jun 29, 2026
Merged

fix(0.9.1): unified LLM-call fingerprint collapses httpx + langchain duplicates#46
maltsev-dev merged 2 commits into
masterfrom
0.9.1

Conversation

@maltsev-dev

Copy link
Copy Markdown
Member

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_call events. Pre-0.9.1 the httpx transport (NullRunSyncTransport._emit) and the LangChain callback (NullRunCallback.on_llm_end) each computed their own _fingerprint from different inputs — sha256(host|status|body) vs sha256(json({path:"langchain_callback", run_id, response_id, model, provider, invocation_params})). The two fingerprints never collided, so the dedup LRU at runtime.track() could not collapse the two emissions for the same 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 the same helper _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.

Tests

  • 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.
  • tests/test_llm_call_metadata_flags.py updated 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-test to ship 0.9.1 directly.

Branch base: master @ f51780a (after 0.9.0 release via PR #45).

…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

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/nullrun/instrumentation/auto.py 88.88% 1 Missing ⚠️

📢 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.
@maltsev-dev maltsev-dev merged commit 3b3b1ab into master Jun 29, 2026
5 checks passed
@maltsev-dev maltsev-dev deleted the 0.9.1 branch June 29, 2026 15:37
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