Skip to content

feat(connectivity): dual-strategy presence/inbox/invites + refcounted merge (#47 C1) - #71

Merged
scotej merged 1 commit into
mainfrom
feat/47-c1-dual-strategy
Jul 10, 2026
Merged

feat(connectivity): dual-strategy presence/inbox/invites + refcounted merge (#47 C1)#71
scotej merged 1 commit into
mainfrom
feat/47-c1-dual-strategy

Conversation

@scotej

@scotej scotej commented Jul 10, 2026

Copy link
Copy Markdown
Owner

What

pair.ts was the only dual-strategy call site; inbox, presence, invite send, and session rooms were Nostr-only (ARCHITECTURE §4.2). Post-v1.3.1 this was incoherent: a friend behind a Nostr-blocking firewall can now be added (offline ContactCard) but then shows permanently offline, every invite dies, and no session can rendezvous — the friendship is inert.

Changes

  1. mergeRooms refcounted peer tracking (prerequisite found during this pass): the old shared-dedup-set fired the consumer's onPeerLeave when ONE transport dropped even though the peer was still connected on the other, and its per-subscriber registration starved second subscribers. Tracking is now registered once at construction (mirroring wrapRoom's fan-out): join fires on the first transport that sees a peer, leave only when the last loses them.
  2. Presence (own + friend rooms), inbox, invite sendstrategies: ['nostr', 'mqtt']. Duplicate delivery of one logical message over both transports is absorbed per consumer — idempotent heartbeat stamps, the PR-18 (from, nonce) inbox replay guard, the latched invite-ACK (C2) — documented at the merge site.
  3. Invite timeout classifier switches to the both-transports pairingRelaysUnreachable (PR-21 rationale) so a Nostr-blocked/MQTT-working network isn't misreported as down.
  4. Session rooms deliberately stay Nostr-only — duplicate RTCPeerConnections would double video; the issue scopes that as a separate design pass. ARCHITECTURE §4.2 rewritten to match; relayDiagnostics comments updated.

Interplay with I48 noted per the issue: a persistent inbox/presence MQTT connection sidesteps the recorded reconnect-leak; the justification here is functionality.

Addresses item C1 of #47 (phase 1 as scoped).

Tests / gates

  • trystero-merge.test.ts +2: single-transport drop fires no leave / last-transport drop fires one; multi-subscriber fan-out.
  • Presence/inbox/invite integration suites green (bus mock is transport-agnostic).
  • build, lint, vitest (708), check-tokens/strings, prettier.
  • Manual: not machine-walked (needs a second peer on a Nostr-blocked network); the merge path is the same shipped code pairing exercises daily.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Improved delivery reliability for pairing, presence, inbox, and invite messages by using multiple transport paths.
    • Added cross-transport peer tracking to prevent duplicate join/leave events and avoid premature disconnects.
    • Kept media connections on a single transport to prevent duplicate WebRTC sessions.
  • Bug Fixes

    • Duplicate messages are safely ignored, improving invite and heartbeat handling.
    • Invite timeout reporting now more accurately distinguishes relay connectivity issues from recipient unavailability.
  • Documentation

    • Updated architecture and diagnostics documentation to reflect multi-transport delivery behavior.

…(C1 phase 1)

pair.ts was the only dual-strategy call site; inbox, presence, and
invite send were Nostr-only. Post-v1.3.1 that was incoherent: a friend
behind a Nostr-blocking firewall can now be ADDED (offline ContactCard)
but then showed permanently offline, every invite died, and the
friendship was inert.

- mergeRooms gains refcounted per-peer transport tracking, registered
  once at construction and fanned out to subscribers: join fires when
  the FIRST transport sees a peer, leave only when the LAST loses them.
  (The old shared-dedup-set fired leave on a single-transport drop and
  starved second subscribers — tolerable for short-lived pairing rooms,
  wrong for long-lived ones.)
- presence (own + friend rooms), the inbox, and the invite send path
  pass strategies ['nostr','mqtt']. Duplicate delivery over both
  transports is absorbed per consumer: idempotent heartbeat stamps, the
  PR-18 (from, nonce) inbox replay guard, the latched invite-ACK.
- the invite timeout's network-down verdict now judges both transports
  (pairingRelaysUnreachable, same PR-21 rationale as pairing)
- session rooms deliberately stay Nostr-only: two transport rooms would
  open duplicate RTCPeerConnections and double video — needs its own
  design pass. ARCHITECTURE §4.2 updated.

Fixes #47 item C1 (phase 1 as scoped by the issue).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 10, 2026 08:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e166c85a-7d74-442e-a659-f428fe269774

📥 Commits

Reviewing files that changed from the base of the PR and between 2355a6e and 77ce3ac.

📒 Files selected for processing (7)
  • ARCHITECTURE.md
  • src/features/friends/inbox.ts
  • src/features/friends/invite.ts
  • src/features/friends/presence.ts
  • src/lib/relayDiagnostics.ts
  • src/lib/trystero/index.ts
  • tests/unit/trystero-merge.test.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: CodeRabbit / Review
  • GitHub Check: Rust (macOS)
  • GitHub Check: Frontend
  • GitHub Check: Rust (Windows)
🧰 Additional context used
📓 Path-based instructions (7)
**/*

📄 CodeRabbit inference engine (CLAUDE.md)

**/*: Before committing or opening a PR, run the required build, lint, test, design-token, strings, contrast, accessibility, formatting, and relevant Rust quality gates.
Use one focused change per commit with a Conventional Commit subject such as feat:, fix:, chore:, docs:, or ci:; PRs should squash-merge.

Files:

  • ARCHITECTURE.md
  • src/features/friends/invite.ts
  • src/lib/relayDiagnostics.ts
  • tests/unit/trystero-merge.test.ts
  • src/features/friends/presence.ts
  • src/features/friends/inbox.ts
  • src/lib/trystero/index.ts
src/**/*.{ts,tsx,css}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{ts,tsx,css}: Use design tokens instead of hard-coded visual values in frontend TypeScript, TSX, and CSS files.
Meet WCAG AA requirements for every text/background pairing in both themes; do not convey information by color alone.
Respect reduced-motion preferences through the global kill switch; new motion sites must be gated by default.

Files:

  • src/features/friends/invite.ts
  • src/lib/relayDiagnostics.ts
  • src/features/friends/presence.ts
  • src/features/friends/inbox.ts
  • src/lib/trystero/index.ts
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{ts,tsx}: Keep JSX text and aria-label literals consistent with the voice defined in DESIGN-SYSTEM.md §14, and prefer centralized strings.
Treat peer wire formats and identity derivation as cross-version contracts; coordinate changes so older peers and existing stored data remain compatible.
Do not add telemetry; the application must remain local-only.

Files:

  • src/features/friends/invite.ts
  • src/lib/relayDiagnostics.ts
  • src/features/friends/presence.ts
  • src/features/friends/inbox.ts
  • src/lib/trystero/index.ts
src/**/*.{ts,tsx,rs}

📄 CodeRabbit inference engine (CLAUDE.md)

Never instruct users to paste a model file or BIP39 mnemonic into an AI service or chat.

Files:

  • src/features/friends/invite.ts
  • src/lib/relayDiagnostics.ts
  • src/features/friends/presence.ts
  • src/features/friends/inbox.ts
  • src/lib/trystero/index.ts
**/*.{ts,tsx,rs}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,rs}: Add comments only when the reason is non-obvious; identifiers should carry meaning and code should read top-to-bottom.
Maintain scope discipline: do not refactor adjacent code during feature work or add abstractions for hypothetical future needs.

Files:

  • src/features/friends/invite.ts
  • src/lib/relayDiagnostics.ts
  • tests/unit/trystero-merge.test.ts
  • src/features/friends/presence.ts
  • src/features/friends/inbox.ts
  • src/lib/trystero/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use TypeScript strict mode and ensure frontend code passes the TypeScript build and type checks.

Files:

  • src/features/friends/invite.ts
  • src/lib/relayDiagnostics.ts
  • tests/unit/trystero-merge.test.ts
  • src/features/friends/presence.ts
  • src/features/friends/inbox.ts
  • src/lib/trystero/index.ts
**/*.test.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Write Vitest tests for applicable unit and integration behavior; component tests are not currently supported without an explicit test-harness scope expansion.

Files:

  • tests/unit/trystero-merge.test.ts
🔇 Additional comments (7)
src/lib/trystero/index.ts (1)

6-12: LGTM!

Also applies to: 225-272, 288-296

tests/unit/trystero-merge.test.ts (1)

150-178: LGTM!

Also applies to: 180-194

src/features/friends/invite.ts (1)

4-4: LGTM!

Also applies to: 174-186

src/features/friends/inbox.ts (1)

175-178: LGTM!

src/features/friends/presence.ts (1)

123-127: LGTM!

Also applies to: 162-163

src/lib/relayDiagnostics.ts (1)

46-46: LGTM!

Also applies to: 84-85

ARCHITECTURE.md (1)

138-138: LGTM!


📝 Walkthrough

Walkthrough

Discovery data rooms now explicitly race Nostr and MQTT. Merged rooms track peers across transports with refcounted join/leave events, while invite reachability and architecture documentation reflect the updated behavior. Media sessions remain Nostr-only.

Changes

Dual-transport discovery

Layer / File(s) Summary
Refcounted transport merging and validation
src/lib/trystero/index.ts, tests/unit/trystero-merge.test.ts
Merged rooms track each peer across transport indices, emit leave only after the final transport disconnects, and fan out join callbacks to all subscribers.
Discovery room wiring and reachability contracts
src/features/friends/invite.ts, src/features/friends/inbox.ts, src/features/friends/presence.ts, src/lib/relayDiagnostics.ts, ARCHITECTURE.md
Invite, inbox, and presence rooms use Nostr and MQTT; invite reachability uses pairingRelaysUnreachable, with comments documenting duplicate handling and Nostr-only media sessions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FriendClient
  participant DiscoveryRooms
  participant Nostr
  participant MQTT
  participant InviteConsumer
  FriendClient->>DiscoveryRooms: join invite, inbox, or presence room
  DiscoveryRooms->>Nostr: establish data-room transport
  DiscoveryRooms->>MQTT: establish data-room transport
  Nostr-->>InviteConsumer: deliver envelope or heartbeat
  MQTT-->>InviteConsumer: deliver envelope or heartbeat
  InviteConsumer->>InviteConsumer: replay guard or idempotent handling
Loading

Possibly related PRs

  • scotej/studyvis#45: Introduces related MQTT pairing reachability and relay plumbing used by this dual-transport discovery flow.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: dual-strategy connectivity for presence/inbox/invites plus refcounted merge logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/47-c1-dual-strategy

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@scotej
scotej merged commit b284622 into main Jul 10, 2026
4 checks passed
@scotej
scotej deleted the feat/47-c1-dual-strategy branch July 10, 2026 09:04
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.

2 participants