Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Take an erased name out of direct rooms only as a whole word

Petr Bauchbbb4c8725fe2
diff --git a/core/switch_core/db/stores/erasure_store.py b/core/switch_core/db/stores/erasure_store.py
index dbe7dfe1b..b4bbd16cf 100644
--- a/core/switch_core/db/stores/erasure_store.py
+++ b/core/switch_core/db/stores/erasure_store.py
@@ -59,6 +59,10 @@ ERASED_NAME = "erased person"
#: The name a deleted account's messages, and the member client that sent
#: them, carry from then on.
FORMER_MEMBER_NAME = "Former member"
+#: The shortest name taken out of a direct room's name and description. A
+#: single character, even as a whole word, is as likely to be something else
+#: in the text as the person; the room keeps it rather than lose its sense.
+MIN_SCRUBBED_NAME_LENGTH = 2
#: How Switch Console describes a chat it creates (`ChatService`): this,
#: then the agents and people in it, joined by `CONSOLE_CHAT_SEPARATOR`.
CONSOLE_CHAT_PREFIX = "Switch Console chat with "
@@ -558,12 +562,16 @@ class ErasureStore:
).scalars()
scrubbed = 0
# Longest first, so a name that contains another is replaced whole.
- ordered = sorted(names, key=len, reverse=True)
+ patterns = [
+ _whole_name(person_name)
+ for person_name in sorted(names, key=len, reverse=True)
+ if len(person_name) >= MIN_SCRUBBED_NAME_LENGTH
+ ]
for room in rooms:
name, description = room.name, room.description
- for person_name in ordered:
- name = name.replace(person_name, ERASED_NAME)
- description = description.replace(person_name, ERASED_NAME)
+ for pattern in patterns:
+ name = pattern.sub(ERASED_NAME, name)
+ description = pattern.sub(ERASED_NAME, description)
if (name, description) != (room.name, room.description):
room.name, room.description = name, description
scrubbed += 1
@@ -745,3 +753,9 @@ class ErasureStore:
.where(Client.tenant_id == require_tenant_id(), Client.id == client_id)
.values(display_name=name, user_id=None)
)
+
+
+def _whole_name(name: str) -> re.Pattern[str]:
+ """`name` where it stands as a word of its own, so "al" leaves "Albert"
+ and "dial" alone."""
+ return re.compile(rf"(?<!\w){re.escape(name)}(?!\w)")
diff --git a/core/tests/switch_core/retention/test_erasure.py b/core/tests/switch_core/retention/test_erasure.py
index 1b98ce224..0781d0175 100644
--- a/core/tests/switch_core/retention/test_erasure.py
+++ b/core/tests/switch_core/retention/test_erasure.py
@@ -607,6 +607,27 @@ class TestErasing:
)
assert copies == {"$bo"}
+ async def test_a_name_leaves_direct_rooms_only_where_it_is_a_whole_word(
+ self, session_factory: async_sessionmaker[AsyncSession]
+ ) -> None:
+ async with session_factory() as session:
+ dm = Room(
+ transport_room_id=f"!dm-{uuid.uuid4().hex[:8]}:test",
+ name="Acme Slack: al / Albert's helper",
+ description="a dial for al",
+ channel_type="direct",
+ )
+ session.add(dm)
+ await session.flush()
+
+ scrubbed = await ErasureStore().scrub_former_direct_rooms(
+ session, [dm.id], ["al", "a", ""]
+ )
+
+ assert scrubbed == 1
+ assert dm.name == "Acme Slack: erased person / Albert's helper"
+ assert dm.description == "a dial for erased person"
+
class TestQueue:
async def test_people_are_listed_with_their_message_counts_and_claimants(