You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(payments): send the NWC subscription before the request it asks about - #1104
Closes nothing by keyword: base is rewrite/main, not the repository's default branch. #1099 is closed by hand after the merge.
An NWC (NIP-47) call could lose its answer. The processor sent its EVENTbefore its REQ, so a wallet that replies the moment it decrypts the request published into a socket with no subscription: kind-23195 replies are ephemeral (the strategy broadcasts and stores nothing), and live dispatch writes only to subscriptions already registered. The reply was not delayed for us — it was gone, and the payment call blocked until it timed out. One hop away, a self-hosted wallet on the same relay is exactly the shape that loses.
The change
- for frame in [event_frame, request_frame] {
+ for frame in [request_frame, event_frame] {
plus the four-line comment at that site stating the obligation, and the test infrastructure that can see the defect.
No reader change was needed, and that was measured rather than assumed: a dependency-free socket probe shows a reply written while the client is not yet reading survives to the later read; tokio-tungstenite reads on poll; and the existing in-tree test already sends and closes before the client's read loop. The read loop, filter, subscription id, encryption and error arms are byte-identical to base — the production diff is one hunk, one line removed and one added.
The oracle, and why it is the assertion
A plain ordering assertion is not enough, and this PR is careful about the difference. tests/nwc_relay.rs already had a relay() helper that waits for both frames before replying — which is precisely why its four tests were green at base. The new strict_relay double answers inside its EVENT arm and only when a REQ registered a subscription; otherwise it drops the reply, records that it dropped, and closes.
Red at 4adaa42, with the base production file restored over the fix:
running 1 test
test a_reply_published_the_moment_the_wallet_sees_the_event_is_received ... FAILED
panicked at crates/nostream-services/tests/nwc_relay.rs:229:5:
assertion `left == right` failed
left: ["EVENT"]
right: ["REQ", "EVENT"]
test result: FAILED. 0 passed; 1 failed; 4 filtered out (finished in 0.00s, exit 101)
Green at head: 1 passed; the whole target 5 passed; 0 failed.
The trap, measured both ways: a tolerant double (one that waits for the REQ) also fails at base — but only on that same order assertion, and with the assertion deleted it goes green at base. So the assert_eq!(seen.verbs(), ["REQ", "EVENT"]) is the whole oracle; the dropped flag is an invariant inside the double, kept so a future tolerance fails loudly.
What would make this test stop being red at base: making the double tolerant, or dropping the order assertion. Both are recorded in spec.md's Assumptions so a future author does not "simplify" the harness back into the shape that hid the defect.
The four ignored are the #[ignore]d Postgres-backed storage targets, unchanged by this branch.
What the review did not look at
security, performance, ux, ui stood down with checkable reasons in review-plan.json: the production hunk swaps two elements of one array literal feeding the same two socket.send calls, and the other paths are a tests/ target and a changeset. The reply's authentication (wallet pubkey, id, signature, e-tag correlation) is outside the hunk and its test a_forged_reply_is_ignored is green at base.
The double is filter-blind and has no OK/EOSE, so a future fix that waits for an ack would hang rather than fail — worth closing when someone next touches this transport.
The wallet-reply construction is duplicated between relay() and strict_relay; a wallet_reply(..) beside Published is the cheap repair when a third double appears.
nostream_relay::testing is public and database-free, so a services test could drive the real Relay on loopback instead of a hand model; that is a bigger test-infrastructure change than this job.
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 74d645b3-8951-4bba-9baa-70c759129916
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes nothing by keyword:
baseisrewrite/main, not the repository's default branch. #1099 is closed by hand after the merge.An NWC (NIP-47) call could lose its answer. The processor sent its
EVENTbefore itsREQ, so a wallet that replies the moment it decrypts the request published into a socket with no subscription: kind-23195replies are ephemeral (the strategy broadcasts and stores nothing), and live dispatch writes only to subscriptions already registered. The reply was not delayed for us — it was gone, and the payment call blocked until it timed out. One hop away, a self-hosted wallet on the same relay is exactly the shape that loses.The change
plus the four-line comment at that site stating the obligation, and the test infrastructure that can see the defect.
No reader change was needed, and that was measured rather than assumed: a dependency-free socket probe shows a reply written while the client is not yet reading survives to the later read;
tokio-tungstenitereads on poll; and the existing in-tree test already sends and closes before the client's read loop. The read loop, filter, subscription id, encryption and error arms are byte-identical to base — the production diff is one hunk, one line removed and one added.The oracle, and why it is the assertion
A plain ordering assertion is not enough, and this PR is careful about the difference.
tests/nwc_relay.rsalready had arelay()helper that waits for both frames before replying — which is precisely why its four tests were green at base. The newstrict_relaydouble answers inside itsEVENTarm and only when aREQregistered a subscription; otherwise it drops the reply, records that it dropped, and closes.Red at
4adaa42, with the base production file restored over the fix:Green at head:
1 passed; the whole target5 passed; 0 failed.The trap, measured both ways: a tolerant double (one that waits for the
REQ) also fails at base — but only on that same order assertion, and with the assertion deleted it goes green at base. So theassert_eq!(seen.verbs(), ["REQ", "EVENT"])is the whole oracle; thedroppedflag is an invariant inside the double, kept so a future tolerance fails loudly.What would make this test stop being red at base: making the double tolerant, or dropping the order assertion. Both are recorded in
spec.md's Assumptions so a future author does not "simplify" the harness back into the shape that hid the defect.Validation
The four ignored are the
#[ignore]d Postgres-backed storage targets, unchanged by this branch.What the review did not look at
review-plan.json: the production hunk swaps two elements of one array literal feeding the same twosocket.sendcalls, and the other paths are atests/target and a changeset. The reply's authentication (wallet pubkey, id, signature,e-tag correlation) is outside the hunk and its testa_forged_reply_is_ignoredis green at base.static/round-1.jsonread0 findingsbecause it was 0 findings from 0 providers — greptile was not signed in where this was built and the key could not be decrypted. That record is preserved asstatic/round-1.zero-provider.json. The same stage was then run at this head with a working key: 4 findings from 1 provider, zero of them in this change, four pre-existing repository defects — dvm: a dispatch tick can hand a job to a worker thathandle_exitthen clears #1096 (dvm_orchestrator.rs:413), import: an imported kind-5 with onlyatags leaves the article readable #1097 (event_import_service.rs:531), dvm: a worker that closes stdout can no longer be killed #1102 (dvm_orchestrator.rs:596,drive_workerstops pollingkilledonce stdout closes then blocks inwait()) and maintenance: a timed-out purge is detached, not stopped, so purges accumulate #1103 (maintenance.rs:125, a timed-out purge detached rather than aborted, its outcome never read). None is innwc_relay.rs, its test or the changeset.Follow-ups the lenses named, not fixed here
OK/EOSE, so a future fix that waits for an ack would hang rather than fail — worth closing when someone next touches this transport.relay()andstrict_relay; awallet_reply(..)besidePublishedis the cheap repair when a third double appears.nostream_relay::testingis public and database-free, so a services test could drive the realRelayon loopback instead of a hand model; that is a bigger test-infrastructure change than this job.