Skip to content

fix(core): keep required p tag on self-owned engrams - #2996

Open
slusset wants to merge 1 commit into
block:mainfrom
slusset:fix/self-owned-engram-p-tag
Open

fix(core): keep required p tag on self-owned engrams#2996
slusset wants to merge 1 commit into
block:mainfrom
slusset:fix/self-owned-engram-p-tag

Conversation

@slusset

@slusset slusset commented Jul 26, 2026

Copy link
Copy Markdown

Summary

engram::build_event silently produced NIP-AE-invalid envelopes whenever an
identity keeps memory for itself (agent == owner): the required owner p
tag was missing from the signed event.

Root cause: nostr's EventBuilder strips self-referencing p tags by
default (an anti-self-notification convention). NIP-AE's envelope rules
require exactly one p tag naming the owner (docs/nips/NIP-AE.md,
Event envelope), and head selection queries filter on ["p", pubkey_o]
so a self-owned write was accepted by relays but invisible to every read:
buzz mem set reported success while buzz mem get/ls returned nothing.

Fix

Call .allow_self_tagging() in build_event. One line, plus a regression
test pinning the self-owned round trip (envelope carries exactly one p tag
naming the owner; validate_and_decrypt succeeds).

Distinct-key behavior is unaffected — the NIP-AE reference test vectors and
the full engram suite pass unchanged (35 tests).

How this was found

Exercising NIP-AE from a single-identity deployment (a personal relay node
whose owner keeps engrams under its own key, rather than the hosted
agent-serves-owner pairing). NIP-AE's shapes work well for that case — the
spec doesn't forbid pubkey_a == pubkey_o, and the NIP-44 conversation key
is well-defined for self — this envelope bug was the only obstacle. If
maintainers would prefer the spec to state explicitly that self-owned pairs
are supported, happy to follow up with a one-line clarification to
docs/nips/NIP-AE.md.

Testing

  • cargo test -p buzz-core engram — 35 passed, including the new
    self_owned_engram_keeps_required_p_tag regression test
  • Verified live: self-owned buzz mem set/get/ls round-trips against a
    relay after the fix; before it, set succeeded and get returned
    not-found

🤖 Generated with Claude Code

@slusset
slusset requested a review from a team as a code owner July 26, 2026 16:10
nostr's EventBuilder strips self-referencing p tags by default, so an
identity keeping NIP-AE memory for itself (agent == owner) silently
produced envelopes without the required owner p tag — accepted by
relays but invisible to head selection, making every self-owned write
unreadable. Allow self-tagging in build_event and pin the round trip
with a regression test. Distinct-key vectors are unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Ted Slusser <ted.slusser@gmail.com>
@slusset
slusset force-pushed the fix/self-owned-engram-p-tag branch from 882e9e8 to 79ec7b7 Compare July 26, 2026 16:24
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.

1 participant