Skip to content

Handle plain Matrix replies to the bot - #62

Closed
strk-ai-agent wants to merge 1 commit into
ominiverdi:mainfrom
strk-ai-agent:matrix-replies
Closed

Handle plain Matrix replies to the bot#62
strk-ai-agent wants to merge 1 commit into
ominiverdi:mainfrom
strk-ai-agent:matrix-replies

Conversation

@strk-ai-agent

Copy link
Copy Markdown

Summary

The Matrix connector now picks up plain m.in_reply_to replies as implicit follow-ups — but only when the reply targets a message the bot itself sent. Previously, replies in a room with an active session were ignored unless they used m.thread relations (which only work with threadIsolation: true), contained the trigger, or mentioned the bot.

Changes

  • New extractReplyTargetId(event, threadIsolation) helper in connectors/matrix-thread-helpers.ts:
    • m.thread event_id wins regardless of isolation
    • Falls back to m.in_reply_to event_id only when isolation is off
    • Handles legacy top-level m.in_reply_to for older clients
  • connectors/matrix.ts:
    • RoomSession gains botSentEventIds: Set<string> to track messages the bot has sent
    • New recordBotEventId() helper called by every send path: sendReply (both isolation branches), sendNoticeReply, createToolActivityMessage, sendImageFromBase64, sendImageFromFile
    • Dispatch in handleRoomMessage: with isolation off, the implicit-follow-up branch now requires session.botSentEventIds.has(threadRootEventId) — third-party replies are dropped
  • Tests:
    • tests/unit/matrix-thread-context.test.ts: 7 new cases for extractReplyTargetId
    • tests/integration/matrix-event-mapping.test.ts: end-to-end contract for plain replies
    • tests/unit/matrix-empty-response.test.ts: factory updated for new session field

Behaviour matrix

  • threadIsolation: true + m.thread reply from anyone in the thread → continues the thread session (unchanged)
  • threadIsolation: true + plain m.in_reply_to reply → ignored (unchanged)
  • threadIsolation: false + m.thread reply → continues the room session (new)
  • threadIsolation: false + m.in_reply_to reply to a bot message → continues the room session (new)
  • threadIsolation: false + m.in_reply_to reply to someone else → ignored (new)
  • Trigger / mention / DM paths unchanged

Testing

bun run typecheck, bun test, and bun run check:connectors all pass (358 tests).

@strk

strk commented Jul 29, 2026

Copy link
Copy Markdown

I've tested this to work fine (in #lounge:osgeo.org).
@lnicola cab confirm (and maybe also review?)

When matrix.threadIsolation is off, plain m.in_reply_to replies in a room
with an existing session now count as implicit follow-ups — but only when
the reply target is a message the bot itself sent (tracked via a new
botSentEventIds set on RoomSession). Third-party replies in busy rooms
are ignored, and m.thread behaviour with isolation on is unchanged.

Add extractReplyTargetId helper that surfaces m.thread roots
unconditionally and falls back to m.in_reply_to only when isolation is
off, with m.thread taking precedence when both are present.

Assisted-By: minimax/MiniMax-M3 [via opencode 1.18.7]
@ominiverdi

Copy link
Copy Markdown
Owner

Closing under the updated contribution policy. The current submission volume and required verification exceed this project’s review capacity, and pull requests from autonomous or delegated agent accounts are no longer accepted. Valid underlying issues may remain open for independent implementation. Please do not revise, reopen, or replace this pull request.

@ominiverdi ominiverdi closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants