Skip to content

fix(transport)(sphere-sdk#559): opt out HMCP + ACP sendDM self-wraps#51

Merged
vrogojin merged 1 commit into
@vrogojin/uxffrom
fix/issue-559-selfwrap-optout
Jun 21, 2026
Merged

fix(transport)(sphere-sdk#559): opt out HMCP + ACP sendDM self-wraps#51
vrogojin merged 1 commit into
@vrogojin/uxffrom
fix/issue-559-selfwrap-optout

Conversation

@vrogojin

Copy link
Copy Markdown
Contributor

Summary

F3 from the #559 verdict comment. Wires { selfWrap: false } (new SDK API from sphere-sdk PR #558) into the two short-lived RPC paths the F1 soak identified as the biggest contributors to §3/§4 relay-index pollution:

  • src/transport/dm-transport.ts (HMCP — CLI → host manager)
  • src/trader/acp-transport.ts (ACP — CLI → trader tenant)

src/legacy/legacy-cli.ts:3961 (sphere message send) is not touched — that command is user-initiated and the user likely wants their sent DM in their own outbound history. Default behavior preserved.

Why

Both files implement short-lived RPC: the sphere host … / sphere trader … process publishes a single request, awaits the correlated reply, and exits. The default NIP-17 self-wrap publishes a SECOND gift-wrap targeting the SENDER's own pubkey so a returning client can replay outbound history — useless work for one-shot CLI, and exactly the noise the F1 soak measured at ~7 new events per spawn process in §3 of manual-test-trader-roundtrip.sh. Cutting the self-wrap halves the per-process publish count and removes the corresponding entries from the relay's #p:controller index for the next short-lived CLI process to pull down on subscribe.

The fix is a strict subset of what sphere-sdk PR #558 was designed for — see #558's own description: "For short-lived senders (one-shot CLI RPC like sphere trader portfolio) the process exits before it could ever read its own self-wrap, making the second publish pure relay-index pollution."

What changed

Both dm-transport.ts and acp-transport.ts:

  • Widen the local SphereComms.sendDM interface to forward an optional SendMessageOptions to the SDK call.
  • Pass { selfWrap: false } at the only outgoing sendDM call site.

Net diff: 2 files changed, 24 insertions(+), 6 deletions(-).

Test plan

  • npx tsc --noEmit → no new errors (3 pre-existing errors in legacy-cli.ts confirmed by stashing F3 and re-running)
  • npx vitest run --reporter=basic187/187 pass (incl. 14 dm-transport, 19 spawn, 44 trader-commands)
  • (Follow-up) Re-run F1 soak with F3 + sphere-sdk #558 both landed; expect per-spawn new-event count to drop from ~7 to ~3-4 (HM responses remain, CLI self-wraps gone)

Related

  • sphere-sdk#555 — original M8 mitigation framing
  • sphere-sdk#559 — fresh-wallet backlog + F1 soak verdict
  • sphere-sdk PR #558 — selfWrap: false SDK API (merged into uxf)
  • sphere-sdk PR #582 — F1 instrumentation (open, awaiting follow-up soak)
  • sphere-sdk PR #614 — re-export SendMessageOptions from index.ts (merged, prereq for this PR's typecheck)

F3 from sphere-sdk#559. Wires `{ selfWrap: false }` into the two
short-lived RPC paths the F1 soak identified as the biggest
contributors to §3/§4 relay-index pollution:

  - src/transport/dm-transport.ts (HMCP — CLI → host manager)
  - src/trader/acp-transport.ts   (ACP  — CLI → trader tenant)

Both are short-lived RPC: the `sphere host …` / `sphere trader …`
process publishes a single request and exits as soon as the reply
correlates. The default NIP-17 self-wrap publishes a SECOND
gift-wrap targeting the SENDER's own pubkey so a returning client
can replay outbound history — useless work for one-shot CLI, and
exactly the noise the F1 soak measured at ~7 new events per spawn
process in §3 of `manual-test-trader-roundtrip.sh`.

Both files also widen their local `SphereComms.sendDM` interface
to forward an optional `SendMessageOptions` to the SDK call.

`sphere message send` in src/legacy/legacy-cli.ts:3961 is NOT
touched — that command is user-initiated and the user likely
wants their sent DM in their own outbound history. Default
behavior preserved.

## Validation

  - npx tsc --noEmit  → no new errors (3 pre-existing in legacy-cli
                        unrelated to F3, confirmed by stashing F3
                        and re-running)
  - npx vitest run    → 187/187 pass

## Related

  - sphere-sdk#555 — original M8 mitigation framing
  - sphere-sdk#559 — fresh-wallet backlog + F1 soak verdict
  - sphere-sdk PR #558 — selfWrap: false SDK API (merged into uxf)
  - sphere-sdk PR #582 — F1 instrumentation (open, awaiting follow-up soak)
  - sphere-sdk PR #614 — re-export SendMessageOptions from index.ts (merged)
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.

1 participant