inferdiff 0.1.1__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.1.1/src/inferdiff.egg-info → inferdiff-0.2.0}/PKG-INFO +164 -15
- {inferdiff-0.1.1 → inferdiff-0.2.0}/README.md +161 -11
- {inferdiff-0.1.1 → inferdiff-0.2.0}/pyproject.toml +3 -3
- {inferdiff-0.1.1 → 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.1 → inferdiff-0.2.0}/src/inferdiff/canary.py +353 -51
- inferdiff-0.2.0/src/inferdiff/cli.py +940 -0
- inferdiff-0.2.0/src/inferdiff/comparison.py +558 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff/detectors.py +196 -19
- {inferdiff-0.1.1 → 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.1 → inferdiff-0.2.0}/src/inferdiff/dialects/sglang_native.py +3 -3
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff/differ.py +11 -5
- {inferdiff-0.1.1 → 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.1 → 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.1 → 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.1 → 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.1 → inferdiff-0.2.0}/src/inferdiff/waterfall.py +384 -84
- {inferdiff-0.1.1 → inferdiff-0.2.0/src/inferdiff.egg-info}/PKG-INFO +164 -15
- 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.1 → inferdiff-0.2.0}/tests/test_doctor_and_waterfall.py +2 -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.1 → 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.1/src/inferdiff/cli.py +0 -490
- inferdiff-0.1.1/src/inferdiff/probes/__init__.py +0 -5
- inferdiff-0.1.1/src/inferdiff/redact.py +0 -355
- inferdiff-0.1.1/src/inferdiff.egg-info/SOURCES.txt +0 -29
- inferdiff-0.1.1/src/inferdiff.egg-info/requires.txt +0 -6
- {inferdiff-0.1.1 → inferdiff-0.2.0}/LICENSE +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/setup.cfg +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff/__main__.py +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff/dialects/ollama_ndjson.py +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff/dialects/openai_chat.py +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff/dialects/openai_responses.py +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff.egg-info/dependency_links.txt +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff.egg-info/entry_points.txt +0 -0
- {inferdiff-0.1.1 → inferdiff-0.2.0}/src/inferdiff.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: inferdiff
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Wireshark for streaming LLMs: catch HTTP 200 silent truncations, broken tool JSON, fake SSE relays & usage drops.
|
|
5
5
|
Author: ApacheWang
|
|
6
6
|
License-Expression: MIT
|
|
@@ -12,15 +12,14 @@ Classifier: Development Status :: 4 - Beta
|
|
|
12
12
|
Classifier: Environment :: Console
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
18
19
|
Classifier: Topic :: Software Development :: Testing
|
|
19
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.10
|
|
20
21
|
Description-Content-Type: text/markdown
|
|
21
22
|
License-File: LICENSE
|
|
22
|
-
Provides-Extra: httpx
|
|
23
|
-
Requires-Dist: httpx>=0.27; extra == "httpx"
|
|
24
23
|
Provides-Extra: dev
|
|
25
24
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
26
25
|
Dynamic: license-file
|
|
@@ -28,16 +27,18 @@ Dynamic: license-file
|
|
|
28
27
|
# inferdiff
|
|
29
28
|
|
|
30
29
|
[](https://github.com/ApacheWang/inferdiff/actions/workflows/ci.yml)
|
|
31
|
-
[](https://github.com/ApacheWang/inferdiff)
|
|
32
31
|
[](https://github.com/ApacheWang/inferdiff/blob/main/pyproject.toml)
|
|
33
32
|
[](https://github.com/ApacheWang/inferdiff/blob/main/LICENSE)
|
|
34
33
|
|
|
35
34
|
**Wireshark & protocol bill-checker for streaming LLM APIs.**
|
|
36
35
|
|
|
37
|
-
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.
|
|
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).
|
|
38
37
|
|
|
39
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)
|
|
40
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
|
+
|
|
41
42
|

|
|
42
43
|
|
|
43
44
|
## Why `inferdiff`? (`HTTP 200 OK` != Your Stream Worked)
|
|
@@ -53,14 +54,14 @@ Standard uptime monitors and latency benchmarks only check HTTP status codes and
|
|
|
53
54
|
|
|
54
55
|
## 5-Second Quickstart (Zero Install via `uvx` or `pip`)
|
|
55
56
|
|
|
56
|
-
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.
|
|
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):
|
|
57
58
|
|
|
58
59
|
```bash
|
|
59
60
|
# 1. Zero-install live health check on a local engine (llama-server, vLLM, SGLang, Ollama)
|
|
60
61
|
uvx inferdiff doctor http://127.0.0.1:8080/v1 --html doctor.html
|
|
61
62
|
|
|
62
63
|
# 2. Audit an OpenAI-compatible relay API + generate shareable single-file HTML scorecard
|
|
63
|
-
OPENAI_API_KEY=
|
|
64
|
+
OPENAI_API_KEY="$RELAY_API_KEY" uvx inferdiff doctor https://api.your-relay.example/v1 \
|
|
64
65
|
--model qwen3-32b --profile relay --html relay-report.html
|
|
65
66
|
|
|
66
67
|
# 3. Or install once from PyPI
|
|
@@ -80,9 +81,40 @@ inferdiff export \
|
|
|
80
81
|
|
|
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.
|
|
82
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
|
+
|
|
83
115
|
## Single-File Offline HTML Frame Waterfall
|
|
84
116
|
|
|
85
|
-
|
|
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`.
|
|
86
118
|
|
|
87
119
|

|
|
88
120
|
|
|
@@ -100,14 +132,113 @@ Every `diff --html`, `audit --html`, `doctor --html`, and `export --format html`
|
|
|
100
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) |
|
|
101
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) |
|
|
102
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).
|
|
103
223
|
|
|
104
224
|
## Recording, Side-by-Side Comparison & Bundled Examples
|
|
105
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
|
+
|
|
106
237
|
```bash
|
|
107
238
|
# Record one request or a multi-line .jsonl suite (strict RFC 9112 framing + per-frame flush)
|
|
108
239
|
inferdiff record --url http://127.0.0.1:8080/v1/responses -d request.json -o target.trace.jsonl
|
|
109
240
|
|
|
110
|
-
#
|
|
241
|
+
# Replay a specific request against two endpoints with per-target credentials
|
|
111
242
|
inferdiff compare \
|
|
112
243
|
--before-url http://127.0.0.1:8080/v1/chat/completions \
|
|
113
244
|
--after-url http://127.0.0.1:8081/v1/chat/completions \
|
|
@@ -124,11 +255,11 @@ inferdiff diff examples/case3_sglang_8_of_8000_short_gen/baseline.trace.jsonl \
|
|
|
124
255
|
|
|
125
256
|
## GitHub Action (CI Gate + HTML Waterfall Artifact)
|
|
126
257
|
|
|
127
|
-
Use `ApacheWang/inferdiff@v0.
|
|
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.
|
|
128
259
|
|
|
129
260
|
```yaml
|
|
130
261
|
- name: Run inferdiff wire gate
|
|
131
|
-
uses: ApacheWang/inferdiff@v0.
|
|
262
|
+
uses: ApacheWang/inferdiff@v0.2.0
|
|
132
263
|
with:
|
|
133
264
|
url: http://127.0.0.1:8080/v1
|
|
134
265
|
profile: full
|
|
@@ -136,6 +267,22 @@ Use `ApacheWang/inferdiff@v0.1.1` directly in GitHub Actions to run a live `doct
|
|
|
136
267
|
html-out: inferdiff-report.html
|
|
137
268
|
```
|
|
138
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
|
+
|
|
139
286
|
## Wire Health Grades & Deterministic CI Exit Codes
|
|
140
287
|
|
|
141
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).
|
|
@@ -166,11 +313,13 @@ Use `ApacheWang/inferdiff@v0.1.1` directly in GitHub Actions to run a live `doct
|
|
|
166
313
|
### Explicit Non-Goals
|
|
167
314
|
|
|
168
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.
|
|
169
|
-
- **No heavy runtime stack**: Core CLI and HTML/SVG waterfall rendering stay 100% Python 3.
|
|
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
|
|
170
319
|
|
|
171
|
-
|
|
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.
|
|
172
321
|
|
|
173
|
-
`
|
|
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.
|
|
174
323
|
|
|
175
324
|
## License
|
|
176
325
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# inferdiff
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ApacheWang/inferdiff/actions/workflows/ci.yml)
|
|
4
|
-
[](https://github.com/ApacheWang/inferdiff)
|
|
5
5
|
[](https://github.com/ApacheWang/inferdiff/blob/main/pyproject.toml)
|
|
6
6
|
[](https://github.com/ApacheWang/inferdiff/blob/main/LICENSE)
|
|
7
7
|
|
|
8
8
|
**Wireshark & protocol bill-checker for streaming LLM APIs.**
|
|
9
9
|
|
|
10
|
-
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
|
+
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).
|
|
11
11
|
|
|
12
12
|
[中文文档 (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)
|
|
13
13
|
|
|
14
|
+
`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).
|
|
15
|
+
|
|
14
16
|

