Skip to content

fix(matrix,simplex): tolerate malformed HERMES_*_TEXT_BATCH_* delay env vars - #49719

Open
ly-wang19 wants to merge 1 commit into
NousResearch:mainfrom
ly-wang19:fix/matrix-simplex-text-batch-env-float
Open

fix(matrix,simplex): tolerate malformed HERMES_*_TEXT_BATCH_* delay env vars#49719
ly-wang19 wants to merge 1 commit into
NousResearch:mainfrom
ly-wang19:fix/matrix-simplex-text-batch-env-float

Conversation

@ly-wang19

Copy link
Copy Markdown
Contributor

Summary

Follow-up to a7dd98c86 ("guard remaining malformed int/float env var casts with utils helpers").

That sweep routed the HERMES_<PLATFORM>_TEXT_BATCH_* delay casts through the safe utils.env_float helper for Feishu, WeCom, Discord, and Telegram — but missed the identical sibling sites in the Matrix and SimpleX adapters, which still do a raw float(os.getenv(...)):

# gateway/platforms/matrix.py (MatrixAdapter.__init__)
self._text_batch_delay_seconds = float(os.getenv("HERMES_MATRIX_TEXT_BATCH_DELAY_SECONDS", "0.6"))
self._text_batch_split_delay_seconds = float(os.getenv("HERMES_MATRIX_TEXT_BATCH_SPLIT_DELAY_SECONDS", "2.0"))
# plugins/platforms/simplex/adapter.py
self._text_batch_delay = float(os.getenv("HERMES_SIMPLEX_TEXT_BATCH_DELAY", "0.8"))

A non-numeric value — e.g. a realistic unit-suffix typo HERMES_MATRIX_TEXT_BATCH_DELAY_SECONDS=0.6s — makes float("0.6s") raise an uncaught ValueError inside MatrixAdapter.__init__. That propagates through GatewayRunner._create_adapter and the unguarded platform-init loop in GatewayRunner.start(), so the whole gateway fails to boot when Matrix is enabled.

This is an overlooked miss, not an intentional fail-fast:

  • the same __init__ already guards MATRIX_ROOM_IDENTITY_TTL_SECONDS with try/except + fallback;
  • the sweep's own commit message states only sites already guarded by try/except or helpers were left untouched;
  • the four sibling text-batch adapters were all converted — Matrix/SimpleX are simply the ones the sweep didn't reach.

Fix

Route both adapters' casts through env_float (returns the default on ValueError/TypeError), exactly as the four siblings were converted. No behavior change for valid values; the empty-string case also degrades to the default instead of raising.

Tests

tests/gateway/test_matrix.py::TestMatrixTextBatchEnvParsing — constructs MatrixAdapter with a malformed HERMES_MATRIX_TEXT_BATCH_DELAY_SECONDS / ..._SPLIT_DELAY_SECONDS and asserts init no longer raises and falls back to the default; plus a valid-value case. The two malformed cases fail without the fix (ValueError out of __init__).

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/matrix Matrix adapter (E2EE) labels Jun 20, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #48771 (feishu env-guard), #48757 (wecom env-guard) — same env_float/env_int guard primitive applied per-platform. Also #35790 / #47338 (broader cross-adapter env-cast hardening). This PR fills the Matrix + SimpleX gap the a7dd98c86 sweep missed; the carried scope is the genuine per-PR fix.

@ly-wang19
ly-wang19 force-pushed the fix/matrix-simplex-text-batch-env-float branch from ea4eb79 to d047d43 Compare June 21, 2026 14:29
@ly-wang19

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main to resolve the conflict. The Matrix adapter moved from gateway/platforms/matrix.py to plugins/platforms/matrix/adapter.py, so the env_float fix is now applied there, and the new TestMatrixTextBatchEnvParsing import was updated to plugins.platforms.matrix.adapter. The three tests pass locally.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for carrying the missed Matrix and SimpleX env-float hardening forward. The underlying direct-construction defect is present on current main at plugins/platforms/matrix/adapter.py:926-931 and plugins/platforms/simplex/adapter.py:194-196; utils.env_float provides the intended fallback at utils.py:421-429.

