Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

refactor: remove write-only and test-only code in subscription and install (#4123)

Tejas Choprac191beef59cc
diff --git a/headroom/install/runtime.py b/headroom/install/runtime.py
index 0073fe4d5..2c0135844 100644
--- a/headroom/install/runtime.py
+++ b/headroom/install/runtime.py
@@ -369,11 +369,6 @@ def _proxy_deployment_markers_match(cmdline: list[str], manifest: DeploymentMani
return True
-def _process_matches_runtime(pid: int, manifest: DeploymentManifest) -> bool:
- """Verify the PID's deployment identity before lifecycle operations."""
- return _process_identity(pid, manifest) is True
-
-
def _process_identity(pid: int, manifest: DeploymentManifest) -> bool | None:
"""Return whether a PID matches, or ``None`` when identity is unavailable."""
if pid == os.getpid():
diff --git a/headroom/subscription/tracker.py b/headroom/subscription/tracker.py
index 80d5aa661..f2d034634 100644
--- a/headroom/subscription/tracker.py
+++ b/headroom/subscription/tracker.py
@@ -49,9 +49,6 @@ logger = logging.getLogger(__name__)
_DEFAULT_POLL_INTERVAL_S = 300
_DEFAULT_ACTIVE_WINDOW_S = 60
-_PERSIST_FILE_ENV = _paths.HEADROOM_SUBSCRIPTION_STATE_PATH_ENV
-_DEFAULT_PERSIST_DIR = ".headroom"
-_DEFAULT_PERSIST_FILE = "subscription_state.json"
# Singleton on-demand poll floor (seconds): the dashboard may request a fresh
# poll if the cached snapshot is stale, but we cap how often we will actually
@@ -127,7 +124,6 @@ class SubscriptionTracker(QuotaTracker):
self._lock = threading.Lock()
self._state = SubscriptionState()
self._current_token: str | None = None
- self._full_tokens: dict[str, int] = {} # token_prefix -> count of requests
self._stop_event: asyncio.Event | None = None
self._poll_task: asyncio.Task[None] | None = None
@@ -200,8 +196,6 @@ class SubscriptionTracker(QuotaTracker):
if not from_local_operator:
return
self._current_token = raw
- prefix = raw[:8]
- self._full_tokens[prefix] = self._full_tokens.get(prefix, 0) + 1
def update_contribution(
self,
diff --git a/tests/test_install/test_runtime.py b/tests/test_install/test_runtime.py
index 3715230df..8d72bcf42 100644
--- a/tests/test_install/test_runtime.py
+++ b/tests/test_install/test_runtime.py
@@ -15,7 +15,6 @@ from headroom.install.runtime import (
_deployment_env,
_mount_source,
_process_identity,
- _process_matches_runtime,
_read_pid,
_runtime_env,
_write_pid,
@@ -847,7 +846,7 @@ def test_process_identity_must_match_headroom_command(monkeypatch) -> None:
}
monkeypatch.setitem(sys.modules, "psutil", types.SimpleNamespace(Process=FakeProcess))
- assert not _process_matches_runtime(4321, _python_service_manifest())
+ assert _process_identity(4321, _python_service_manifest()) is False
class MatchingProcess(FakeProcess):
def cmdline(self) -> list[str]:
@@ -860,7 +859,7 @@ def test_process_identity_must_match_headroom_command(monkeypatch) -> None:
}
monkeypatch.setitem(sys.modules, "psutil", types.SimpleNamespace(Process=MatchingProcess))
- assert _process_matches_runtime(4321, _python_service_manifest())
+ assert _process_identity(4321, _python_service_manifest()) is True
def test_process_identity_falls_back_without_psutil(monkeypatch) -> None:
@@ -876,7 +875,7 @@ def test_process_identity_falls_back_without_psutil(monkeypatch) -> None:
),
)
monkeypatch.setitem(sys.modules, "psutil", None)
- assert _process_matches_runtime(4321, manifest)
+ assert _process_identity(4321, manifest) is True
def test_process_identity_uses_macos_ps_fallback_without_psutil(monkeypatch) -> None:
@@ -893,7 +892,7 @@ def test_process_identity_uses_macos_ps_fallback_without_psutil(monkeypatch) ->
)
monkeypatch.setattr("headroom.install.runtime.run", lambda *a, **k: Result())
- assert _process_matches_runtime(4321, manifest)
+ assert _process_identity(4321, manifest) is True
def test_process_identity_uses_windows_wmi_command_line_without_psutil(monkeypatch) -> None:
@@ -914,7 +913,7 @@ def test_process_identity_uses_windows_wmi_command_line_without_psutil(monkeypat
lambda command, **kwargs: calls.append(command) or Result(),
)
- assert _process_matches_runtime(4321, manifest)
+ assert _process_identity(4321, manifest) is True
assert calls[0][:3] == ["powershell.exe", "-NoProfile", "-NonInteractive"]
@@ -1010,7 +1009,7 @@ def test_runtime_status_does_not_use_ready_probe_for_failed_identity(
def test_process_identity_rejects_current_pid(monkeypatch) -> None:
monkeypatch.setattr("headroom.install.runtime.os.getpid", lambda: 4321)
- assert not _process_matches_runtime(4321, _python_service_manifest())
+ assert _process_identity(4321, _python_service_manifest()) is False
def test_darwin_task_preserves_popen_path(monkeypatch, tmp_path: Path) -> None:
diff --git a/tests/test_subscription_tracker.py b/tests/test_subscription_tracker.py
index ece9c6966..481102574 100644
--- a/tests/test_subscription_tracker.py
+++ b/tests/test_subscription_tracker.py
@@ -59,7 +59,6 @@ def test_tracker_notify_active_update_and_basic_state(monkeypatch: pytest.Monkey
tracker.notify_active("Bearer oauth-token-123", from_local_operator=True)
assert tracker._current_token == "oauth-token-123"
- assert tracker._full_tokens["oauth-to"] == 1
assert tracker.is_active() is True
tracker.update_contribution(