Skip to content

feat(import): consented conversation import with original timestamps (NIP-CI) - #8981

Draft
jaykurian wants to merge 5 commits into
block:mainfrom
jaykurian:jkurian/conversation-import
Draft

jaykurian wants to merge 5 commits into
block:mainfrom
jaykurian:jkurian/conversation-import

Conversation

@jaykurian

Copy link
Copy Markdown

What

Relay side of NIP-CI: people in a conversation on another platform can import its history into a Buzz channel or DM with the original timestamps. Each participant signs only their own messages, and only after every participant has consented to the same manifest.

How

  • Drift check. Only a well-formed import-tagged kind:9 or kind:7 skips the drift check (check_timestamp_drift, unit-tested). It is stored only if the session rules hold in the storage transaction: active session, matching channel and source type, a consenting participant, in range, under the declared count, and a reaction target imported under the same proposal.

  • Replica fence (own commit). Imported rows are older than the commit-time floor guard (migration 0021). The import transaction disarms the floor for itself only, with a test that a plain old write on the same connection is still refused afterwards. Covered replica reads (channel windows, channel-pinned queries, thread pages) go to the writer while the reader snapshot shows an active, unexpired import session for that channel; a thread root the snapshot lacks stays on the replica. 0021 is checksum-frozen, so the exception is documented in 0081, replica_fence.rs and docs/database.md. The commit body carries a reviewer ask for a replica-fence owner.

  • Warm-up. A session accepts imports only from activated_at + 75 s (fence proof retention 60 s plus a 15 s margin), so every replica shows the session active before the first backdated row commits. Until then imports are refused with invalid: import session warming (retryable) and the active 30623 snapshot carries ["accepts_after", "<unix seconds>"]. resolve now also refuses fence proofs older than retention.

  • Active-session caps. BUZZ_IMPORT_MAX_ACTIVE_SESSIONS_PER_CHANNEL (default 2) and BUZZ_IMPORT_MAX_ACTIVE_SESSIONS_PER_PROPOSER (default 8), counted under advisory locks, so a member cannot pin channels to the writer at will. A resend of a stored proposal is still answered duplicate:.

  • Atomic writes. Rules 2 to 7 are re-checked under the session row lock, in the same transaction that inserts the event and increments the author's counter. Concurrent publishes cannot overshoot a declared count. A resent event, control events included, returns duplicate: even after expiry.

  • No agents. Imported history never reaches agents, on push or pull paths:

    • REQ history, search and every /query mode drop import-tagged events for agent-authenticated readers (fail closed on a lookup error)
    • proposals naming an agent participant are refused
    • DM or private destinations with an agent member are refused, at proposal time and on every imported event
    • live fan-out skips agent-authenticated connections
    • buzz-acp drops imported events from thread and DM context
  • Limits. Declared counts are capped per participant and per session (BUZZ_IMPORT_MAX_EVENTS_PER_PARTICIPANT default 50000, BUZZ_IMPORT_MAX_EVENTS_PER_SESSION default 200000). The range starts no earlier than 2000-01-01 and ends in the past. Imports use their own rate limit (BUZZ_RATE_LIMIT_IMPORT_EVENTS_PER_MIN, default 600). BUZZ_IMPORT_SESSION_MAX_DAYS (default 30) caps session lifetime.

  • Strict control records. Each control kind accepts only its spec tags. A consent must name the proposer. A participant who has left the channel can still send kind:42113.

  • DMs. The participant set must equal the DM member set, at proposal time and again on every imported event.

  • Quiet writes. Imported events are stored, searchable, audited and fanned out to human channel readers. They produce:

    • no mention rows
    • no listener outbox entry
    • no push
    • no unread evidence
    • no thread last_reply_at bump
    • no channel TTL refresh
    • no workflow trigger
    • no buzz-acp match

    Control records are live activity and do create mention rows.

  • Snapshot. Republished after each control event, on lazy expiry, and every 50 accepted events per participant. It is stored in the session's channel, so it uses the channel read gate.

  • Storage. Migration 0081, plus the desired-state schema, deletion inventory, purge coverage and catalog parity for both tables.

Risk

  • Covered-read soundness needs the activation transaction to commit within the 15 s margin (lock and statement timeouts are set below it) and relay and database clocks to agree within that margin.
  • An agent can still learn that imported events exist: COUNT, thread-summary overlays and cursors expose ids, counts and participant pubkeys, never content. Documented in NIP-CI.md.
  • One member can hold up to the per-proposer cap of active sessions for the session lifetime, pinning those channels' covered reads to the writer. Bounded by the caps.
  • A DM member can still add a third person with kind:9000. Imports stop when that happens, but DM membership itself is not fixed.