Problems

  • The added Matrix comments and test docstring say malformed input aborts gateway boot. Current plugin creation catches factory exceptions in gateway/platform_registry.py:318-328, and GatewayRunner.start() continues when no adapter is returned at gateway/run.py:7047-7060. Please describe the current consequence as Matrix adapter creation failing instead.
  • The SimpleX production change has no corresponding malformed-env regression test. Its current adapter-init coverage lives in tests/gateway/test_simplex_plugin.py:121-142.

Suggested changes

  • Correct the stale gateway-boot explanation in the added Matrix comments/tests.
  • Add a SimpleX malformed-delay fallback test alongside its adapter-init tests.

Automated hermes-sweeper review.

self._text_batch_split_delay_seconds = float(
os.getenv("HERMES_MATRIX_TEXT_BATCH_SPLIT_DELAY_SECONDS", "2.0")
# env_float tolerates a malformed value (e.g. a "0.6s" unit-suffix typo)
# instead of raising ValueError out of __init__ and crashing gateway

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current main no longer lets this exception abort the full gateway boot: PlatformRegistry.create_adapter() catches factory exceptions at gateway/platform_registry.py:318-328, and GatewayRunner.start() continues when it receives no adapter. Please describe this as failed Matrix adapter creation rather than a gateway-wide crash.

)
# env_float tolerates a malformed value instead of raising out of
# __init__ (mirrors the other text-batch adapters).
self._text_batch_delay = env_float("HERMES_SIMPLEX_TEXT_BATCH_DELAY", 0.8)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a malformed HERMES_SIMPLEX_TEXT_BATCH_DELAY regression case in tests/gateway/test_simplex_plugin.py alongside the existing adapter-init tests, so this changed fallback path is covered as well as Matrix.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
…nv vars

a7dd98c swept the unguarded float(os.getenv()) text-batch delay casts onto
the safe utils.env_float helper for Feishu/WeCom/Discord/Telegram, but missed
the identical sibling sites in the Matrix and SimpleX adapters. A non-numeric
value (e.g. a `HERMES_MATRIX_TEXT_BATCH_DELAY_SECONDS=0.6s` unit-suffix typo)
raises an uncaught ValueError in MatrixAdapter.__init__, which propagates
through GatewayRunner._create_adapter and the unguarded platform-init loop in
start(), aborting gateway boot when Matrix is enabled.

The same __init__ already guards MATRIX_ROOM_IDENTITY_TTL_SECONDS with
try/except, and the sweep's own message says only already-guarded sites were
left untouched — so these are overlooked misses, not intentional fail-fast.

Route both through env_float (default-on-malformed), matching the four sibling
adapters. Adds Matrix init tests; the malformed cases raise without the fix.
@ly-wang19

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. The Matrix adapter has since moved (gateway/platforms/matrix.pyplugins/platforms/matrix/adapter.py), so this is re-targeted at the new location — the raw cast is still there today:

plugins/platforms/matrix/adapter.py:950   os.getenv("HERMES_MATRIX_TEXT_BATCH_DELAY_SECONDS", "0.6")
plugins/platforms/simplex/adapter.py:195  os.getenv("HERMES_SIMPLEX_TEXT_BATCH_DELAY", "0.8")

Both now go through utils.env_float, matching how Feishu/WeCom/Discord/Telegram read the same HERMES_<PLATFORM>_TEXT_BATCH_* family after a7dd98c. Matrix test suite is green (the one unrelated TestMatrixProxyConfig::test_no_proxy_by_default failure reproduces on unmodified main in any environment with HTTP_PROXY set, so it's not from this change).

@ly-wang19
ly-wang19 force-pushed the fix/matrix-simplex-text-batch-env-float branch from d047d43 to 3bb2028 Compare July 18, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/matrix Matrix adapter (E2EE) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants