Skip to content

fix(gateway): add reply_to for all mid-turn messages in group chats - #10929

Closed
shamork wants to merge 1 commit into
NousResearch:mainfrom
shamork:fix/gateway-progress-reply-to
Closed

fix(gateway): add reply_to for all mid-turn messages in group chats#10929
shamork wants to merge 1 commit into
NousResearch:mainfrom
shamork:fix/gateway-progress-reply-to

Conversation

@shamork

@shamork shamork commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

All mid-turn messages sent during agent processing were missing reply_to, causing them to appear as standalone posts in group chats instead of threading under the user's original message.

On Feishu/Lark this was especially broken:

  • Normal groups: mid-turn messages posted to group root, not as replies
  • Topic groups: messages created spurious new topics because reply_in_thread only takes effect in the ReplyMessage API path, which requires reply_to to be set

Fix: propagate event_message_id as reply_to through every mid-turn message path in _run_agent() and _run_agent_via_proxy():

gateway/run.py:

  • send_progress_messages() — tool progress line edits
  • _status_callback_sync() — context pressure / status events
  • _interim_assistant_cb() — natural mid-turn commentary (non-streaming)
  • _approval_notify_sync() — dangerous command approval card and plain-text fallback
  • _notify_long_running() — periodic "still working" heartbeat
  • _deliver_bg_review_message() — background code-review callback
  • Inactivity warning — "no activity for N min" timeout warning
  • Queued-message first-response delivery after interrupt
  • GatewayStreamConsumer creation (both local and proxy paths)

gateway/stream_consumer.py:

  • New reply_to constructor parameter, wired through _send_commentary(), _send_or_edit() first-send path, and _send_fallback_final()

gateway/platforms/feishu.py:

  • send_exec_approval() now accepts and forwards reply_to instead of hardcoding None

Related Issue

Fixes Feishu/Lark group chat threading — mid-turn messages broke out of thread context.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run.py — propagated reply_to=event_message_id to all 8+ mid-turn message paths
  • gateway/stream_consumer.py — added reply_to constructor param, wired through commentary/edit/fallback sends
  • gateway/platforms/feishu.pysend_exec_approval() accepts and forwards reply_to

How to Test

  1. Send a message to Hermes in a Feishu normal group → verify mid-turn progress/commentary appears as replies to your message, not as standalone posts
  2. Send a message in a Feishu topic group → verify mid-turn messages stay in the same topic thread, no spurious new topics created
  3. Trigger a dangerous command (e.g. rm -rf /tmp/test) → verify the approval card is posted as a reply
  4. Run pytest tests/ -q — 184 passed, 16 skipped, 0 failed. The only known failure (test_run_agent_previewed_final_marks_already_sent) is a pre-existing issue unrelated to this change

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Win10 21H2 (19044.7184) WSL2 Ubuntu + Feishu gateway

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Before: mid-turn messages appear as standalone posts / create new topics in Feishu groups
After: all mid-turn messages correctly thread under the user's original message

All mid-turn messages sent during agent processing were missing
reply_to, causing them to appear as standalone posts in group chats
instead of threading under the user's original message.

On Feishu/Lark this was especially broken:
- Normal groups: mid-turn messages posted to group root, not as replies
- Topic groups: messages created spurious new topics because
  reply_in_thread only takes effect in the ReplyMessage API path,
  which requires reply_to to be set

Fix: propagate event_message_id as reply_to through every mid-turn
message path in _run_agent() and _run_agent_via_proxy():

gateway/run.py:
- send_progress_messages() — tool progress line edits
- _status_callback_sync() — context pressure / status events
- _interim_assistant_cb() — natural mid-turn commentary (non-streaming)
- _approval_notify_sync() — dangerous command approval card and
  plain-text fallback
- _notify_long_running() — periodic "still working" heartbeat
- _deliver_bg_review_message() — background code-review callback
- Inactivity warning — "no activity for N min" timeout warning
- Queued-message first-response delivery after interrupt
- GatewayStreamConsumer creation (both local and proxy paths)

gateway/stream_consumer.py:
- New reply_to constructor parameter, wired through _send_commentary(),
  _send_or_edit() first-send path, and _send_fallback_final()

gateway/platforms/feishu.py:
- send_exec_approval() now accepts and forwards reply_to instead of
  hardcoding None
@shamork

shamork commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

fixed by 910684c9

@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/feishu Feishu / Lark adapter labels Apr 24, 2026
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/feishu Feishu / Lark adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants