mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(proxy): accept HEADROOM_MEMORY_INJECTION_MODE=tool
memory_decision.py documents and handles mode_name "tool" (skip reason mode_tool), but resolve_memory_injection_mode only accepted live_zone_tail and disabled, so get_memory_injection_mode() raised ValueError on every request when the value was set. Accept "tool" and list it in the configuration docs. Fixes #4391 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e995eb9f1d
commit
62ec86b5b2
@@ -383,7 +383,7 @@ headroom proxy --learn --min-evidence 3
|
||||
| `HEADROOM_TOIN_PATH` | Override TOIN telemetry file location. Always wins when set. | derived from `${HEADROOM_WORKSPACE_DIR}` |
|
||||
| `HEADROOM_SUBSCRIPTION_STATE_PATH` | Override subscription tracker state file. Always wins when set. | derived from `${HEADROOM_WORKSPACE_DIR}` |
|
||||
| `HEADROOM_PERIODIC_TOIN_STATS` | Controls periodic TOIN stats logging in long-lived proxy workers. Set to `0`, `false`, `off`, or `no` to disable the 5-minute stats loop without disabling TOIN learning or request-time feedback. | `true` |
|
||||
| `HEADROOM_MEMORY_INJECTION_MODE` | Memory-context routing mode: `live_zone_tail` (default) or `disabled`. The legacy `system_prompt` mode was retired by PR-A2; supplying it raises. | `live_zone_tail` |
|
||||
| `HEADROOM_MEMORY_INJECTION_MODE` | Memory-context routing mode: `live_zone_tail` (default), `disabled`, or `tool` (auto-injection off; the agent calls memory tools explicitly). The legacy `system_prompt` mode was retired by PR-A2; supplying it raises. | `live_zone_tail` |
|
||||
| `HEADROOM_PROXY_PYTHON_FORWARDER_MODE` | Python forwarder serialization mode. `byte_faithful` (default) forwards original request bytes verbatim when no transform mutated the body and re-serializes canonically only when needed — keeps Anthropic prompt-cache hit-rate intact. `legacy_json_kwarg` is an explicit operator opt-in for emergency rollback to the historical `httpx ... json=body` behavior. NOT a fallback — only flip on explicit operator decision. | `byte_faithful` |
|
||||
| `HEADROOM_STRIP_INTERNAL_HEADERS` | Python proxy: whether to strip internal `x-headroom-*` request headers (e.g. `x-headroom-bypass`, `x-headroom-mode`, `x-headroom-user-id`, `x-headroom-stack`, `x-headroom-base-url`) before every upstream forwarder call (PR-A5, fixes P5-49). `enabled` (default) stops fingerprinting / leakage. `disabled` is an explicit operator opt-in for diagnostic shadow tracing — NOT a fallback. Inbound reads of these headers (bypass gating, memory user-id resolution) are unaffected because they read `request.headers` directly. | `enabled` |
|
||||
| `HEADROOM_PROXY_STRIP_INTERNAL_HEADERS` | Rust proxy: same policy as `HEADROOM_STRIP_INTERNAL_HEADERS` but for the Rust transparent proxy. Stripping happens inside `build_forward_request_headers` so both HTTP and WebSocket upstream calls are gated by one flag. `enabled` default; `disabled` operator opt-in for diagnostic shadow tracing. Response-side `X-Headroom-*` injection (e.g. `x-headroom-tokens-saved`) is unrelated and stays. | `enabled` |
|
||||
|
||||
@@ -250,6 +250,8 @@ def capture_codex_wire_debug(
|
||||
# prefix) is never mutated.
|
||||
# - "disabled": Memory context lookup is skipped entirely; the request
|
||||
# forwards untouched.
|
||||
# - "tool": Auto-injection is off; the agent calls memory tools explicitly
|
||||
# (skip reason ``mode_tool`` in memory_decision.py).
|
||||
#
|
||||
# Configurable via HEADROOM_MEMORY_INJECTION_MODE env var. There is no
|
||||
# "system_prompt" option — that path is permanently retired by I2 (cache hot
|
||||
|
||||
@@ -5,8 +5,8 @@ from __future__ import annotations
|
||||
from typing import Literal, cast
|
||||
|
||||
MEMORY_INJECTION_MODE_ENV = "HEADROOM_MEMORY_INJECTION_MODE"
|
||||
MEMORY_INJECTION_MODE_DEFAULT: Literal["live_zone_tail", "disabled"] = "live_zone_tail"
|
||||
MemoryInjectionMode = Literal["live_zone_tail", "disabled"]
|
||||
MEMORY_INJECTION_MODE_DEFAULT: Literal["live_zone_tail", "disabled", "tool"] = "live_zone_tail"
|
||||
MemoryInjectionMode = Literal["live_zone_tail", "disabled", "tool"]
|
||||
|
||||
|
||||
def resolve_memory_injection_mode(raw: str | None) -> MemoryInjectionMode:
|
||||
@@ -14,9 +14,9 @@ def resolve_memory_injection_mode(raw: str | None) -> MemoryInjectionMode:
|
||||
normalized = (raw or "").strip().lower()
|
||||
if not normalized:
|
||||
return MEMORY_INJECTION_MODE_DEFAULT
|
||||
if normalized in ("live_zone_tail", "disabled"):
|
||||
if normalized in ("live_zone_tail", "disabled", "tool"):
|
||||
return cast(MemoryInjectionMode, normalized)
|
||||
raise ValueError(
|
||||
f"Invalid {MEMORY_INJECTION_MODE_ENV}={normalized!r}; "
|
||||
"expected 'live_zone_tail' or 'disabled'"
|
||||
"expected 'live_zone_tail', 'disabled' or 'tool'"
|
||||
)
|
||||
|
||||
@@ -17,6 +17,15 @@ def test_resolve_memory_injection_mode_defaults_for_missing_value() -> None:
|
||||
def test_resolve_memory_injection_mode_accepts_known_values_case_insensitively() -> None:
|
||||
assert resolve_memory_injection_mode("live_zone_tail") == "live_zone_tail"
|
||||
assert resolve_memory_injection_mode(" DISABLED ") == "disabled"
|
||||
assert resolve_memory_injection_mode(" Tool ") == "tool"
|
||||
|
||||
|
||||
def test_get_memory_injection_mode_accepts_tool_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
# Documented in memory_decision.py (mode_tool); must not raise per request.
|
||||
from headroom.proxy.helpers import get_memory_injection_mode
|
||||
|
||||
monkeypatch.setenv("HEADROOM_MEMORY_INJECTION_MODE", "tool")
|
||||
assert get_memory_injection_mode() == "tool"
|
||||
|
||||
|
||||
def test_resolve_memory_injection_mode_rejects_unknown_values() -> None:
|
||||
|
||||
Reference in New Issue
Block a user