How to test

just test-unit
DATABASE_URL=postgres://buzz:buzz_dev@localhost:5432/buzz \
  cargo test -p buzz-db --lib \
-- --ignored import_session purge_postgres_removes_import_session_rows
DATABASE_URL=postgres://buzz:buzz_dev@localhost:5432/buzz \
  cargo test -p buzz-relay --lib \
-- --ignored a_participant_who_left imported_events_skip_agent put_user_self_add_is_refused_on_dm
cargo test -p buzz-relay --lib import_events_use_their_own_budget \
-- --ignored   # needs BUZZ_TEST_REDIS_URL
just relay   # then:
cargo test -p buzz-test-client --test e2e_conversation_import \
-- --ignored --test-threads=1

The e2e test runs over POST /events and /query and covers the session lifecycle and its rejections. It also checks that the mentions feed excludes an imported mention (with a live mention as the control) and that a non-member reads neither the snapshot nor the history.

Follow-ups

  • The client side is in buzz-app (consent card, imported marker, unread exclusion).
  • The mentions feed lists only message, forum and git kinds, so proposal mention rows do not appear in feed_types: ["mentions"] yet.

🤖 Generated with Claude Code

… rules

Adds kinds 42110 to 42113 and the relay-only 30623 snapshot, the payload structs, the import tag parser, the pure session status and acceptance rule functions, the rejection reasons (including the session warm-up and the per-channel and per-proposer session caps) and the relay import limits.

Signed-off-by: jaykurian <49807026+jaykurian@users.noreply.github.com>
…d writes

Adds import_sessions and import_session_participants, the session store that applies control events and imported events under the session row lock and republishes the relay-signed snapshot, and keeps imported events out of mention rows, the listener outbox, unread evidence and thread activity.

New proposals are refused once the channel or the proposer holds the configured number of unended sessions; both counts run under transaction-scoped advisory locks. Every imported event rechecks that its author is not an agent.

At this commit the replica-fence floor still refuses an imported event's original timestamp, so the tests here cover sessions, consent, caps, expiry and deletion; the next commit adds the transaction-local floor exception, the covered-read guard that keeps it sound, and the tests that store imported events.

Signed-off-by: jaykurian <49807026+jaykurian@users.noreply.github.com>
Imported events keep their original created_at, which is older than the buzz.created_at_floor guard (migration 0021). insert_import_event now blanks the floor for its own transaction only (set_config(.., true)); the pooled connection is armed again after COMMIT or ROLLBACK, and a test checks that a plain write on the same connection is still refused.

Two rules keep covered replica reads sound:
- guard_covered_route sends a covered channel or thread read to the writer while the replica snapshot shows an active session for that channel, until expires_at plus the accept delay. A thread root the snapshot lacks stays on the replica, since its replies commit only after it.
- Imports commit only from the session's accepts_after: activated_at plus PROOF_MAX_AGE (the ring's 120 x 500 ms) plus a 15 s margin, computed once at activation and published as an accepts_after tag on the 30623 snapshot. Earlier imports get "invalid: import session warming". The fence now refuses ring entries older than PROOF_MAX_AGE, so a proved snapshot taken while imports can exist already contains the activation.

The Postgres tests that store imported events (counts, ranges, agents, DM membership, concurrency, session matching) move here, since they need the exception.

Migration 0021 is checksum-frozen, so the exception is recorded in 0081, the replica_fence module docs and docs/database.md.

Reviewer ask: sign-off from a replica-fence owner on the floor exception and the warm-up bound.

Signed-off-by: jaykurian <49807026+jaykurian@users.noreply.github.com>
…stamps

Routes NIP-CI control events to the session store, skips the drift check only for well-formed imported events that pass every session rule, charges imports to a new ImportEvents budget (BUZZ_RATE_LIMIT_IMPORT_EVENTS_PER_MIN, default 600), caps session lifetime with BUZZ_IMPORT_SESSION_MAX_DAYS (default 30), caps unended sessions with BUZZ_IMPORT_MAX_ACTIVE_SESSIONS_PER_CHANNEL (default 2) and BUZZ_IMPORT_MAX_ACTIVE_SESSIONS_PER_PROPOSER (default 8), and keeps imported events away from workflows and agent subscriptions.

