feat: reply OK to client-published events #3

Merged
padreug merged 2 commits from feat/ok-reply into main 2026-09-12 12:40:50 +00:00
Owner

Problem

nostrclient never answered a client's EVENT with the NIP-01 ["OK", <id>, <accepted>, <message>] command result. Clients built on nostr-tools and similar libraries wait for that reply before treating a publish as successful, so NWC wallet apps paired against wss://<host>/nostrclient/api/v1/relay reported "publish failed" even though the request had been fanned out to the upstream relays and answered by nwcprovider.

Upstream lnbits/nostrclient has the same gap (checked at ae674ef, 2026-07-13).

Change

  • nostr/message_pool.py — parse relay OK messages into a CommandResultMessage queue, alongside events / notices / EOSE.
  • nostr/client/client.py — pump that queue through a new callback_command_results_func.
  • tasks.py — store results keyed by event id, but only for ids some connected client is still waiting on (keeps the shared map bounded).
  • router.py — track each EVENT a client publishes (PendingPublish) and reply exactly one OK:
    • true as soon as any relay accepts (multiplexer semantics: the event is out there),
    • false once every relay connected at publish time has rejected it, with the last rejection message,
    • false after a 10 s timeout,
    • false immediately when no relay is connected.
    • Events without an id are ignored (nothing to acknowledge).
  • tests/test_router_ok.py — 6 unit tests covering the cases above, run against stubbed websocket + relay manager.
  • README: documents the acknowledgement step.
  • Version bumped to 1.2.0-aio.2 (separate commit).

Verification

  • black, ruff, mypy: clean.
  • pytest: 7 passed (6 new + existing test_init).
  • Not yet exercised against a live wallet app; that is the deploy-time smoke test (see release steps below).

Release steps after merge

  1. git tag v1.2.0-aio.2 && git push origin v1.2.0-aio.2
  2. sha256 of the archive, add a new entry to aiolabs/lnbits-extensions/extensions.json (keep 1.2.0-aio.1).
  3. Upgrade nostrclient on four84 via the LNbits UI, re-pair the NWC wallet.

🤖 Generated with Claude Code

https://claude.ai/code/session_013Tbyw6FwjhEJg3gHfPHxWt

## Problem nostrclient never answered a client's `EVENT` with the NIP-01 `["OK", <id>, <accepted>, <message>]` command result. Clients built on nostr-tools and similar libraries wait for that reply before treating a publish as successful, so NWC wallet apps paired against `wss://<host>/nostrclient/api/v1/relay` reported **"publish failed"** even though the request had been fanned out to the upstream relays and answered by nwcprovider. Upstream `lnbits/nostrclient` has the same gap (checked at `ae674ef`, 2026-07-13). ## Change - `nostr/message_pool.py` — parse relay `OK` messages into a `CommandResultMessage` queue, alongside events / notices / EOSE. - `nostr/client/client.py` — pump that queue through a new `callback_command_results_func`. - `tasks.py` — store results keyed by event id, but only for ids some connected client is still waiting on (keeps the shared map bounded). - `router.py` — track each `EVENT` a client publishes (`PendingPublish`) and reply exactly one `OK`: - `true` as soon as **any** relay accepts (multiplexer semantics: the event is out there), - `false` once every relay connected at publish time has rejected it, with the last rejection message, - `false` after a 10 s timeout, - `false` immediately when no relay is connected. - Events without an `id` are ignored (nothing to acknowledge). - `tests/test_router_ok.py` — 6 unit tests covering the cases above, run against stubbed websocket + relay manager. - README: documents the acknowledgement step. - Version bumped to `1.2.0-aio.2` (separate commit). ## Verification - `black`, `ruff`, `mypy`: clean. - `pytest`: 7 passed (6 new + existing `test_init`). - Not yet exercised against a live wallet app; that is the deploy-time smoke test (see release steps below). ## Release steps after merge 1. `git tag v1.2.0-aio.2 && git push origin v1.2.0-aio.2` 2. sha256 of the archive, add a **new** entry to `aiolabs/lnbits-extensions/extensions.json` (keep `1.2.0-aio.1`). 3. Upgrade nostrclient on four84 via the LNbits UI, re-pair the NWC wallet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013Tbyw6FwjhEJg3gHfPHxWt
nostrclient never answered a client's EVENT with the NIP-01
`["OK", <id>, <accepted>, <message>]` command result. Clients built on
nostr-tools and similar libraries wait for that reply before treating a
publish as successful, so NWC wallet apps paired through the public
endpoint reported "publish failed" even though the request had been
fanned out and answered.

Relay OKs now flow through the message pool like events and notices.
The router tracks each EVENT a client publishes and replies exactly
once: `true` as soon as any relay accepts, `false` once every relay
connected at publish time has rejected it, after a 10 s timeout, or
immediately when no relay is connected. OKs nobody is waiting on are
dropped at the pump so the shared result map cannot grow unbounded.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Tbyw6FwjhEJg3gHfPHxWt
chore: bump version to 1.2.0-aio.2
Some checks failed
ci.yml / chore: bump version to 1.2.0-aio.2 (pull_request) Failing after 0s
98e5accdd0
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Tbyw6FwjhEJg3gHfPHxWt
padreug deleted branch feat/ok-reply 2026-09-12 12:40:50 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/nostrclient!3
No description provided.