|
|
15
17
|
|
|
16
18
|
## Why `inferdiff`? (`HTTP 200 OK` != Your Stream Worked)
|
|
@@ -26,14 +28,14 @@ Standard uptime monitors and latency benchmarks only check HTTP status codes and
|
|
|
26
28
|
|
|
27
29
|
## 5-Second Quickstart (Zero Install via `uvx` or `pip`)
|
|
28
30
|
|
|
29
|
-
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.
|
|
31
|
+
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):
|
|
30
32
|
|
|
31
33
|
```bash
|
|
32
34
|
# 1. Zero-install live health check on a local engine (llama-server, vLLM, SGLang, Ollama)
|
|
33
35
|
uvx inferdiff doctor http://127.0.0.1:8080/v1 --html doctor.html
|
|
34
36
|
|
|
35
37
|
# 2. Audit an OpenAI-compatible relay API + generate shareable single-file HTML scorecard
|
|
36
|
-
OPENAI_API_KEY=
|
|
38
|
+
OPENAI_API_KEY="$RELAY_API_KEY" uvx inferdiff doctor https://api.your-relay.example/v1 \
|
|
37
39
|
--model qwen3-32b --profile relay --html relay-report.html
|
|
38
40
|
|
|
39
41
|
# 3. Or install once from PyPI
|
|
@@ -53,9 +55,40 @@ inferdiff export \
|
|
|
53
55
|
|
|
54
56
|
> **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.
|
|
55
57
|
|
|
58
|
+
## Capture Live SDK Traffic
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
inferdiff proxy --upstream https://api.openai.com --save-dir ./traces --only-breaches
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
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.
|
|
65
|
+
|
|
66
|
+
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.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
inferdiff proxy --upstream https://primary.example.com \
|
|
70
|
+
--fallback-url https://fallback.example.com --fallback-api-key env:FALLBACK_API_KEY
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
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`.
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
## Audit a Capture
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
inferdiff audit capture.sse --dialect openai-chat --expect-usage --strict
|
|
81
|
+
inferdiff audit - --dialect openai-chat --sarif reports/audit.sarif --junit reports/audit.xml < capture.sse
|
|
82
|
+
inferdiff audit traces/run.trace.jsonl --github-issue
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
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`.
|
|
86
|
+
|
|
87
|
+
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.
|
|
88
|
+
|
|
56
89
|
## Single-File Offline HTML Frame Waterfall
|
|
57
90
|
|
|
58
|
-
|
|
91
|
+
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`.
|
|
59
92
|
|
|
60
93
|