Import-tagged events are hidden from agent readers on REQ history, NIP-50 search and every HTTP /query mode, using the same agent predicate as live fan-out.

Signed-off-by: jaykurian <49807026+jaykurian@users.noreply.github.com>
Signed-off-by: jaykurian <49807026+jaykurian@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is ff6ab96e42b1fc64bfc1236104478a84e11b5abd...db27b0b08d562b859771435bb29c567bdf618faa.
A new review must complete for this exact range. When manual authorization
is required, a user with write access must comment exactly
@buzz-security-review db27b0b08d562b859771435bb29c567bdf618faa to authorize a new review.
Any previous review applies only to its recorded range.

@presentyourlove

Copy link
Copy Markdown

Hi @jaykurian,

I resolved the merge conflicts that arose with recent changes on main regarding the HTTP bridge ProvenCaller refactor and enforce_ws_admission access-logging return signatures:

  • crates/buzz-relay/src/rejection.rs: Adapted send_admission_verdict to return Result<(), &'static str> to match main's access logging format, while preserving custom NIP-CI rate-limiting error messages and quota handling.
  • crates/buzz-relay/src/api/bridge.rs: Adapted query_events_authed to pass caller: &ProvenCaller into query_member_events and preserved ImportReadGate::retain_json post-filtering to protect imported conversation history from unauthorized agent readers.
  • crates/buzz-relay/src/handlers/req.rs: Kept both ImportReadGate and the new search error failure tracking in handle_search_req.
  • Merge verification: Verified with git merge-tree --write-tree main resulting in 0 conflicts (Tree SHA: 69d3b1aedc50bb012509d645120723aac44e2731).

If you'd like to pull these conflict fixes into your PR branch, you can run:

git pull https://github.com/presentyourlove/buzz.git fix/relay-conversation-import-8981

RenKoya1 added a commit to RenKoya1/buzz that referenced this pull request Nov 11, 2026
Drop everything except `buzz import slack` so the change carries no relay,
database, desktop, or new-crate surface:

- relay import exemption and the replica-fence backfill guard
- kinds 30623/30624 (identity attestation/claim) and their SDK builders
- the `buzz-migrate` claim-service crate
- desktop claim dialog, deep link, onboarding flow, and timeline attribution
- `buzz import bind` / `buzz import claim`

The relay exemption closed the replica fence with an in-process counter, which
does not hold across relay pods, and kind 30623 plus the `import` tag collide
with the consented-import proposal in block#8981. The removed work stays available
on the contributor fork for separate proposals.

`uuid`'s v5 feature moves from the workspace manifest to buzz-cli, its only
user.

Signed-off-by: Ren Koya <koya.ren.701@gmail.com>
RenKoya1 added a commit to RenKoya1/buzz that referenced this pull request Nov 11, 2026
The importer no longer asks the relay for anything a member cannot already
do, so it runs unchanged against any relay:

- Events are stamped with the import time. Each message gets its own second,
  in Slack order, because the relay orders a channel by whole-second
  created_at; the original author and time open the message content.
- Provenance is a single ["imported_from", "slack", <team>/<channel>/<ts>]
  tag, the shape proposed in block#3306. The `import` tag, which block#8981 reserves
  for consented imports, is no longer emitted.
- The ledger is exact. Import-time stamps make event ids unreproducible, so
  a signed event id is journaled as an intent before it is submitted, and an
  intent left unconfirmed is looked up on the relay by the next run and
  either adopted or signed afresh. Writes are appended to a synced journal
  and compacted into the snapshot at channel boundaries.
- A run with unconfirmed writes exits non-zero and reports them as `failed`.
- --identity-map becomes --user-map: it only populates private channels and
  DMs now that no identity binding is published.

Verified against a relay built from this tree: order, threads, reactions,
private and archived channels, re-run idempotency, intent adoption, and
recovery from a SIGKILL mid-run with no duplicate messages.

Signed-off-by: Ren Koya <koya.ren.701@gmail.com>
@LordMelkor

LordMelkor commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 @jaykurian Update from #9641 at 80036cc: no action needed here. An oldest-first channel page whose cursor is below the channel-floor month (head pages included) now reads all rows below that month in one pass before walking partitions, so pre-channel imported rows are read in both directions and sparse imports cost one statement instead of one per two months.

This branch has not been deployed

No deployments
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.

3 participants