Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gateway/platforms/whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,16 @@ def __init__(self, config: PlatformConfig):
# WhatsApp often delivers multiple messages in rapid succession
# (e.g. forwarded batches, paste-splits) — without debounce each
# message triggers a separate agent invocation, wasting tokens and
# flooding the user with reply fragments. Default 5s delay /
# 10s split delay are conservative for WhatsApp's delivery cadence.
# flooding the user with reply fragments. Default 0.3s delay /
# 2.0s split delay match the Telegram adapter's cadence.
# Tunable via config.yaml under
# ``gateway.platforms.whatsapp.extra.text_batch_delay_seconds`` /
# ``text_batch_split_delay_seconds``.
self._text_batch_delay_seconds = self._coerce_float_extra(
"text_batch_delay_seconds", 5.0
"text_batch_delay_seconds", 0.3
)
self._text_batch_split_delay_seconds = self._coerce_float_extra(
"text_batch_split_delay_seconds", 10.0
"text_batch_split_delay_seconds", 2.0
)
self._pending_text_batches: Dict[str, MessageEvent] = {}
self._pending_text_batch_tasks: Dict[str, asyncio.Task] = {}
Expand Down
10 changes: 5 additions & 5 deletions tests/gateway/test_whatsapp_text_batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def _event(text):

def test_batch_delays_default_from_config():
adapter = _make_adapter()
assert adapter._text_batch_delay_seconds == 5.0
assert adapter._text_batch_split_delay_seconds == 10.0
assert adapter._text_batch_delay_seconds == 0.3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Current main's test already imports plugins.platforms.whatsapp.adapter, but the production half of this PR still edits the retired gateway/platforms/whatsapp.py. Port the matching defaults to plugins/platforms/whatsapp/adapter.py; otherwise this updated assertion will not match runtime behavior.

assert adapter._text_batch_split_delay_seconds == 2.0


def test_batch_delays_overridden_via_config_extra():
Expand All @@ -53,15 +53,15 @@ def test_invalid_config_value_falls_back_to_default():
text_batch_delay_seconds="garbage",
text_batch_split_delay_seconds=-3,
)
assert adapter._text_batch_delay_seconds == 5.0
assert adapter._text_batch_split_delay_seconds == 10.0
assert adapter._text_batch_delay_seconds == 0.3
assert adapter._text_batch_split_delay_seconds == 2.0


def test_env_var_is_ignored(monkeypatch):
# Config-only path: the legacy HERMES_* env var must NOT influence delays.
monkeypatch.setenv("HERMES_WHATSAPP_TEXT_BATCH_DELAY_SECONDS", "99")
adapter = _make_adapter()
assert adapter._text_batch_delay_seconds == 5.0
assert adapter._text_batch_delay_seconds == 0.3


def test_rapid_texts_collapse_into_single_dispatch():
Expand Down
Loading