block / block/buzz

Mobile: DM messages omit recipient p-tags, so agents never receive them

Open
#3,591 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
32.7k
Forks
4.3k
Avg merge
1d 13h
Merged PRs (30d)
253

Description

## Summary

Messages sent from the mobile client in a **DM channel** carry no `p` tags, so agent harnesses never receive them as a turn. The event reaches the relay and shows up in history, but the agent stays silent. The same message sent from Desktop works, because Desktop implicitly p-tags every DM participant.

## Root cause

Desktop has an explicit DM rule in `desktop/src/features/messages/lib/messageMentionPubkeys.ts`:

```ts
const candidates =
channel.channelType === "dm"
? [...explicitMentions, ...channel.memberPubkeys, ...channel.participantPubkeys]
: explicitMentions;
```

Its doc comment names this exact requirement:

> Stream messages notify only explicit mentions. A DM addresses every other participant, so it must carry recipient `p` tags even when the composer text contains no `@mention`. Agent harnesses and human notification subscriptions both rely on those tags.

Covered by `desktop/src/features/messages/lib/messageMentionPubkeys.test.mjs`: *"plain DM messages p-tag every recipient except the sender"*.

Mobile has no equivalent. `mobile/lib/features/channels/send_message_provider.dart` builds tags as:

```dart
final tags = >[
['h', channelId],
if (parentEventId != null) ..._buildReplyTags(parentEventId, rootEventId),
for (final pk in normalizedMentions) ['p', pk],
...mediaTags,
];
```

`normalizedMentions` comes only from explicitly passed pubkeys or from `_resolveMentions()`, which scans the text for `@(\w+)`. There is no `channelType == 'dm'` branch anywhere in that file.

## Reproduction

1. Open a DM with a managed agent.
2. Send a plain message from Desktop, e.g. `hello` -> event has `["h", ]` and `["p", ]`; the agent replies.
3. Send the same plain message from mobile -> event has only `["h", ]` (plus `["e", ...]` when replying in a thread); the agent never wakes.

Observed across 15 consecutive messages in one DM: all 9 events with a `p` tag produced an agent turn, all 6 without one were silently dropped. Correlation was exact; timing, message length and thread nesting made no difference.

## Impact

From mobile, a user cannot talk to an agent in a DM at all unless they know to type a literal `@AgentName`. There is no error and no visual difference: the message appears delivered.

## Suggested fix

Port the `messageMentionPubkeys` rule into `send_message_provider.dart`: when the channel is a DM, add the other participants to `normalizedMentions` before building the tags. Mirror the Desktop unit test on the mobile side.

## Workaround

On mobile, type `@AgentName` in the message body so `_resolveMentions()` produces the `p` tag.

Contributor guide

Open the contributing guide

Research direction

Start in mobile/lib/features/channels/send_message_provider.dart and compare its tag-building flow with desktop/src/features/messages/lib/messageMentionPubkeys.ts. Read the existing desktop test, then locate the mobile message tests or test entry point and add coverage for a plain DM. Done means a mobile DM event includes recipient p tags and the regression test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.