Skip to content

nostreamd: the daemon still runs on unavailable::stores(), so it serves the wire and stores nothing #1206

Done

Description

@chappie-daemon

Measured on rewrite/main at ff045445: crates/nostreamd/src/main.rs resolves the storage backend name, logs it, and then builds the relay over nostream_services::unavailable::stores() and nostream_relay::unavailable::stores(). The comment above the two lines says so plainly: the LMDB environment is a stub, so the wire is served in full and nothing is stored. crates/nostreamd/src/mcp_stdio.rs:78 composes the same empty bundle for the MCP door, so there are two sites, not one.

Where the wiring already exists

The pattern is not to be designed: the CLI already does it. crates/nostream-cli/src/store.rs has selected_backend(settings) (:65) reading the configured backend, Opened (:25-28) as the enum over LmdbBackend and PostgresBackend, accessors that hand out the repositories whatever answered (events :32, invites :40, invoices :48, users :56), and open() (:97) as the one match over the backend.

The gap is scope, measured: Opened exposes 4 repositories, while the two bundles the daemon needs cover 9 between them —

  • relay Stores (crates/nostream-relay/src/handlers/mod.rs:61-68): events, users, nip05, invites, dvm_jobs, reports
  • services ServiceStores (crates/nostream-services/src/unavailable.rs:24-32): events, users, invoices, nip05, dvm_jobs, notification_outbox, notification_delivery_log

The five Opened does not expose are already implemented by both backends — nip05 (lmdb/mod.rs:893, postgres/repository.rs:249), dvm_jobs (lmdb/mod.rs:1012, postgres/repository.rs:308), reports (lmdb/mod.rs:1075, postgres/repository.rs:339), outbox (lmdb/mod.rs:1169, postgres/repository.rs:402), delivery log (lmdb/mod.rs:1122, postgres/repository.rs:372) — so the work is to expose them and compose the two bundles, not to write repositories.

Also in scope

  • LMDB has no transaction type. The payments flow that needs BEGIN ISOLATION LEVEL SERIALIZABLE is PostgresTransaction-only, so the same code path has no atomic equivalent on LMDB, and no crate doc flags it.
  • user_subscriptions has no repository trait. Nine of ten repositories are ported; the tenth is the subscriptions/payments surface.

Acceptance:

  • nostreamd boots on the LMDB backend and stores an event that a second process reads back after a restart.
  • The same on Postgres, from the same binary, selected by configuration rather than by rebuild.
  • --mcp-stdio composes the same wired stores as the relay door; neither path builds unavailable::stores().
  • The storage parity suite runs against the daemon's own composition, not only against the crate's seams.
  • The payments write path either gets an LMDB transaction equivalent or refuses with a typed error naming the backend, and the limitation is written down where the flow is defined.

Activity

  1. added
    rewrite
    rust
    on Nov 21, 2026
  2. cameri commented on Nov 21, 2026

    @cameri
    Owner

    One thing that makes this smaller than it looks: the wiring pattern already exists — the CLI does it. crates/nostream-cli/src/store.rs open() picks the backend through selected_backend() (configured_backend), opens LmdbBackend::open(root) or Postgres, and hands the repositories out through Opened. The daemon can follow that instead of designing the wiring from scratch.

    The gap is scope, not design. Opened exposes 4 repositories (events, invites, invoices, users); the two bundles the daemon needs cover 9 between them — services ServiceStores (events, users, invoices, nip05, dvm_jobs, notification_outbox, notification_delivery_log) and relay Stores (handlers/mod.rs:61-68: events, users, nip05, invites, dvm_jobs, reports). The other five are already implemented by both backends (nip05: lmdb/mod.rs:893, postgres/repository.rs:249; dvm_jobs: lmdb/mod.rs:1012, postgres/repository.rs:308; reports: lmdb/mod.rs:1075, postgres/repository.rs:339; outbox: lmdb/mod.rs:1169, postgres/repository.rs:402; delivery log: lmdb/mod.rs:1122, postgres/repository.rs:372), so the remaining work is exposing them and composing the two bundles — plus the LMDB-transaction point already in the issue.

  3. chappie-daemon commented on Nov 21, 2026

    @chappie-daemon
    CollaboratorAuthor

    Verified all of it at ff045445 and folded it into the body, so whoever picks this up starts from the CLI's pattern rather than re-deriving it:

    • Opened has exactly four accessors — events :32, invites :40, invoices :48, users :56 — over selected_backend :65 and open :97
    • relay Stores is six (handlers/mod.rs:61-68), services ServiceStores is seven (unavailable.rs:24-32), union nine
    • spot-checked two of the five already-implemented ones: impl Nip05VerificationRepository for LmdbBackend at lmdb/mod.rs:893 and impl ReportRepository for PostgresBackend at postgres/repository.rs:339

    One addition: the daemon has a second composition point — mcp_stdio.rs:78 builds the same unavailable::stores() bundle for the MCP door — so the acceptance now names both paths and fails if either one still composes an empty bundle. That also makes the parity test meaningful: it has to run through the daemon's own composition, because a crate's seams being green is exactly what let this gap survive three merged jobs.

  4. AgrimTawani commented on Nov 28, 2026

    @AgrimTawani
    Contributor

    Hey @cameri, I'd like to take this on next.

    My approach would be:

    • Grow the CLI's Opened to expose all nine repositories and build both the relay and services store bundles from it
    • Use that in main.rs and mcp_stdio.rs, so neither one builds unavailable::stores() anymore
    • Add a restart test on LMDB and Postgres, and have the LMDB payments path refuse with a typed error
  5. cameri commented on Nov 28, 2026

    @cameri
    Owner

    @AgrimTawani Assigned to you

  6. AgrimTawani commented on Nov 29, 2026

    @AgrimTawani
    Contributor

    Hey @cameri, the fix for this is ready on AgrimTawani:fix/1206-daemon-real-stores (one commit, bb0b2d9, on the latest rewrite/main):

    • Wiring: a shared nostream_storage::Repositories (nine handles over one opened backend, also behind the CLI's Opened now) feeds both Stores and ServiceStores; nostreamd --data-dir opens it for the relay door and --mcp-stdio alike, and LMDB without the flag or an unreachable Postgres refuses to start instead of serving an empty store
    • LMDB second process: --mcp-stdio beside a running relay is the case ADR 0012 D9 said would overturn it, so open also takes a file lock across the search-index check and rebuild (ADR amended); the payments write-path limitation is written on confirm_invoice (three writes, no transaction, on either backend)
    • Tests: a new store_wiring target publishes to one daemon and reads the event back from a second on LMDB and on Postgres (added to CI as "Daemon store against Postgres"); the MCP tests now prove real reads and writes; the five checks and the Postgres suites pass locally
  7. chappie-daemon commented on Nov 29, 2026

    @chappie-daemon
    CollaboratorAuthor

    Shipped in PR #1281, merged as 1514e7f2e84806f5e3320dbb03b536aa19aba7d7 on rewrite/main at 2026-11-29T14:42Z. Closes is inert because the base is not the repository's default branch, so this closes by hand.

    The daemon opens the store its settings name and hands the same nine repositories to both doors; LMDB without --data-dir and an unreachable Postgres both refuse to start. Accepted throughput is no longer 0, so #868's benchmark gate and 72 h soak rows can measure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

rewriterust

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions