mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(proxy): register HEADROOM_WEB_SEARCH_HISTORY as a runtime-env knob
`headroom wrap` reusing a running proxy pushes only the knobs listed in `runtime_env.RUNTIME_ENV_KNOBS` to `POST /admin/runtime-env`, so `HEADROOM_WEB_SEARCH_HISTORY=0` exported in the wrap shell never reached a reused proxy. The reader already goes through `runtime_env.getenv`; this registers the knob, so wrap pushes it, `/health` reports it, and the admin route accepts it. The security-model page's allowlist table gets the row. Test: a runtime-env override of `0` disables the drop with no environment variable set, and `explicit_env` includes the knob in the wrap payload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -284,6 +284,7 @@ accept arbitrary environment variables — writes are restricted to a hardcoded
|
||||
| `HEADROOM_INTERCEPT_READ_MIN_CHARS` | ast-grep read-interception threshold |
|
||||
| `HEADROOM_VERIFY_TRUNCATION_ON_DISK` | Verify ast-grep Read truncation against disk when no client banner is found. Always returns `UNKNOWN` on Windows, where `dir_fd` / `O_NOFOLLOW` support is unavailable. |
|
||||
| `HEADROOM_VERIFY_TRUNCATION_MAX_BYTES` | Max on-disk file size (bytes) the disk-verify fallback will read |
|
||||
| `HEADROOM_WEB_SEARCH_HISTORY` | Drop `web_search_call` history from a Responses request that declares no web_search tool (default on; `0` disables) |
|
||||
|
||||
Keys outside this list are ignored, and `/admin/upstream` is read-only — there is no
|
||||
write route on the admin surface, specifically so a caller cannot redirect
|
||||
|
||||
@@ -1110,8 +1110,9 @@ def _drop_undeclared_web_search_calls(
|
||||
Mutates *payload* in place and returns the number of items dropped
|
||||
(0 = untouched). Callers skip it for a bypass request
|
||||
(``x-headroom-bypass: true``), which asked for its bytes untouched.
|
||||
Disable with ``HEADROOM_WEB_SEARCH_HISTORY=0``. Remove once the backend
|
||||
accepts such a body.
|
||||
Disable with ``HEADROOM_WEB_SEARCH_HISTORY=0`` (a registered runtime-env
|
||||
knob, so ``headroom wrap`` also pushes it to a reused proxy). Remove once
|
||||
the backend accepts such a body.
|
||||
"""
|
||||
items = payload.get("input")
|
||||
if not isinstance(items, list) or payload.get("previous_response_id"):
|
||||
|
||||
@@ -84,6 +84,12 @@ RUNTIME_ENV_KNOBS: tuple[Knob, ...] = (
|
||||
"int",
|
||||
"Max on-disk file size (bytes) the disk-verify fallback will read.",
|
||||
),
|
||||
Knob(
|
||||
"HEADROOM_WEB_SEARCH_HISTORY",
|
||||
"bool",
|
||||
"Drop web_search_call history from a Responses request that declares no "
|
||||
"web_search tool (default on; 0 disables).",
|
||||
),
|
||||
)
|
||||
|
||||
_KNOBS_BY_ENV: dict[str, Knob] = {k.env: k for k in RUNTIME_ENV_KNOBS}
|
||||
|
||||
@@ -129,6 +129,20 @@ def test_override_changes_astgrep_threshold_without_env():
|
||||
assert astgrep._min_chars_to_rewrite() == 500
|
||||
|
||||
|
||||
def test_override_disables_web_search_history_drop_without_env():
|
||||
from headroom.proxy.handlers.openai import _drop_undeclared_web_search_calls
|
||||
|
||||
def body() -> dict:
|
||||
return {"input": [{"type": "web_search_call", "id": "ws_1"}], "tools": []}
|
||||
|
||||
assert _drop_undeclared_web_search_calls(body()) == 1
|
||||
rt.set_overrides({"HEADROOM_WEB_SEARCH_HISTORY": "0"})
|
||||
assert _drop_undeclared_web_search_calls(body()) == 0
|
||||
assert rt.explicit_env({"HEADROOM_WEB_SEARCH_HISTORY": "0"}) == {
|
||||
"HEADROOM_WEB_SEARCH_HISTORY": "0"
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# /health surface + /admin/runtime-env hot-reload endpoint
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user