|
|
61
94
|
|
|
@@ -73,14 +106,113 @@ Every `diff --html`, `audit --html`, `doctor --html`, and `export --format html`
|
|
|
73
106
|
| `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) |
|
|
74
107
|
| `C7` (P1) | Buffered non-streaming response dumped as a fake SSE burst | `quick`, `full`, `relay` | [`LiteLLM #5803`](https://github.com/BerriAI/litellm/issues/5803) |
|
|
75
108
|
| `C8` (P2) | Randomized-prefix same-seed heterogeneous backend pool drift (advisory) | `full`, `relay` | [vLLM Benchmarking CLI](https://docs.vllm.ai/en/stable/benchmarking/cli/) |
|
|
109
|
+
| `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) |
|
|
110
|
+
| `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) |
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
inferdiff doctor https://api.anthropic.com/v1 --model "$CLAUDE_MODEL" \
|
|
114
|
+
--protocol anthropic --anthropic-version 2023-06-01 --json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
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`.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
inferdiff doctor https://generativelanguage.googleapis.com --model "$GEMINI_MODEL" \
|
|
121
|
+
--protocol gemini --api-key '$GEMINI_API_KEY' --save-dir ./gemini-traces
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
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`.
|
|
125
|
+
|
|
126
|
+
## Offline Trace Replay
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
inferdiff replay ./traces/run.trace.jsonl
|
|
130
|
+
inferdiff replay ./after --baseline ./before --out-json replay.json \
|
|
131
|
+
--out-sarif replay.sarif --out-junit replay.xml --out-html replay.html
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
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`.
|
|
135
|
+
|
|
136
|
+
`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.
|
|
137
|
+
|
|
138
|
+
## Continuous Canary Monitoring
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
inferdiff watch --base-url https://relay.example.com/v1 --model "$MODEL" \
|
|
142
|
+
--profile relay --interval 60 --max-runs 10 --out-jsonl watch.jsonl \
|
|
143
|
+
--prom-out watch.prom --metrics-port 0 --fail-on-breach
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`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.
|
|
147
|
+
|
|
148
|
+
`--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.
|
|
149
|
+
|
|
150
|
+
## Test Streaming Contracts with pytest
|
|
151
|
+
|
|
152
|
+
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.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from pathlib import Path
|
|
156
|
+
|
|
157
|
+
from inferdiff.testing import assert_sse_honest
|
|
158
|
+
|
|
159
|
+
assert_sse_honest(Path("capture.sse").read_text(encoding="utf-8"), dialect="openai-chat")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Install pytest in your test environment and opt in through `conftest.py`.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# conftest.py
|
|
166
|
+
pytest_plugins = ["inferdiff.pytest_plugin"]
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
# test_stream.py
|
|
171
|
+
from pathlib import Path
|
|
172
|
+
|
|
173
|
+
def test_saved_stream(assert_sse_honest):
|
|
174
|
+
capture = Path("capture.sse").read_text(encoding="utf-8")
|
|
175
|
+
assert_sse_honest(capture, dialect="openai-chat")
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
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.
|
|
179
|
+
|
|
180
|
+
## Scaffold CI and Generate a Badge
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
inferdiff init --target github-actions --endpoint https://relay.example.com/v1 --model model-id
|
|
184
|
+
inferdiff init --target gitlab-ci --stdout
|
|
185
|
+
inferdiff init --target pre-commit
|
|
186
|
+
inferdiff doctor http://127.0.0.1:8080/v1 --json > doctor.json
|
|
187
|
+
inferdiff badge doctor.json --out inferdiff.svg --label "Wire health"
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`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.
|
|
191
|
+
|
|
192
|
+
## Local HTTP 200 Fault Benchmark
|
|
193
|
+
|
|
194
|
+
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.
|
|
195
|
+
|
|
196
|
+
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).
|
|
76
197
|
|
|
77
198
|
## Recording, Side-by-Side Comparison & Bundled Examples
|
|
78
199
|
|
|
200
|
+
Run the same canaries against two targets and export the side-by-side results.
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
inferdiff compare \
|
|
204
|
+
--a-url https://api.example.com/v1 --a-key '$KEY_A' --a-model model-id --a-label Baseline \
|
|
205
|
+
--b-url https://relay.example.com/v1 --b-key '$KEY_B' --b-model model-id --b-label Relay \
|
|
206
|
+
--only C1,C4,C7 --out-json compare.json --out-md compare.md --out-html compare.html
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
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.
|
|
210
|
+
|
|
79
211
|
```bash
|
|
80
212
|
# Record one request or a multi-line .jsonl suite (strict RFC 9112 framing + per-frame flush)
|
|
81
213
|
inferdiff record --url http://127.0.0.1:8080/v1/responses -d request.json -o target.trace.jsonl
|
|
82
214
|
|
|
83
|
-
#
|
|
215
|
+
# Replay a specific request against two endpoints with per-target credentials
|
|
84
216
|
inferdiff compare \
|
|
85
217
|
--before-url http://127.0.0.1:8080/v1/chat/completions \
|
|
86
218
|
--after-url http://127.0.0.1:8081/v1/chat/completions \
|
|
@@ -97,11 +229,11 @@ inferdiff diff examples/case3_sglang_8_of_8000_short_gen/baseline.trace.jsonl \
|
|
|
97
229
|
|
|
98
230
|
## GitHub Action (CI Gate + HTML Waterfall Artifact)
|
|
99
231
|
|
|
100
|
-
Use `ApacheWang/inferdiff@v0.
|
|
232
|
+
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.
|
|
101
233
|
|
|
102
234
|
```yaml
|
|
103
235
|
- name: Run inferdiff wire gate
|
|
104
|
-
uses: ApacheWang/inferdiff@v0.
|
|
236
|
+
uses: ApacheWang/inferdiff@v0.2.0
|
|
105
237
|
with:
|
|
106
238
|
url: http://127.0.0.1:8080/v1
|
|
107
239
|
profile: full
|
|
@@ -109,6 +241,22 @@ Use `ApacheWang/inferdiff@v0.1.1` directly in GitHub Actions to run a live `doct
|
|
|
109
241
|
html-out: inferdiff-report.html
|
|
110
242
|
```
|
|
111
243
|
|
|
244
|
+
Set `sarif-output` and `junit-output` in either mode to write CI reports. This example audits two saved traces.
|
|
245
|
+
|
|
246
|
+
```yaml
|
|
247
|
+
- name: Run inferdiff wire gate with CI reports
|
|
248
|
+
uses: ApacheWang/inferdiff@v0.2.0
|
|
249
|
+
with:
|
|
250
|
+
before-trace: traces/baseline.trace.jsonl
|
|
251
|
+
after-trace: traces/target.trace.jsonl
|
|
252
|
+
sarif-output: reports/inferdiff.sarif
|
|
253
|
+
junit-output: reports/inferdiff.xml
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
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.
|
|
257
|
+
|
|
258
|
+
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`.
|
|
259
|
+
|
|
112
260
|
## Wire Health Grades & Deterministic CI Exit Codes
|
|
113
261
|
|
|
114
262
|
- **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).
|
|
@@ -139,11 +287,13 @@ Use `ApacheWang/inferdiff@v0.1.1` directly in GitHub Actions to run a live `doct
|
|
|
139
287
|
### Explicit Non-Goals
|
|
140
288
|
|
|
141
289
|
- **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.
|
|
142
|
-
- **No heavy runtime stack**: Core CLI and HTML/SVG waterfall rendering stay 100% Python 3.
|
|
290
|
+
- **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).
|
|
291
|
+
|
|
292
|
+
## Non-Invasive KV and Storage Probes
|
|
143
293
|
|
|
144
|
-
|
|
294
|
+
`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.
|
|
145
295
|
|
|
146
|
-
`
|
|
296
|
+
`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.
|
|
147
297
|
|
|
148
298
|
## License
|
|
149
299
|
|
|
@@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "inferdiff"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Wireshark for streaming LLMs: catch HTTP 200 silent truncations, broken tool JSON, fake SSE relays & usage drops."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
11
|
-
requires-python = ">=3.
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
12
|
dependencies = []
|
|
13
13
|
authors = [
|
|
14
14
|
{ name = "ApacheWang" },
|
|
@@ -19,6 +19,7 @@ classifiers = [
|
|
|
19
19
|
"Environment :: Console",
|
|
20
20
|
"Intended Audience :: Developers",
|
|
21
21
|
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
22
23
|
"Programming Language :: Python :: 3.11",
|
|
23
24
|
"Programming Language :: Python :: 3.12",
|
|
24
25
|
"Programming Language :: Python :: 3.13",
|
|
@@ -26,7 +27,6 @@ classifiers = [
|
|
|
26
27
|
]
|
|
27
28
|
|
|
28
29
|
[project.optional-dependencies]
|
|
29
|
-
httpx = ["httpx>=0.27"]
|
|
30
30
|
dev = ["pytest>=8.0"]
|
|
31
31
|
|
|
32
32
|
[project.scripts]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Threaded HTTP listener that closes active sockets before joining handlers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import http.server
|
|
6
|
+
import socket
|
|
7
|
+
import threading
|
|
8
|
+
from contextlib import contextmanager, suppress
|
|
9
|
+
from typing import Iterator
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ManagedHTTPServer(http.server.ThreadingHTTPServer):
|
|
13
|
+
daemon_threads = False
|
|
14
|
+
|
|
15
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
16
|
+
self._connections: set[socket.socket] = set()
|
|
17
|
+
self._connections_lock = threading.Lock()
|
|
18
|
+
self._closing = False
|
|
19
|
+
super().__init__(*args, **kwargs)
|
|
20
|
+
|
|
21
|
+
def _track(self, connection: socket.socket) -> None:
|
|
22
|
+
with self._connections_lock:
|
|
23
|
+
if self._closing:
|
|
24
|
+
raise ConnectionAbortedError("HTTP listener is closing")
|
|
25
|
+
self._connections.add(connection)
|
|
26
|
+
|
|
27
|
+
def _untrack(self, connection: socket.socket) -> None:
|
|
28
|
+
with self._connections_lock:
|
|
29
|
+
self._connections.discard(connection)
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def closing(self) -> bool:
|
|
33
|
+
with self._connections_lock:
|
|
34
|
+
return self._closing
|
|
35
|
+
|
|
36
|
+
@contextmanager
|
|
37
|
+
def track_upstream(self, connection: socket.socket) -> Iterator[None]:
|
|
38
|
+
self._track(connection)
|
|
39
|
+
try:
|
|
40
|
+
yield
|
|
41
|
+
finally:
|
|
42
|
+
self._untrack(connection)
|
|
43
|
+
|
|
44
|
+
def process_request(self, request, client_address) -> None:
|
|
45
|
+
self._track(request)
|
|
46
|
+
super().process_request(request, client_address)
|
|
47
|
+
|
|
48
|
+
def shutdown_request(self, request) -> None:
|
|
49
|
+
try:
|
|
50
|
+
super().shutdown_request(request)
|
|
51
|
+
finally:
|
|
52
|
+
self._untrack(request)
|
|
53
|
+
|
|
54
|
+
def server_close(self) -> None:
|
|
55
|
+
with self._connections_lock:
|
|
56
|
+
self._closing = True
|
|
57
|
+
connections = tuple(self._connections)
|
|
58
|
+
for connection in connections:
|
|
59
|
+
with suppress(OSError):
|
|
60
|
+
connection.shutdown(socket.SHUT_RDWR)
|
|
61
|
+
super().server_close()
|