* refactor(plugins): remove the Sep 2026 decomposition compat layer on schedule The PLUGIN-COMPAT layer (2776813df3+d63e380324+0a5164cebe) kept pre-#102117 import paths alive for external plugins until 2026-09-14. That window closed two weeks ago; since then the loader has already been skipping plugins that use the old paths. This removes the layer itself: - 328 appended `PLUGIN-COMPAT` blocks (lazy `__getattr__` pointer tables, re-exported third-party names, restored dead definitions) and the three re-export stub modules (gateway/startup_watchdog, hermes_cli/observability/relay_runtime, tools/environments/modal_utils) - COMPAT_MANIFEST.md, compat_manifest.json, scripts/check_compat_pointers.py and its lint step - the reporting surfaces: CLI banner notice, `hermes plugins compat`, the `hermes doctor` section, the post-update notice, the Desktop one-time dialog, the loader's pre-import skip and the `plugins.allow_deprecated_imports` escape hatch An external plugin that still imports an old path now fails to load with its ImportError as the reason in `hermes plugins list`, the same path as any broken plugin. hermes_cli/plugin_compat.py stays as three inert stubs (compat_report, removal_in_effect, summary_lines): an already-running pre-removal `hermes update` lazy-imports them after the checkout swap (tests/compat/old_updater_surface.json). In-tree fallout, both already dead: hermes_cli/setup.py::_check_espeak_ng (no callers; its `shutil` came from a compat block) and gateway/config.py::SessionResetPolicy ("retained solely for the scheduled plugin-compat window"). Two test_run_agent patches targeted the removed `run_agent.handle_function_call` pointer; they now patch `model_tools.handle_function_call`, the seam production reads, like every sibling test in that file. * chore: retrigger CI (zero-job startup_failure phantom) * test: drop resolution allowlist rows for the two deleted which() sites hermes_cli/setup.py::_check_espeak_ng (dead) and tools/skillevaluator_scan.py::scanner_available (a restored definition inside a PLUGIN-COMPAT block) no longer exist; the stale-row gate requires their allowlist entries go with them.
80 lines
3.1 KiB
Python
80 lines
3.1 KiB
Python
"""Bounded reads of HTTP error response bodies.
|
|
|
|
On a non-OK *streaming* response Hermes reads the body for a diagnostic (only ever shown truncated to
|
|
a few hundred chars). A bare ``response.read()`` is unbounded two ways: arbitrarily large body
|
|
(memory) or a body that stalls forever (hang). ``read_streaming_error_body`` caps bytes and enforces a
|
|
hard wall-clock deadline; callers use the returned text instead of ``response.text`` (unbounded /
|
|
raises after a partial stream read). ``httpx.iter_bytes()`` blocks *inside* the socket read, so the
|
|
read runs on a daemon thread; on timeout we close the response (unblocking the read) and return the
|
|
partial bytes. Used by the streaming error-body sites: native Gemini, Gemini Cloud Code, Antigravity.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import threading
|
|
from typing import List
|
|
|
|
import httpx
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Comfortably holds any real provider error envelope while rejecting pathological bodies.
|
|
DEFAULT_ERROR_BODY_MAX_BYTES = 64 * 1024
|
|
# Hard deadline for the whole read; past it the connection is closed and the partial bytes are kept.
|
|
DEFAULT_ERROR_BODY_TIMEOUT_S = 10.0
|
|
|
|
|
|
def read_streaming_error_body(
|
|
response: httpx.Response,
|
|
*,
|
|
max_bytes: int = DEFAULT_ERROR_BODY_MAX_BYTES,
|
|
timeout_s: float = DEFAULT_ERROR_BODY_TIMEOUT_S,
|
|
) -> str:
|
|
"""Read a non-OK streaming body with a byte cap and a hard deadline.
|
|
|
|
Returns UTF-8 text (errors replaced) truncated to ``max_bytes``. Never raises: transport errors,
|
|
stalls and oversize bodies yield best-effort partial text (or ""), so a read error can't mask the
|
|
original failure.
|
|
"""
|
|
chunks: List[bytes] = []
|
|
state = {"truncated": False}
|
|
done = threading.Event()
|
|
|
|
def _drain() -> None:
|
|
total = 0
|
|
try:
|
|
for chunk in response.iter_bytes():
|
|
if not chunk:
|
|
continue
|
|
remaining = max_bytes - total
|
|
if len(chunk) > remaining:
|
|
if remaining > 0:
|
|
chunks.append(chunk[:remaining])
|
|
state["truncated"] = True
|
|
break
|
|
chunks.append(chunk)
|
|
total += len(chunk)
|
|
except Exception as exc: # noqa: BLE001 - error path must not raise
|
|
logger.debug("bounded error-body read failed: %s", exc)
|
|
finally:
|
|
done.set()
|
|
|
|
threading.Thread(target=_drain, name="bounded-error-body-read", daemon=True).start()
|
|
if not done.wait(timeout=timeout_s):
|
|
logger.debug(
|
|
"bounded error-body read: hard timeout after %.1fs (%d bytes so far)",
|
|
timeout_s, sum(len(c) for c in chunks),
|
|
)
|
|
# Closing cancels any in-flight socket read so the worker unwinds. No join (daemon, may be blocked in C).
|
|
try:
|
|
response.close()
|
|
except Exception: # noqa: BLE001
|
|
pass
|
|
|
|
if state["truncated"]:
|
|
logger.debug(
|
|
"bounded error-body read: capped at %d bytes (max=%d)", sum(len(c) for c in chunks), max_bytes,
|
|
)
|
|
return b"".join(chunks).decode("utf-8", errors="replace")
|