Skip to content

fix(sdk): generic DM readback changes message kind to channel #1987

Open

Description

@coygeek

fix(sdk): generic DM readback changes message kind to channel

Summary

A direct message sent through sendMessage({ to: '@recipient', ... }) returns kind: 'dm', but the intended recipient's messages.get(sent.id) returns kind: 'channel' for the same stored message. The ID, text and sender remain intact. Applications branching on RelayMessage.kind can therefore route or display a DM as a channel message.

Steps to reproduce

Prerequisite: start a disposable local engine using the engine package listed under Runtime or environment, and set RELAY_BASE_URL to its origin. The tested engine ran from the official npm package in a Node Docker container with its port published only on host loopback. This creates a fresh workspace and two agents; generated credentials stay in memory and are never printed.

  1. In an empty directory, run npm install @agent-relay/sdk@14.0.0 zod.
  2. Save the following as repro.mjs, then run node repro.mjs with RELAY_BASE_URL set. The script below was executed against the published package. The same create/register/send/read/raw-read sequence was also executed against the source build.
import assert from 'node:assert/strict';
import { AgentRelay } from '@agent-relay/sdk';

const baseUrl = process.env.RELAY_BASE_URL;
assert.ok(baseUrl, 'Set RELAY_BASE_URL to a disposable local engine');
const relay = await AgentRelay.createWorkspace({ name: 'dm-kind-repro', baseUrl });
let sender, recipient;
try {
  sender = await relay.workspace.register({ name: 'sender', type: 'agent' }, { strict: true });
  recipient = await relay.workspace.register({ name: 'recipient', type: 'agent' }, { strict: true });
  const sent = await sender.sendMessage({ to: '@recipient', text: 'private follow-up' });
  const read = await recipient.messages.get(sent.id);
  const response = await fetch(`${baseUrl}/v1/messages/${sent.id}`, {
    headers: { Authorization: `Bearer ${recipient.token}` },
  });
  const raw = (await response.json()).data;
  assert.equal(response.status, 200);
  console.log(JSON.stringify({
    sentKind: sent.kind,
    readKind: read.kind,
    sameId: read.id === sent.id,
    sameText: read.text === sent.text,
    sameSender: read.from.id === sender.id,
    rawDmChannel: raw.channel_id?.startsWith('dmch_'),
    rawHasConversationId: Object.hasOwn(raw, 'conversation_id'),
  }, null, 2));
} finally {
  await sender?.events.disconnect();
  await recipient?.events.disconnect();
  await relay.events.disconnect();
}

Expected behavior

The recipient's generic read of this direct message preserves its DM classification: read.kind === 'dm'. The common RelayMessage API distinguishes dm from channel; reading the same ID should not turn the DM into a channel message merely because storage uses a backing channel.

Actual behavior

The published build and the source build both returned dm on send and channel on recipient readback. Each build was tested once with a fresh workspace, two agents and one DM. The public script was then run separately against the published build and printed:

{
  "sentKind": "dm",
  "readKind": "channel",
  "sameId": true,
  "sameText": true,
  "sameSender": true,
  "rawDmChannel": true,
  "rawHasConversationId": false
}

The actual HTTP response from GET /v1/messages/{id} contained data.channel_id starting with dmch_ and omitted data.conversation_id. It also retained the message's ID, text, agent ID and agent name. The intended recipient successfully read it; this report establishes a metadata classification failure and makes no permission-bypass claim.

Runtime or environment

  • OS: Linux x86_64.
  • SDK runtime: Node v26.12.1, npm 12.2.1.
  • Published package: @agent-relay/sdk 14.0.0, the current npm stable release; resolved dependencies @relaycast/sdk 8.16.0, @relaycast/types 8.16.0 and Zod 4.6.7.
  • Source build: repository main at c3a92d9c179972963756ebce3fcd106679302934, compiled with the repository-pinned TypeScript 5.9.3 and tested with the same SDK dependency versions as the published build.
  • Self-hosted engine: @relaycast/engine 11.0.0, the current npm stable release, on Node v22.23.4 with better-sqlite3 11.10.0.

Evidence

  • Expected source: The public RelayMessageKind and RelayMessage types define distinct DM and channel kinds. The message APIs return the common message type for generic reads and normalize direct sends as DMs.
  • Failure source: Executed SDK send, recipient readback and authenticated raw HTTP read using the inline fixture's sequence; the output above records the discriminating fields without credentials or generated identifiers.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

The current normalizer chooses channel when a message has a channel ID but no conversation ID or parent ID. Generic messages.get supplies no DM context. That branch matches the observed raw response shape; this identifies the classification path without assuming that a particular repair belongs solely in the SDK or engine.

Restoration check

Run the fresh-workspace reproduction and confirm that send and recipient readback both report kind: 'dm', with matching ID, text and sender. A genuine channel message should still read back as kind: 'channel'. Preserve recipient access and the message data; returning a different message or omitting the discriminator does not restore this contract.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: The generic read returns the wrong message discriminator for an observed valid DM, so consumers using that field can misclassify it; the tested recipient still receives the correct content.
  • Workaround status: available
  • Workaround basis: A sender-tracking application can correlate the original DM send, intended recipient, message ID, content and sender instead of relying on generic readback kind. These correlations were verified in the reproduction; this does not provide a discriminator for consumers that lack the original send context.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions