Skip to content

feat: add natural WhatsApp cascade delivery - #54455

Closed
devatnull wants to merge 9 commits into
NousResearch:mainfrom
devatnull:feat/whatsapp-cascade-delivery
Closed

feat: add natural WhatsApp cascade delivery#54455
devatnull wants to merge 9 commits into
NousResearch:mainfrom
devatnull:feat/whatsapp-cascade-delivery

Conversation

@devatnull

@devatnull devatnull commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add metadata-controlled WhatsApp delivery style (single, cascade, auto) for gateway outputs
  • add natural DM-style final-message composition for substantive long prose, with jittered 300–800ms-ish delays between follow-up bubbles and tail merging
  • keep approvals, code blocks, groups by default, status chrome, short/config-ish replies, copy-sensitive text, and machine/artifact payloads as single messages
  • cap natural cascade at 3 bubbles, lower the default split threshold, and keep structured/list/code/log/json/config/diff/command/checklist tails glued
  • keep active questions/actions out of early bubbles and keep links with their immediate context
  • add regression coverage for cascade thresholds, structured/artifact tails, active prompts, links, stream-consumer metadata, and status delivery style

Test Plan

  • scripts/run_tests.sh tests/gateway/test_whatsapp_formatting.py tests/gateway/test_stream_consumer.py tests/gateway/test_gateway_status_delivery_style.py

Copilot AI review requested due to automatic review settings June 28, 2026 21:57

Copilot AI 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.

Pull request overview

This PR introduces a metadata-controlled delivery style for WhatsApp gateway sends, adding a conservative “human cascade” mode that splits substantive multi-paragraph prose into a small sequence of natural DM-like bubbles while keeping status/progress chrome and other sensitive/structured content in a single message.

Changes:

  • Add WhatsApp “human cascade” splitting with configurable thresholds, jittered per-bubble delays, and tail merging/chunking.
  • Ensure non-final streaming commentary and gateway status/progress sends force delivery_style=single via send metadata.
  • Add regression tests covering cascade thresholds, structured tails, stream-consumer metadata behavior, and status delivery style.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
plugins/platforms/whatsapp/adapter.py Implements WhatsApp delivery style parsing and human-cascade splitting/delay behavior.
gateway/stream_consumer.py Forces delivery_style=single for non-final stream sends and uses that metadata for commentary sends.
gateway/run.py Forces delivery_style=single for status/progress sends (including fallback status sends).
tests/gateway/test_whatsapp_formatting.py Adds coverage for cascade heuristics, forced styles, structured tails, and guardrails (code blocks/approvals/groups).
tests/gateway/test_stream_consumer.py Adds unit coverage for _metadata_for_send() and commentary send metadata.
tests/gateway/test_gateway_status_delivery_style.py Adds regression tests to ensure status/progress sends force single delivery style.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +418 to +434
self._human_cascade_max_total_chars = self._coerce_int_extra(
"human_cascade_max_total_chars", 900, env_var="WHATSAPP_HUMAN_CASCADE_MAX_TOTAL_CHARS"
)
self._human_cascade_min_total_chars = self._coerce_int_extra(
"human_cascade_min_total_chars", 420
)
self._human_cascade_min_lead_chars = self._coerce_int_extra(
"human_cascade_min_lead_chars", 40
)
self._human_cascade_max_bubble_chars = self._coerce_int_extra(
"human_cascade_max_bubble_chars", 320, env_var="WHATSAPP_HUMAN_CASCADE_MAX_BUBBLE_CHARS"
)
self._human_cascade_max_merged_bubble_chars = self._coerce_int_extra(
"human_cascade_max_merged_bubble_chars",
640,
env_var="WHATSAPP_HUMAN_CASCADE_MAX_MERGED_BUBBLE_CHARS",
)
Comment thread plugins/platforms/whatsapp/adapter.py Outdated
Comment on lines +503 to +506
@staticmethod
def _has_approval_gate(text: str) -> bool:
"""Return True for explicit approval/control prompts that must stay intact."""
return bool(re.search(r"`/(approve|deny|reject|confirm|cancel|stop|new|reset)\b", text, re.IGNORECASE))
Comment on lines +585 to +590
force_cascade = style in {"cascade", "human_cascade", "human-cascade"}
if not force_cascade and (
(is_group and not self._human_cascade_groups)
or self._has_approval_gate(text)
):
return self.truncate_message(formatted, limit), False
Comment thread plugins/platforms/whatsapp/adapter.py Outdated
Comment on lines +607 to +623
merged_tail = False
if not force_cascade and self._looks_structured_outbound(text):
merged = self._merge_structured_tail(paragraphs, max_bubbles)
if merged is None:
return self.truncate_message(formatted, limit), False
paragraphs = merged
merged_tail = True

if len(paragraphs) > max_bubbles and not force_cascade:
# Keep the human cadence without machine-gunning the chat: send the
# first few thoughts as separate bubbles, then fold the remainder
# into the final bubble. This handles natural 5–6 paragraph chatty
# replies better than falling all the way back to one glued block.
head = paragraphs[: max_bubbles - 1]
tail = "\n\n".join(paragraphs[max_bubbles - 1:]).strip()
paragraphs = [*head, tail]
merged_tail = True
@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery platform/whatsapp WhatsApp Business adapter P3 Low — cosmetic, nice to have sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jun 28, 2026
@devatnull

Copy link
Copy Markdown
Contributor Author

Closing this old branch so we can rebuild the Hermes changes cleanly from current main and reopen smaller fresh PRs.

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 P3 Low — cosmetic, nice to have platform/whatsapp WhatsApp Business adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants