Repository navigation
fix(nostr): DMs through a relay are lost after its connection drops - #174074
rodricksz4h5 wants to merge 2 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesResubscribe closed Nostr relay connections with backoff and replay missed DMs while preserving admission capacity. Example: Relay 2 restarts, then stores probe-102 before the Gateway reconnects.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR repairs a current Nostr delivery bug with convincing live evidence. The prior assertion finding is resolved, no new blocking defect was found, and current-head CI remains pending. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Nostr plugin receives encrypted relay events, admits them to the shared durable ingress queue, and dispatches authorized DMs to the agent. flowchart LR
Sender[Nostr sender] --> Relay[Nostr relay]
Relay --> Bus[Nostr bus]
Bus --> Queue[Durable ingress queue]
Queue --> Agent[Agent dispatch]
Bus --> Retry[Resubscription timer]
Retry --> Relay
Technical reviewBest possible solution: Keep reconnect scheduling in the existing Nostr bus and retain durable ingress dedupe, replay overlap, and shutdown settlement. Do we have a high-confidence way to reproduce the issue? Current-main source shows the one-shot subscription path, and the contributor supplies a concrete three-relay before/after reproduction; no target code was executed during this review. Is this the best way to solve the issue? The patch repairs the owning relay lifecycle without adding an SDK surface or competing persistence owner, and the additional admission safeguards address observed replay failures. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 27c21c171e94. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +68, Tests +241. Total +309 across 6 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed November 15, 2026, 3:55 PM ET / 20:55 UTC (Revision 5). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
27a7b13 to
426d852
Compare
|
Rebased onto current main (the subscription code moved into
Each test fails with its safeguard removed. The real strfry run on this head is in the body. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
426d852 to
2b31154
Compare
|
Rebased onto current main and fixed the two CI failures:
Behavior is unchanged: eviction only runs when the set holds more than 4096 ids. Locally the ratchet, type-aware oxlint (fails on the old line, passes on the new), oxfmt and |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Closes #174073
What Problem This Solves
Fixes: the Nostr channel stops receiving DMs through a relay for the rest of the Gateway's life after that relay's WebSocket closes (a relay restart, a crash, a network blip).
User Impact
User impact: when a relay connection drops, the channel subscribes to it again (after 10 s, backing off to once a minute) and receives the DMs sent through it, including ones the relay stored while the socket was down. No configuration change.
Why This Change Was Made
Each relay's DM subscription in
startNostrBusis opened once, at startup. When one closes, the bus only reportsSubscription closed. With two or more relays (the default) the channel keeps reporting connected, so the health monitor never restarts it, and every DM through the dropped relay is lost. nostr-tools' own reconnect does not cover this on Node: the socket fireserrorbeforecloseand nostr-tools turns reconnects off for a socket that had connected. So the bus now resubscribes a relay itself after an unexpected close, and never during shutdown or abort.Rebased onto current
main, where the per-relay subscription moved intonostr-bus.ts. The replay and admission rules follow the review:alreadyHaveEvent, a bounded set of 4096 ids; rejected events are never added, so they are retried). An event that still reaches durable admission and turns out to be a duplicate hands its rate-window slot back, so even an id that fell out of that set cannot starve a new DM.Evidence
A Gateway from source (this branch,
pnpm build), the Nostr channel and a scripted OpenAI-compatible provider in a Linux container, against three strfry relays in Docker. A second key ("alice") DMed the bot through relay 2 only and watched all three relays for replies. After a warm-up turn, relay 2 was restarted (docker restart); probe-102 was sent 6 s later, while relay 2 was back but before any resubscription, so the relay stored it.356931bbd)426d852d4)Trace from the PR run (all UTC):
Tests (
pnpm test, Linux, Node 24.22.1):nostr-bus.reconnect.test.ts(new): the real bus and nostr-tools pool against a loopback relay that stores DMs and replays them for each REQ'ssince; only the resubscribe backoff runs on a controlled clock.rate_limitedrejection;nostr-state-store.test.ts: a duplicate admission hands its rate-window slot back.since1793017805 > 1793017724).nostr-bus.reconnect,nostr-state-store,nostr-bus.inbound,nostr-cursor: 41 + 6 passed.pnpm tsgo:extensionspasses;oxlintandoxfmt --checkare clean on the changed files.Merge Risk
Two-way door: reverting restores the old behavior without touching stored state. Blast radius is the Nostr channel's relay subscriptions and its inbound admission count. A relay that keeps closing is retried once a minute, and a real EOSE resets the backoff; that includes a relay that refuses the DM subscription outright (for example strfry's default
auth-requiredfor kind 4), which is now retried once a minute with a log line each time. The duplicate refund only applies to events the durable queue already holds, which append nothing.Not covered: a socket that dies silently and never closes. Nothing detects it, before or after this change; #174073 describes it as a separate follow-up.