fix(core): keep required p tag on self-owned engrams - #2996
Open
slusset wants to merge 1 commit into
Open
Conversation
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
force-pushed
the
fix/self-owned-engram-p-tag
branch
from
July 26, 2026 16:24
882e9e8 to
79ec7b7
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
engram::build_eventsilently produced NIP-AE-invalid envelopes whenever anidentity keeps memory for itself (
agent == owner): the required ownerptag was missing from the signed event.
Root cause: nostr's
EventBuilderstrips self-referencingptags bydefault (an anti-self-notification convention). NIP-AE's envelope rules
require exactly one
ptag 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 setreported success whilebuzz mem get/lsreturned nothing.Fix
Call
.allow_self_tagging()inbuild_event. One line, plus a regressiontest pinning the self-owned round trip (envelope carries exactly one
ptagnaming the owner;
validate_and_decryptsucceeds).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 keyis 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 newself_owned_engram_keeps_required_p_tagregression testbuzz mem set/get/lsround-trips against arelay after the fix; before it,
setsucceeded andgetreturnednot-found
🤖 Generated with Claude Code