inferdiff 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inferdiff-0.2.0/PKG-INFO +326 -0
- inferdiff-0.2.0/README.md +300 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/pyproject.toml +3 -3
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/__init__.py +1 -1
- inferdiff-0.2.0/src/inferdiff/_http_server.py +61 -0
- inferdiff-0.2.0/src/inferdiff/_probe_data.py +114 -0
- inferdiff-0.2.0/src/inferdiff/_sse_contract.py +436 -0
- inferdiff-0.2.0/src/inferdiff/_urls.py +57 -0
- inferdiff-0.2.0/src/inferdiff/anthropic.py +241 -0
- inferdiff-0.2.0/src/inferdiff/audit_cmd.py +225 -0
- inferdiff-0.2.0/src/inferdiff/badge.py +122 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/canary.py +536 -84
- inferdiff-0.2.0/src/inferdiff/cli.py +940 -0
- inferdiff-0.2.0/src/inferdiff/comparison.py +558 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/detectors.py +196 -19
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/dialects/__init__.py +14 -4
- inferdiff-0.2.0/src/inferdiff/dialects/anthropic_messages.py +96 -0
- inferdiff-0.2.0/src/inferdiff/dialects/gemini_sse.py +85 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/dialects/sglang_native.py +3 -3
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/differ.py +11 -5
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/exporter.py +138 -45
- inferdiff-0.2.0/src/inferdiff/exporters.py +246 -0
- inferdiff-0.2.0/src/inferdiff/gemini.py +143 -0
- inferdiff-0.2.0/src/inferdiff/init_cmd.py +163 -0
- inferdiff-0.2.0/src/inferdiff/metrics.py +140 -0
- inferdiff-0.2.0/src/inferdiff/probes/__init__.py +12 -0
- inferdiff-0.2.0/src/inferdiff/probes/_http.py +81 -0
- inferdiff-0.2.0/src/inferdiff/probes/_task.py +56 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/probes/base.py +2 -2
- inferdiff-0.2.0/src/inferdiff/probes/composite.py +88 -0
- inferdiff-0.2.0/src/inferdiff/probes/lmcache.py +93 -0
- inferdiff-0.2.0/src/inferdiff/probes/mooncake.py +115 -0
- inferdiff-0.2.0/src/inferdiff/probes/proc_io.py +143 -0
- inferdiff-0.2.0/src/inferdiff/probes/prom.py +181 -0
- inferdiff-0.2.0/src/inferdiff/proxy.py +1022 -0
- inferdiff-0.2.0/src/inferdiff/proxy_ui.py +602 -0
- inferdiff-0.2.0/src/inferdiff/pytest_plugin.py +22 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/recorder.py +382 -122
- inferdiff-0.2.0/src/inferdiff/redact.py +741 -0
- inferdiff-0.2.0/src/inferdiff/replay.py +238 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/schema.py +139 -33
- inferdiff-0.2.0/src/inferdiff/testing.py +151 -0
- inferdiff-0.2.0/src/inferdiff/watch.py +293 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/waterfall.py +384 -84
- inferdiff-0.2.0/src/inferdiff.egg-info/PKG-INFO +326 -0
- inferdiff-0.2.0/src/inferdiff.egg-info/SOURCES.txt +70 -0
- inferdiff-0.2.0/src/inferdiff.egg-info/requires.txt +3 -0
- inferdiff-0.2.0/tests/test_anthropic_parser.py +169 -0
- inferdiff-0.2.0/tests/test_audit_cmd.py +331 -0
- inferdiff-0.2.0/tests/test_comparison_unit.py +97 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/tests/test_doctor_and_waterfall.py +178 -2
- inferdiff-0.2.0/tests/test_exporters.py +387 -0
- inferdiff-0.2.0/tests/test_gemini_and_replay.py +406 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/tests/test_inferdiff.py +22 -18
- inferdiff-0.2.0/tests/test_init_cmd.py +179 -0
- inferdiff-0.2.0/tests/test_live_contract_comparison.py +389 -0
- inferdiff-0.2.0/tests/test_metrics.py +370 -0
- inferdiff-0.2.0/tests/test_proxy.py +1036 -0
- inferdiff-0.2.0/tests/test_stream_limits.py +201 -0
- inferdiff-0.2.0/tests/test_testing_sdk.py +354 -0
- inferdiff-0.2.0/tests/test_v02_hardening.py +496 -0
- inferdiff-0.2.0/tests/test_v02_probes.py +945 -0
- inferdiff-0.2.0/tests/test_watch.py +292 -0
- inferdiff-0.1.0/PKG-INFO +0 -165
- inferdiff-0.1.0/README.md +0 -138
- inferdiff-0.1.0/src/inferdiff/cli.py +0 -490
- inferdiff-0.1.0/src/inferdiff/probes/__init__.py +0 -5
- inferdiff-0.1.0/src/inferdiff/redact.py +0 -355
- inferdiff-0.1.0/src/inferdiff.egg-info/PKG-INFO +0 -165
- inferdiff-0.1.0/src/inferdiff.egg-info/SOURCES.txt +0 -29
- inferdiff-0.1.0/src/inferdiff.egg-info/requires.txt +0 -6
- {inferdiff-0.1.0 → inferdiff-0.2.0}/LICENSE +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/setup.cfg +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/__main__.py +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/dialects/ollama_ndjson.py +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/dialects/openai_chat.py +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff/dialects/openai_responses.py +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff.egg-info/dependency_links.txt +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff.egg-info/entry_points.txt +0 -0
- {inferdiff-0.1.0 → inferdiff-0.2.0}/src/inferdiff.egg-info/top_level.txt +0 -0
inferdiff-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: inferdiff
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Wireshark for streaming LLMs: catch HTTP 200 silent truncations, broken tool JSON, fake SSE relays & usage drops.
|
|
5
|
+
Author: ApacheWang
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ApacheWang/inferdiff
|
|
8
|
+
Project-URL: Repository, https://github.com/ApacheWang/inferdiff
|
|
9
|
+
Project-URL: Issues, https://github.com/ApacheWang/inferdiff/issues
|
|
10
|
+
Keywords: llm,inference,sse,streaming,vllm,llama-cpp,sglang,ollama,litellm,testing
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# inferdiff
|
|
28
|
+
|
|
29
|
+
[](https://github.com/ApacheWang/inferdiff/actions/workflows/ci.yml)
|
|
30
|
+
[](https://github.com/ApacheWang/inferdiff)
|
|
31
|
+
[](https://github.com/ApacheWang/inferdiff/blob/main/pyproject.toml)
|
|
32
|
+
[](https://github.com/ApacheWang/inferdiff/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
**Wireshark & protocol bill-checker for streaming LLM APIs.**
|
|
35
|
+
|
|
36
|
+
Catch silent `HTTP 200 OK` failures — truncated tool JSON, ghost thinking starvation, buffered nonconformant SSE relays, and illusory benchmark speedups — with **zero third-party runtime dependencies** (Python 3.10+ standard library only).
|
|
37
|
+
|
|
38
|
+
[中文文档 (README.zh-CN.md)](https://github.com/ApacheWang/inferdiff/blob/main/README.zh-CN.md) · [PyPI (`inferdiff`)](https://pypi.org/project/inferdiff/) · [Releases](https://github.com/ApacheWang/inferdiff/releases)
|
|
39
|
+
|
|
40
|
+
`v0.2.0` adds a streaming proxy and dashboard, stdin auditing, CI reports, Anthropic and Gemini canaries, and optional KV and storage probes. Install from a checkout with `python -m pip install .`. See the [changelog](CHANGELOG.md).
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
## Why `inferdiff`? (`HTTP 200 OK` != Your Stream Worked)
|
|
45
|
+
|
|
46
|
+
Standard uptime monitors and latency benchmarks only check HTTP status codes and wall-clock speed. In production, streaming LLM upgrades and third-party OpenAI-compatible relays routinely return `200 OK` while silently corrupting wire contracts:
|
|
47
|
+
|
|
48
|
+
| Who Gets Burned | What Breaks Silently Under `HTTP 200 OK` | Real-World Bug Anchors | How `inferdiff` Catches It |
|
|
49
|
+
| :--- | :--- | :--- | :--- |
|
|
50
|
+
| **Agent & App Engineers** | Tool-call JSON arguments are cut off mid-string by token budgets yet reported as `completed` / `stop`, reasoning tokens starve `content` to empty, or chunk splits emit `U+FFFD` replacement chars — sending agents into retry loops. | [`llama.cpp #30773`](https://github.com/ggml-org/llama.cpp/issues/30773), [`Ollama #17274`](https://github.com/ollama/ollama/issues/17274), [`vLLM #68324`](https://github.com/vllm-project/vllm/issues/68324) | Rules `D1`, `D2` & Canary `C1`, `C2`, `C6` validate strict JSON syntax trees, UTF-8 multibyte boundaries, and terminal state honesty. |
|
|
51
|
+
| **API Relay & Gateway Users** | Proxies buffer upstream non-streaming responses and dump them as a fake SSE burst, strip trailing `include_usage` chunks, undercount tool-schema tokens, strip initial `delta.role`, or route across mixed-quantization pools. | [`LiteLLM #5803`](https://github.com/BerriAI/litellm/issues/5803), [`LiteLLM #16112`](https://github.com/BerriAI/litellm/issues/16112), [`LiteLLM #24221`](https://github.com/BerriAI/litellm/issues/24221), [vLLM Streaming Usage](https://docs.vllm.ai/en/latest/serving/online_serving/derenderer/) | `inferdiff doctor --profile relay` runs low-budget canary probes (`C1–C8`) and grades wire health from `A+` to `F`. |
|
|
52
|
+
| **AI Infra & Perf Engineers** | Engine upgrades report massive throughput/TTFT jumps because fixed-length `ignore_eos` runs stopped at `8 / 8000` tokens, prefix caches leaked across runs, or empty handshake frames gamed first-frame timers. | [`SGLang #53119`](https://github.com/sgl-project/sglang/pull/53119), [`SGLang #50443`](https://github.com/sgl-project/sglang/issues/50443), [vLLM Benchmarking CLI](https://docs.vllm.ai/en/stable/benchmarking/cli/) | Separates empty handshake `ttff_ms` from real `ttft_effective_ms` and flags short-generation & cache-pollution illusions (`D3`, `D5`). |
|
|
53
|
+
| **OSS Contributors & Release CI** | SSE chunk boundaries shift between runs, making raw `curl` logs impossible to diff by eye — while noisy log dumps get closed upstream. | [rusefi LLM Policy](https://github.com/rusefi/rusefi/wiki/LLM-policy) | Normalizes chunk jitter, pins the **exact first divergent wire frame**, and exports an airgapped `<80 KiB` HTML waterfall or a `<=25`-line redacted `curl` reproducer. |
|
|
54
|
+
|
|
55
|
+
## 5-Second Quickstart (Zero Install via `uvx` or `pip`)
|
|
56
|
+
|
|
57
|
+
Zero-install via [`uvx`](https://docs.astral.sh/uv/guides/tools/) directly from [PyPI](https://pypi.org/project/inferdiff/), or install locally with `pip` (Python 3.10+, zero third-party dependencies):
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 1. Zero-install live health check on a local engine (llama-server, vLLM, SGLang, Ollama)
|
|
61
|
+
uvx inferdiff doctor http://127.0.0.1:8080/v1 --html doctor.html
|
|
62
|
+
|
|
63
|
+
# 2. Audit an OpenAI-compatible relay API + generate shareable single-file HTML scorecard
|
|
64
|
+
OPENAI_API_KEY="$RELAY_API_KEY" uvx inferdiff doctor https://api.your-relay.example/v1 \
|
|
65
|
+
--model qwen3-32b --profile relay --html relay-report.html
|
|
66
|
+
|
|
67
|
+
# 3. Or install once from PyPI
|
|
68
|
+
pip install inferdiff
|
|
69
|
+
|
|
70
|
+
# Offline demo on bundled Case 1 (llama.cpp #30773, clone repo — no GPU or server required)
|
|
71
|
+
inferdiff diff \
|
|
72
|
+
examples/case1_responses_truncated_tool/baseline.trace.jsonl \
|
|
73
|
+
examples/case1_responses_truncated_tool/target.trace.jsonl \
|
|
74
|
+
--html case1-waterfall.html
|
|
75
|
+
|
|
76
|
+
inferdiff export \
|
|
77
|
+
examples/case1_responses_truncated_tool/baseline.trace.jsonl \
|
|
78
|
+
examples/case1_responses_truncated_tool/target.trace.jsonl \
|
|
79
|
+
--format github-issue
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
> **Auth note**: If neither `--api-key` nor `-H "Authorization: ..."` is passed, `inferdiff doctor` falls back to `OPENAI_API_KEY` from the environment and sends it to the target URL (use `https://` for production keys). Reflected secrets are scrubbed from terminal output, saved traces, JSON, and HTML exports.
|
|
83
|
+
|
|
84
|
+
## Capture Live SDK Traffic
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
inferdiff proxy --upstream https://api.openai.com --save-dir ./traces --only-breaches
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Set your OpenAI-compatible client's base URL to `http://127.0.0.1:8787/v1`. For Claude Code or a Gemini SDK, set `--upstream` to the provider's HTTPS origin and use `http://127.0.0.1:8787` as the client's base URL if it adds the versioned API path itself. Keep the credentials in your client configuration. The proxy forwards them upstream and redacts them from logs, captures, and status output.
|
|
91
|
+
|
|
92
|
+
The proxy forwards streamed bytes as they arrive and runs `D1`–`D4` when the stream ends. Open `http://127.0.0.1:8787/_inferdiff/` for recent requests, a frame timeline, findings, and redacted issue text. `/_inferdiff/status` serves the dashboard counters as JSON. `--no-ui` turns off the dashboard and event history. Omit `--only-breaches` to save passing streams too.
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
inferdiff proxy --upstream https://primary.example.com \
|
|
96
|
+
--fallback-url https://fallback.example.com --fallback-api-key env:FALLBACK_API_KEY
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
With a fallback configured, the proxy retries the request once after HTTP `429`, `502`, `503`, or `504`, or an eligible pre-response transport failure. For HTTP `200` streaming or chunked responses, it can also recover from a timeout or incomplete transport before the first body byte. Failover ends once the proxy receives body bytes or commits response headers to the client. The chosen response carries `X-Inferdiff-Upstream: primary` or `fallback`.
|
|
100
|
+
|
|
101
|
+
Scrape `http://127.0.0.1:8787/_inferdiff/metrics` for request and failover counters, findings by detector and severity, active streams, and an effective TTFT histogram. Scrapes are available by default on loopback. Set `--metrics-token env:INFERDIFF_METRICS_TOKEN` to require a Bearer token or enable authenticated scrapes on a non-loopback bind. Disable the endpoint with `--no-metrics`. Import the [Grafana dashboard](examples/grafana-inferdiff-dashboard.json) and select your Prometheus data source.
|
|
102
|
+
|
|
103
|
+
## Audit a Capture
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
inferdiff audit capture.sse --dialect openai-chat --expect-usage --strict
|
|
107
|
+
inferdiff audit - --dialect openai-chat --sarif reports/audit.sarif --junit reports/audit.xml < capture.sse
|
|
108
|
+
inferdiff audit traces/run.trace.jsonl --github-issue
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Use `-` to read SSE, NDJSON, or `.trace.jsonl` from stdin. In PowerShell, run `cmd /c "inferdiff audit - --dialect openai-chat < capture.sse"` to pass the original bytes. The JSON, SARIF 2.1.0, JUnit XML, and GitHub Issue reports redact credentials. `--html` accepts a saved trace and writes the frame waterfall. `--expect-usage` checks whether a stream carried requested usage, and `--strict` makes P1 findings exit `3`.
|
|
112
|
+
|
|
113
|
+
Traces keep observed wire frames and timing separate from server-reported token counts. Trace summaries use `unknown` for absent usage. The `.trace.jsonl` frame count measures observed protocol records.
|
|
114
|
+
|
|
115
|
+
## Single-File Offline HTML Frame Waterfall
|
|
116
|
+
|
|
117
|
+
Use `diff --html`, `audit --html` on a saved trace, `doctor --html`, or `export --format html` to write a self-contained report. The HTML and inline SVG work offline and fit within `80 KiB`.
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
> GitHub Markdown strips interactive SVG scripts; download [`case1-waterfall.html` from the `v0.1.0` Release](https://github.com/ApacheWang/inferdiff/releases/tag/v0.1.0) to hover frame timings, toggle Absolute ms / Normalized %, and click any lane segment offline.
|
|
122
|
+
|
|
123
|
+
## Canary Probe Matrix (`inferdiff doctor`)
|
|
124
|
+
|
|
125
|
+
| Probe | Target Failure Mode | Profiles | Upstream Anchor |
|
|
126
|
+
| :--- | :--- | :--- | :--- |
|
|
127
|
+
| `C1` (P0) | Truncated tool-call JSON claiming `stop`/`completed` (plus `/v1/responses` cross-check in `full`) | `quick`, `full`, `relay` | [`llama.cpp #30773`](https://github.com/ggml-org/llama.cpp/issues/30773) |
|
|
128
|
+
| `C2` (P0) | Reasoning swallows budget -> empty visible output claiming `stop` | `full`, `relay` | [`Ollama #17274`](https://github.com/ollama/ollama/issues/17274) |
|
|
129
|
+
| `C3` (P1) | `ignore_eos=true` fixed-length budget mismatch (auto-`SKIP` on HTTP 400/422) | `full` | [`SGLang #53119`](https://github.com/sgl-project/sglang/pull/53119) |
|
|
130
|
+
| `C4` (P1) | Stripped trailing empty-`choices` `include_usage` chunk or omitted tool-schema tokens | `quick`, `full`, `relay` | [`LiteLLM #16112`](https://github.com/BerriAI/litellm/issues/16112), [`#28553`](https://github.com/BerriAI/litellm/issues/28553) |
|
|
131
|
+
| `C5` (P1/P0) | Missing initial `delta.role`, omitted/invalid raw indices, or parallel tool index collision | `quick`, `full`, `relay` | [`LiteLLM #24221`](https://github.com/BerriAI/litellm/issues/24221) |
|
|
132
|
+
| `C6` (P0) | Multi-byte UTF-8 / 4-byte emoji `U+FFFD` corruption or swallowed stream tail | `quick`, `full`, `relay` | [`vLLM #68324`](https://github.com/vllm-project/vllm/issues/68324), [`#47161`](https://github.com/vllm-project/vllm/issues/47161) |
|
|
133
|
+
| `C7` (P1) | Buffered non-streaming response dumped as a fake SSE burst | `quick`, `full`, `relay` | [`LiteLLM #5803`](https://github.com/BerriAI/litellm/issues/5803) |
|
|
134
|
+
| `C8` (P2) | Randomized-prefix same-seed heterogeneous backend pool drift (advisory) | `full`, `relay` | [vLLM Benchmarking CLI](https://docs.vllm.ai/en/stable/benchmarking/cli/) |
|
|
135
|
+
| `C9` (P0) | Anthropic Messages lifecycle, dishonest `max_tokens` termination, and missing output usage | `--only C9` or `--protocol anthropic` | [Anthropic streaming messages](https://platform.claude.com/docs/en/build-with-claude/streaming) |
|
|
136
|
+
| `C10` (P0) | Gemini SSE truncation honesty, token accounting, and UTF-8 integrity in visible and thinking output | `--only C10` or `--protocol gemini` | [Gemini streaming content](https://ai.google.dev/api/generate-content) |
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
inferdiff doctor https://api.anthropic.com/v1 --model "$CLAUDE_MODEL" \
|
|
140
|
+
--protocol anthropic --anthropic-version 2023-06-01 --json
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
C9 requests a long tool argument with a 32-token budget and falls back to a long text prompt if the server rejects the tool request. It validates text, thinking, and tool input deltas. It uses `x-api-key` and falls back to `ANTHROPIC_API_KEY`. `--anthropic-version` alone also selects C9, and `--only C1,C9` runs both checks against a gateway's sibling routes. HTTP 404 or 405 on `/v1/messages` yields `SKIP`.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
inferdiff doctor https://generativelanguage.googleapis.com --model "$GEMINI_MODEL" \
|
|
147
|
+
--protocol gemini --api-key '$GEMINI_API_KEY' --save-dir ./gemini-traces
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
C10 requests a long response with a 32-token budget and checks for `MAX_TOKENS`. Gemini credentials are sent in `x-goog-api-key`, with `GEMINI_API_KEY` or `GOOGLE_API_KEY` as environment fallbacks. HTTP 404, 405, or 501 yields `SKIP`.
|
|
151
|
+
|
|
152
|
+
## Offline Trace Replay
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
inferdiff replay ./traces/run.trace.jsonl
|
|
156
|
+
inferdiff replay ./after --baseline ./before --out-json replay.json \
|
|
157
|
+
--out-sarif replay.sarif --out-junit replay.xml --out-html replay.html
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Replay runs the current detectors over saved `.trace.jsonl` files locally. With `--baseline`, it matches traces by relative path across Windows and POSIX separators, runs pair checks on matches, and reports `NEW_BREACHES`, `FIXED_BREACHES`, and `UNCHANGED`. Missing, empty, or malformed input bundles exit `1`. New P0 findings exit `2`. `--strict` also gates P1 findings with exit `3`.
|
|
161
|
+
|
|
162
|
+
`record` and raw `audit` limit captures to 32 MiB and 32,768 frames, with a 1 MiB limit per wire record. Saved traces allow 64 MiB, 32,768 frames, and 16 MiB per JSONL line. If a recording reaches its local capture or serialization budget, it exits `1` and preserves the captured prefix when possible. Offline gates reject that prefix as incomplete evidence. `replay` applies the byte and frame budgets across its inputs and accepts up to 1,024 trace files. The proxy keeps relaying bytes past its capture limit of 16 MiB decoded or 32,768 frames, and reports the capture as limited without an audit verdict. Proxy request metadata is capped at 4 MiB.
|
|
163
|
+
|
|
164
|
+
## Continuous Canary Monitoring
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
inferdiff watch --base-url https://relay.example.com/v1 --model "$MODEL" \
|
|
168
|
+
--profile relay --interval 60 --max-runs 10 --out-jsonl watch.jsonl \
|
|
169
|
+
--prom-out watch.prom --metrics-port 0 --fail-on-breach
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`watch` runs `doctor` on a schedule. Add `--webhook-url "$INFERDIFF_WEBHOOK"` to send failure and recovery notifications to a generic JSON, Feishu, or Lark webhook. `--cooldown` controls how often it repeats failure alerts. Leave out `--max-runs` for continuous monitoring.
|
|
173
|
+
|
|
174
|
+
`--prom-out` atomically replaces a Prometheus textfile after each cycle. `--metrics-port` serves the latest snapshot at `/metrics` on loopback, and port `0` selects an available port and prints the scrape URL. The snapshot includes health, grade, probe results, effective TTFT, and the last-check timestamp.
|
|
175
|
+
|
|
176
|
+
## Test Streaming Contracts with pytest
|
|
177
|
+
|
|
178
|
+
The SDK works with the standard library. Import `assert_sse_honest` for captured SSE or `assert_endpoint_honest` to run live doctor probes and check a minimum grade.
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from pathlib import Path
|
|
182
|
+
|
|
183
|
+
from inferdiff.testing import assert_sse_honest
|
|
184
|
+
|
|
185
|
+
assert_sse_honest(Path("capture.sse").read_text(encoding="utf-8"), dialect="openai-chat")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Install pytest in your test environment and opt in through `conftest.py`.
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
# conftest.py
|
|
192
|
+
pytest_plugins = ["inferdiff.pytest_plugin"]
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
# test_stream.py
|
|
197
|
+
from pathlib import Path
|
|
198
|
+
|
|
199
|
+
def test_saved_stream(assert_sse_honest):
|
|
200
|
+
capture = Path("capture.sse").read_text(encoding="utf-8")
|
|
201
|
+
assert_sse_honest(capture, dialect="openai-chat")
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The plugin also exposes `assert_endpoint_honest` as a fixture. Pass `expect_usage=True` for an SSE capture whose request asked for usage. The assertions raise `InferdiffAssertionError` with a redacted report if a check fails.
|
|
205
|
+
|
|
206
|
+
## Scaffold CI and Generate a Badge
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
inferdiff init --target github-actions --endpoint https://relay.example.com/v1 --model model-id
|
|
210
|
+
inferdiff init --target gitlab-ci --stdout
|
|
211
|
+
inferdiff init --target pre-commit
|
|
212
|
+
inferdiff doctor http://127.0.0.1:8080/v1 --json > doctor.json
|
|
213
|
+
inferdiff badge doctor.json --out inferdiff.svg --label "Wire health"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`init` writes a canary workflow, a GitLab CI include, or an offline replay hook. Set the CI secret `LLM_API_KEY` for authenticated endpoints. `--stdout` previews the generated configuration. Pass `--output` for a custom file or `--force` to replace an existing file. `badge` turns doctor summary JSON into a self-contained grade SVG and accepts `-` for stdin.
|
|
217
|
+
|
|
218
|
+
## Local HTTP 200 Fault Benchmark
|
|
219
|
+
|
|
220
|
+
Run `python benchmarks/run_fault_matrix.py` from a checkout. The local stdlib origin needs no API keys. The Windows 10 / Python 3.12 run matched **15/15 injected faults** and **5/5 healthy controls** across five dialects. Both pre-body failover cases recovered.
|
|
221
|
+
|
|
222
|
+
Across 10,000 paired SSE frames, added proxy delivery time was **318,614.6 / 593,958.4 / 607,899.9 µs** at p50 / p95 / p99. The burst saturated the proxy on this Windows loopback run, with 19,808 frames/s direct and 5,212 frames/s proxied. The delivery timings include queueing and buffering. Fresh `inferdiff --help` processes took **385.7 / 678.7 / 678.7 ms** over 15 launches. See the [full matrix and measurement method](benchmarks/RESULTS.md).
|
|
223
|
+
|
|
224
|
+
## Recording, Side-by-Side Comparison & Bundled Examples
|
|
225
|
+
|
|
226
|
+
Run the same canaries against two targets and export the side-by-side results.
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
inferdiff compare \
|
|
230
|
+
--a-url https://api.example.com/v1 --a-key '$KEY_A' --a-model model-id --a-label Baseline \
|
|
231
|
+
--b-url https://relay.example.com/v1 --b-key '$KEY_B' --b-model model-id --b-label Relay \
|
|
232
|
+
--only C1,C4,C7 --out-json compare.json --out-md compare.md --out-html compare.html
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Use `--markdown` for paste-ready stdout. The report includes per-check statuses, model and fingerprint differences, finish reasons, tool and thinking-stream differences, and B/A latency ratios. By default, latency regression requires a B/A increase of at least 50% and 20 ms on matched samples. The verdict prioritizes suspected model mismatch, then contract drift, then latency regression. The report retains all observed differences.
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Record one request or a multi-line .jsonl suite (strict RFC 9112 framing + per-frame flush)
|
|
239
|
+
inferdiff record --url http://127.0.0.1:8080/v1/responses -d request.json -o target.trace.jsonl
|
|
240
|
+
|
|
241
|
+
# Replay a specific request against two endpoints with per-target credentials
|
|
242
|
+
inferdiff compare \
|
|
243
|
+
--before-url http://127.0.0.1:8080/v1/chat/completions \
|
|
244
|
+
--after-url http://127.0.0.1:8081/v1/chat/completions \
|
|
245
|
+
--before-header "Authorization: Bearer $KEY_A" \
|
|
246
|
+
--after-header "Authorization: Bearer $KEY_B" \
|
|
247
|
+
-d request.json --save-dir ./traces --html compare.html --fail-on p1
|
|
248
|
+
|
|
249
|
+
# Additional bundled golden examples
|
|
250
|
+
inferdiff diff examples/case2_ollama_ghost_thinking_tokens/baseline.trace.jsonl \
|
|
251
|
+
examples/case2_ollama_ghost_thinking_tokens/target.trace.jsonl
|
|
252
|
+
inferdiff diff examples/case3_sglang_8_of_8000_short_gen/baseline.trace.jsonl \
|
|
253
|
+
examples/case3_sglang_8_of_8000_short_gen/target.trace.jsonl --fail-on p1
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## GitHub Action (CI Gate + HTML Waterfall Artifact)
|
|
257
|
+
|
|
258
|
+
Use `ApacheWang/inferdiff@v0.2.0` in GitHub Actions to run a live `doctor` check or offline `diff` regression gate and attach the HTML waterfall.
|
|
259
|
+
|
|
260
|
+
```yaml
|
|
261
|
+
- name: Run inferdiff wire gate
|
|
262
|
+
uses: ApacheWang/inferdiff@v0.2.0
|
|
263
|
+
with:
|
|
264
|
+
url: http://127.0.0.1:8080/v1
|
|
265
|
+
profile: full
|
|
266
|
+
strict: "true"
|
|
267
|
+
html-out: inferdiff-report.html
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Set `sarif-output` and `junit-output` in either mode to write CI reports. This example audits two saved traces.
|
|
271
|
+
|
|
272
|
+
```yaml
|
|
273
|
+
- name: Run inferdiff wire gate with CI reports
|
|
274
|
+
uses: ApacheWang/inferdiff@v0.2.0
|
|
275
|
+
with:
|
|
276
|
+
before-trace: traces/baseline.trace.jsonl
|
|
277
|
+
after-trace: traces/target.trace.jsonl
|
|
278
|
+
sarif-output: reports/inferdiff.sarif
|
|
279
|
+
junit-output: reports/inferdiff.xml
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The default `version: bundled` installs the package from the Action checkout. Use `version: ""` for the latest PyPI release or a version such as `version: "0.2.0"` to pin it. `upload-artifact` controls the HTML artifact. Upload SARIF and JUnit separately when your workflow needs them.
|
|
283
|
+
|
|
284
|
+
The CLI accepts `--out-sarif` (SARIF 2.1.0) and `--out-junit` (JUnit XML) on `doctor`, `audit`, `diff`, and `replay`. `compare` also accepts `--out-junit`.
|
|
285
|
+
|
|
286
|
+
## Wire Health Grades & Deterministic CI Exit Codes
|
|
287
|
+
|
|
288
|
+
- **Doctor grades**: `A+` (all executed probes pass with zero skips/warnings), `A` (zero P0/P1 issues, advisory P2 warning or inconclusive/skipped probe), `B` (1 P1 warning), `C` (2+ P1 warnings), `F` (any P0 silent protocol breach or transport/HTTP error).
|
|
289
|
+
|
|
290
|
+
| Exit Code | Constant | Meaning |
|
|
291
|
+
| :--- | :--- | :--- |
|
|
292
|
+
| `0` | `EXIT_OK` | Gate passed (`doctor` grades `A+` / `A` / `B` / `C` without `--strict`) |
|
|
293
|
+
| `1` | `EXIT_USAGE_OR_IO_ERROR` | CLI usage error, malformed trace schema, unreachable endpoint, or non-200 HTTP failure |
|
|
294
|
+
| `2` | `EXIT_SILENT_PROTOCOL_BREACH` | Confirmed P0 silent protocol breach (`D1`, `D2`, `D4`, or `doctor` P0 `FAIL`) |
|
|
295
|
+
| `3` | `EXIT_SEMANTIC_REGRESSION` | P1 regression (`D3`, `D5`, terminal drift, TTFT regression, `--fail-on any-diff`, or `doctor --strict` P1 warn) |
|
|
296
|
+
|
|
297
|
+
## Airgap-Safe HTML Waterfall & Privacy Defaults
|
|
298
|
+
|
|
299
|
+
- Single-file HTML5 + inline SVG reports use a hash-locked CSP (`default-src 'none'; style-src 'unsafe-inline'; script-src 'sha256-...'; img-src data:;`) with zero external scripts, fonts, or stylesheets, and adaptive folding to stay strictly under `80 KiB`.
|
|
300
|
+
- Shareable exports (`export --format github-issue|json|html`, `diff --html`, `audit --html`, `doctor --html`) omit arbitrary request bodies and raw wire payloads by default; pass `--include-body` or `--include-wire` to `export` only after reviewing your trace.
|
|
301
|
+
|
|
302
|
+
## Positioning: How `inferdiff` Complements Existing Tools
|
|
303
|
+
|
|
304
|
+
`inferdiff` is intentionally scoped as a **wire-level surgical knife** (`git diff` + protocol bill-checker for streaming frames), not an all-in-one evaluation or load-testing platform. Use it alongside — not instead of — established ecosystem tools:
|
|
305
|
+
|
|
306
|
+
| Tool Category | Great Open-Source Options | Use Them When You Need To... | Use `inferdiff` When You Need To... |
|
|
307
|
+
| :--- | :--- | :--- | :--- |
|
|
308
|
+
| **Semantic & Agent Evals** | [promptfoo](https://github.com/promptfoo/promptfoo) | Grade prompt accuracy, RAG faithfulness, or red-team safety across models after responses are assembled. | Catch **wire-level silent corruption** under `HTTP 200 OK` (truncated tool JSON, missing `arguments.done`, `U+FFFD` chunk-split leaks) before SDKs even finish assembling text. |
|
|
309
|
+
| **Load & Throughput Benchmarks** | [GuideLLM](https://github.com/vllm-project/guidellm), [LLMPerf](https://github.com/ray-project/llmperf) | Measure multi-concurrency QPS, latency percentiles, and capacity curves under sustained load. | Verify your benchmark isn't **measuring an illusion** (e.g., `8 / 8000` short generation on `ignore_eos`, empty handshake frames gaming TTFT, or unisolated prefix caches). |
|
|
310
|
+
| **Broad Engine & Relay Suites** | [ddalcu/llmprobe](https://github.com/ddalcu/llmprobe), [lmspeed-audit](https://github.com/nexmoe/lmspeed-audit) | Run comprehensive Node.js capability scorecards (GPQA/AIME evals, surface coverage, or provider fingerprinting) using built-in test banks. | Run a **zero-dep Python CLI** inside GPU containers to **record & frame-diff your own failing production payloads** across `openai-chat`, `openai-responses`, `sglang-native`, and `ollama-ndjson`, and export a `<=25`-line upstream GitHub Issue. |
|
|
311
|
+
| **Interactive Local Proxies** | [StreamLens](https://github.com/alexandrmotologa/streamlens), [ForkMind](https://github.com/Medhovarsh/forkmind) | Route local app traffic through a persistent reverse proxy and inspect conversations interactively in a Web UI. | Run **stateless CLI / CI regression gates** (`Exit 0/1/2/3`) and generate `<80 KiB` airgap-safe single-file HTML frame waterfalls without deploying a proxy. |
|
|
312
|
+
|
|
313
|
+
### Explicit Non-Goals
|
|
314
|
+
|
|
315
|
+
- **No LLM-as-a-Judge or capability leaderboards**: `inferdiff` never grades prose quality, math/coding intelligence, or jailbreak resistance. Every verdict is a deterministic function of raw wire bytes, JSON syntax trees, and monotonic frame timestamps.
|
|
316
|
+
- **No heavy runtime stack**: Core CLI and HTML/SVG waterfall rendering stay 100% Python 3.10+ standard library (`0` mandatory `pip` packages, `0` Node.js runtime, `0` external CDN requests).
|
|
317
|
+
|
|
318
|
+
## Non-Invasive KV and Storage Probes
|
|
319
|
+
|
|
320
|
+
`record` and request-mode `compare` can sample LMCache MP metrics, Mooncake Store master and client endpoints, and Linux `/proc/<pid>/io`. The probes read existing metrics before the request, at the first effective token, and at stream end. Use `--probe-lmcache`, `--probe-mooncake-master`, `--probe-mooncake-client`, or `--probe-pid` to opt in. `compare` accepts `--before-probe-*` and `--after-probe-*` for separate targets.
|
|
321
|
+
|
|
322
|
+
`D6` flags evidence of page-cache-warmed reads. `D7` flags evidence of lookup hits whose data is dropped before delivery. `D8` flags fragmented physical reads or a TTFT regression with storage evidence. These checks use telemetry stored in `inferdiff.trace.v1`, so `audit`, `diff`, and `replay` can run them offline.
|
|
323
|
+
|
|
324
|
+
## License
|
|
325
|
+
|
|
326
|
+
MIT
|