Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/trader/acp-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Mirror of trader-service/src/cli/dm-transport.ts.
*/

import type { DirectMessage } from '@unicitylabs/sphere-sdk';
import type { DirectMessage, SendMessageOptions } from '@unicitylabs/sphere-sdk';

import {
createAcpMessage,
Expand All @@ -30,7 +30,11 @@ export type { TimeoutError, TransportError };
export { MIN_TIMEOUT_MS };

export interface SphereComms {
sendDM(recipient: string, content: string): Promise<{ recipientPubkey: string }>;
sendDM(
recipient: string,
content: string,
options?: SendMessageOptions,
): Promise<{ recipientPubkey: string }>;
onDirectMessage(handler: (message: DirectMessage) => void): () => void;
}

Expand Down Expand Up @@ -165,7 +169,12 @@ class AcpDmTransportImpl implements AcpDmTransport {
return;
}

this.comms.sendDM(this.tenantAddress, payload).then((sent) => {
// sphere-sdk#559 / PR #558 — ACP RPC is short-lived (the trader
// CLI's `sphere trader <command>` exits as soon as the result
// lands). Skip the self-wrap so we don't leave a copy of every
// outgoing ACP command in the relay's `#p:controller` index for
// the next short-lived CLI process to pull down on subscribe.
this.comms.sendDM(this.tenantAddress, payload, { selfWrap: false }).then((sent) => {
if (!this.resolvedPubkey) {
this.resolvedPubkey = normalizeKey(sent.recipientPubkey);
// Drain pre-resolution buffer.
Expand Down
15 changes: 12 additions & 3 deletions src/transport/dm-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* });
*/

import type { DirectMessage } from '@unicitylabs/sphere-sdk';
import type { DirectMessage, SendMessageOptions } from '@unicitylabs/sphere-sdk';
import type { HmcpRequest, HmcpResponse } from './hmcp-types.js';
import { parseHmcpResponse, byteLength, MAX_MESSAGE_SIZE } from './hmcp-types.js';
import { TimeoutError, TransportError } from './errors.js';
Expand Down Expand Up @@ -47,7 +47,11 @@ export interface DmTransportConfig {

/** Narrow slice of Sphere.communications needed by DmTransport — injectable for testing. */
export interface SphereComms {
sendDM(recipient: string, content: string): Promise<{ recipientPubkey: string }>;
sendDM(
recipient: string,
content: string,
options?: SendMessageOptions,
): Promise<{ recipientPubkey: string }>;
onDirectMessage(handler: (message: DirectMessage) => void): () => void;
}

Expand Down Expand Up @@ -286,7 +290,12 @@ class DmTransportImpl implements DmTransport {
`Request too large: ${byteLength(serialized)} bytes exceeds MAX_MESSAGE_SIZE (${MAX_MESSAGE_SIZE})`,
);
}
const sent = await this.comms.sendDM(this.managerAddress, serialized);
// sphere-sdk#559 / PR #558 — HMCP RPC is short-lived (CLI exits
// shortly after the manager's reply). Suppressing the self-wrap
// halves the per-process relay-index pollution targeting the
// controller pubkey, which directly reduces the §3/§4 buffered-
// event noise the F1 soak measured at ~7 new events per spawn.
const sent = await this.comms.sendDM(this.managerAddress, serialized, { selfWrap: false });
// Cache the resolved pubkey on first send. Subsequent sends for the same
// manager address produce the same pubkey, so concurrent writes are safe.
if (!this.resolvedPubkey) {
Expand Down