Commit Graph

10 Commits

Author SHA1 Message Date
morgmart
990f8b2ed1 fix(relay): start a new DM with its people, not its agents
A new DM forked from an existing one now holds the source's people plus
the explicit additions. Agents already in the source stay behind and can
be added later, so no agent's add policy can block "Start new DM".

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 14:14:37 -10:00
morgmart
22c532f776 fix(relay): keep DM writes on one connection and tighten agent checks
- fork_dm finds or makes the new DM on the transaction that holds the
  source DM's lock, so a 41011 without the tag uses one connection
  besides the command's, and it checks that the source is a live,
  unarchived DM, as grow_dm does.
- Removing an agent from a DM identified by all its members moves it to
  its people's identity when that is free, instead of discarding it.
- A tagged add that lands in the DM its people already have checks agent
  policies against that DM only.
- The direct-DM policy exemption applies only to a newly created DM, not
  to a DM someone left.
- A tagged 41010 reopen adds only the named agents, so it cannot re-add
  someone who left, and the race-only redirect branches are gone.
- SDK and CLI no longer cap DM opens at 8 pubkeys: the relay enforces
  nine people, and agents, including an agent caller, do not count.
  They document that agents cannot send the history tag.
- Tests force the lost-insert race and wait on the DM lock explicitly
  instead of sleeping.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 12:28:36 -10:00
morgmart
4e0e692cd4 fix(relay): check and claim DM membership in one locked step
Every DM membership write now reads the DM's members under its lock,
checks the add policy of the agents actually joining, and reconciles
the DM's identity against the fingerprint it has stored.

- An agent joining, or a tagged reopen of, a DM still identified by
  all its members moves it to its people. If those people already have
  a DM, people meet there and agents join in place.
- Reopening a DM ignores the policy of agents already in it.
- A create that loses a race reports created=false, so the opener
  still adds its agents.
- Starting a new DM from a DM rereads its members under its lock and
  checks every agent in the result, not only the ones being added.
- kind:41011 cannot add the relay to a DM.
- The nine-people limit counts the caller only if they are a person,
  so an agent can open a DM with nine people.
- Only people send the history tag, on kind:41010 as on kind:41011.
- SDK: build_dm_open_with_history opts in to the history tag.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 12:04:49 -10:00
morgmart
b685c8bd11 fix(relay): keep agent-only DMs from gaining people in place
A DM of at most one person and their agents now never grows into a DM
of two or more people, even with ["history","include"]. grow_dm reports
PeopleStartNewDm under the membership lock, and 41011 falls back to the
fork path: it opens or creates the DM of everyone and leaves the
original untouched. This matches main, where adding a person to an
agent chat always started a new DM. Agents still join in place, and
DMs of two or more people are unchanged.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:56:59 -10:00
morgmart
62dd4f3214 fix(dms): join a DM in place only with the history tag
Without ["history","include"], kind:41010 and kind:41011 behave as before
members could join in place: opening finds or makes the DM of exactly the
named members, agents included, and any add starts a new DM of everyone.
With the tag, opening finds the people's DM and adds the named agents, and
adds join in place. An older client can no longer put an agent into an
existing DM, and show it the history, without the user seeing a warning.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:56:59 -10:00
morgmart
fa2842048c fix(dms): close the moderation, agent-policy and one-person identity gaps
- Opening a DM can no longer put anyone else in the relay's moderation DM.
- Opening a DM checks each agent's add policy unless it is just the caller
  and that one agent.
- An agent joining a DM of at most one person moves its identity to all its
  members, so reopening the original pair starts a new DM.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:56:59 -10:00
morgmart
4b1ad7f5c4 fix(dms): let people leave DMs and owners remove their agents
Refusing kinds 9001 and 9022 on DMs took away leaving a DM, which
clients offer today, and broke agent deletion, which removes the agent
from each of its channels with kind:9001. Every removal already
releases the DM's identity when its people change, so a DM again
accepts kind:9022, and kind:9001 for yourself or your own agent.
People still join only through kind:41011.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:56:59 -10:00
morgmart
d0315d5669 fix(dms): keep a group DM's identity when an agent is removed
A removal releases a DM's identity only when the remaining members no
longer have it. Agents are not part of a DM of people's identity, so
kicking one leaves the DM as that group's DM; a DM of someone and their
agents, identified by all its members, is still released.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:56:59 -10:00
morgmart
19a856caed fix(dms): keep DM identity in step with removals
Generic membership kinds 9000, 9001 and 9022 are refused on DMs, so a
DM's members change only through kind:41010/41011, which keep its
identity current. Moderation and admin kicks remove members directly in
the database and still work on DMs; any removal from a DM now releases
its identity under the membership lock, so the DM keeps its history and
opening that group again starts a new DM instead of a stale match.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:56:59 -10:00
morgmart
defb8dc091 feat(relay): grow DMs in place, identified by their people
A DM is now identified by its people: agents never change which DM it
is and do not count toward the 9-person limit.

kind:41011 gains ["history", "include"]: the added people join this DM
with its history, and its identity moves to the grown set of people. If
a DM of those people already exists, that DM is returned instead.
Without the tag an added person starts a new DM of everyone, as before.
Agents always join in place, subject to their channel_add_policy.

kind:41010 finds the DM of the named people and adds any named agents
it lacks. DMs made before this change are still found by all members.

Only people grow DMs: an agent cannot send the history tag, its adds
start a new DM, and a DM it opens is identified by all its members.
Growing never reveals a DM the actor is not in.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:56:59 -10:00