fix(router): log the ONNX fallbacks at info instead of warning (#4535)

<!-- maintainer-current-main -->
## Maintainer latest-main checkpoint
Published `fe40ae66e3d0dd9e7df00be81716c42370139004` incorporates
upstream main `e4a60ed72f6ef5b28569f8bfbe2163cfda32c948`. 23
ORT/dylib/logging/Gemini tests pass; Ruff/format/diff pass. Main sync is
clean; expected-fallback source changes remain only the two INFO log
levels. Shared Gemini request-fixture repair is test-only. No new code
finding.

The inherited main shard-2 failure was confirmed in actual hosted logs
and locally (four Gemini failures). This head carries the maintainer
fixture repair: real ASGI Request/JSON bytes replace an unused
body-reader mock. All six test-function ASTs/assertions are preserved;
all 10 Gemini cases pass. Contributor production logic was not rewritten
by the sync/fixture follow-up. Earlier runtime captures retain their
original commit/platform scope. Fresh exact-head hosted qualification is
requested; nothing merged by this review.
<!-- /maintainer-current-main -->

## Description



A plain `pip install headroom-ai` has no ONNX Runtime (it comes with
`[proxy]`), and the pure-Python detector is the supported path there.
The first `compress()` call still logged "Native content detection
requires ONNX Runtime 1.24+; using pure-Python detection for this
process" as a WARNING. Every library user sees it on first import; both
coding agents in our sandbox runs saw it, and one spent a step
investigating it before continuing.


## Type of Change



- [x] Bug fix (non-breaking change that fixes an issue)



## Changes Made



- `headroom/_ort.py`: the sibling "onnxruntime x.y exposes an older C
API than Rust detection requires" message drops to INFO as well. It
fires on Intel macOS, where the `proxy` extra pins `onnxruntime <1.24`
by design (`docs/installation.mdx`: Rust ML detection stays disabled
there), so a supported `[proxy]` install warned on first `compress()`
too. Its test now asserts the level.


- `headroom/transforms/content_router.py`: `logger.warning` to
`logger.info` for the ORT-compat fallback, with a comment on why. The
existing circuit breaker (`_detect_native_unhealthy`) already makes it
fire once per process; unchanged.
-
`tests/test_transforms/test_ort_dylib.py::test_content_router_bypasses_native_detector_for_incompatible_ort`:
now captures at INFO, asserts the record's level is INFO and that a
second call logs nothing.


## Testing



- [x] Unit tests: the test fails before the fix (`assert 30 == 20`) and
passes after; `tests/test_transforms/test_ort_dylib.py` 10 passed.
- [x] `ruff check` / `ruff format --check`



### Test Output



```text

pytest tests/test_transforms/test_ort_dylib.py: 10 passed (fails before the fix: assert 30 == 20)

source build, default logging: 20031 -> 95 FATAL kept: True  (no fallback line on stderr)

source build, INFO enabled: INFO headroom.transforms.content_router: Native content detection requires ONNX Runtime 1.24+; using pure-Python detection for this process.

```



## Real Behavior Proof



- Environment: macOS arm64, Python 3.12, clean venv with the published
0.42.0 wheel (no onnxruntime).
- Exact command / steps: `HEADROOM_OFFLINE=1 python -c "from headroom
import compress; ..."` on a 3,000-line log.
- Observed result: the warning line on stderr on first import, then
`20031 -> 95`.
- After-fix, this branch built from source (`uv pip install -e .` with
maturin, fresh venv with tiktoken, pydantic, filelock,
opentelemetry-api; no onnxruntime):
  ```text

headroom from /Users/tejas/headroom-wt-onnx-info/headroom/__init__.py
  20031 -> 95 FATAL kept: True

  ```

No fallback line on stderr at default logging. With
`logging.basicConfig(level=INFO)` the same run prints
`INFO headroom.transforms.content_router: Native content detection
requires ONNX Runtime 1.24+; using pure-Python detection for this
process.` once.
- Not tested: the native (ORT present) path, which this change does not
touch.


## Runtime Rollout Safety



- Rollout-managed feature(s): none; two log records change level from
WARNING to INFO, no behaviour change
- Minimum rollout channel: stable (ships with the next release)

- Stable/default behavior changed: only log level; detection and
compression paths are untouched
- Kill switch / disable path: not needed; `HEADROOM_LOG_LEVEL`-style
logger config still surfaces the line at INFO
- Unsafe override required: no

- Qualification impact: none

- Rollback path: revert the commit



## Review Readiness



- [x] I have performed a self-review

- [x] This PR is ready for human review



🤖 Generated with [Claude Code](https://claude.com/claude-code)





## Maintainer post-merge revisit: main e9331b6b

Published `6d9b9a52ccb939fd6c404c1debe955ecda3af3a9` includes upstream
main `e9331b6b963b5b6554f45943abed2366aaa25ea6`. 13 ORT
runtime/dylib/logging tests passed. Clean main sync; the source change
remains limited to expected fallback log levels, preserving fallback
behavior and once-per-process behavior. Author source-built default/INFO
evidence and latest discussion reconsidered; no new finding.
Touched-file Ruff/format and whitespace checks pass. Contributor runtime
logic was not rewritten. Scoped Windows tests use the existing
development native extension; no fresh native build or installed-agent
qualification is claimed. Hosted CI must finish on this exact head
before reapproval. Nothing merged.


### Maintainer current-main requalification

Exact head `7b7b3a1624c3e644f67b2ad9707c7e222ed2771c`, upstream main
`ecbaf86d78cf52d185fbffa306157b9a4cc1b906`.

Mechanically updated against upstream/main
ecbaf86d78 and re-reviewed the two
expected ONNX-unavailable/older-API fallback records. Only severity
changes to INFO; fallback behavior and once-per-process suppression
remain intact. The test-only conflict retains main's two-chunk ASGI
request helper and all memory assertions. No contributor production
logic was rewritten.

All 23 ORT/logging/Gemini tests pass; Ruff0.17.3 lint/format and
whitespace checks pass. The author's source-built no-ORT default/INFO
after-fix replay and its macOS scope were read and remain applicable; no
new source-built runtime replay is claimed here. Local execution used
the existing native extension. Formal approval awaits exact-head hosted
qualification; maintainers handle those checks. Nothing merged.


Exact-head hosted checks are being handled by maintainers. No new
finding in the reviewed scope; formal approval awaits exact-head hosted
qualification; nothing merged.

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
Tejas Chopra
2026-11-05 10:39:25 -06:00
committed by GitHub
co-authored by Claude Fable 5.1 JerrettDavis
parent 81fa4bdda6
commit db30d82dff
3 changed files with 25 additions and 4 deletions
+4 -1
View File
@@ -138,7 +138,10 @@ def _resolve_and_pin() -> str | None:
installed = _installed_ort_version()
if installed is not None and installed < _MIN_RUST_ORT_API_VERSION:
logger.warning(
# By design on Intel macOS, where the proxy extra pins onnxruntime
# <1.24 (no newer x86_64 wheels): Python detection is the supported
# path there, so this is information, not a warning.
logger.info(
"onnxruntime %d.%d exposes an older C API than Rust detection "
"requires (1.24+); leaving %s unset and using Python detection",
*installed,
+5 -1
View File
@@ -1350,8 +1350,12 @@ def _detect_content(content: str) -> DetectionResult:
from headroom._ort import rust_ort_runtime_compatible
if not rust_ort_runtime_compatible():
# Expected on every install without the proxy extra's ONNX Runtime
# (plain ``pip install headroom-ai``): the pure-Python detector is the
# supported path there, so this is information, not a warning. The
# circuit breaker above makes it fire once per process.
_detect_native_unhealthy = True
logger.warning(
logger.info(
"Native content detection requires ONNX Runtime 1.24+; "
"using pure-Python detection for this process."
)
+16 -2
View File
@@ -11,6 +11,7 @@ monkeypatched so every branch runs on any CI OS.
from __future__ import annotations
import json
import logging
import os
import subprocess
import sys
@@ -86,10 +87,14 @@ def test_incompatible_package_is_not_pinned(monkeypatch, tmp_path, caplog):
capi.mkdir(parents=True)
(capi / "libonnxruntime.so.1.23.2").write_bytes(b"old")
_fake_spec_for(monkeypatch, pkg)
caplog.set_level(logging.INFO, logger=_ort.logger.name)
assert _ort.ensure_ort_dylib_pinned() is None
assert not _ort.rust_ort_runtime_compatible()
assert "older C API" in caplog.text
older = [r for r in caplog.records if "older C API" in r.getMessage()]
assert len(older) == 1
# Supported configuration (Intel macOS pins onnxruntime <1.24): not a warning.
assert older[0].levelno == logging.INFO
def test_content_router_bypasses_native_detector_for_incompatible_ort(monkeypatch, caplog):
@@ -98,12 +103,21 @@ def test_content_router_bypasses_native_detector_for_incompatible_ort(monkeypatc
monkeypatch.setenv("HEADROOM_DETECT_BACKEND", "rust")
monkeypatch.setattr(_ort, "rust_ort_runtime_compatible", lambda: False)
monkeypatch.setattr(router, "_detect_native_unhealthy", False)
caplog.set_level(logging.INFO, logger=router.logger.name)
result = router._detect_content('{"safe": true}')
assert result.content_type.value.startswith("json")
assert router._detect_native_unhealthy is True
assert "requires ONNX Runtime 1.24+" in caplog.text
fallback = [r for r in caplog.records if "requires ONNX Runtime 1.24+" in r.getMessage()]
assert len(fallback) == 1
# A base install has no ONNX Runtime by design; the fallback is the
# supported path there, so it must not surface as a warning on first import.
assert fallback[0].levelno == logging.INFO
caplog.clear()
router._detect_content('{"safe": true}')
assert "requires ONNX Runtime 1.24+" not in caplog.text
def test_pins_to_package_capi_dll(monkeypatch, tmp_path):