oliver-zehentleitner / maity
clean-up: chats and inbox: one mention resolver for both chat kinds, one public chat-access API
tsk-s8ss5vewfjg8 Open
From the clean-up audit tsk-hgnbapyw7hnh, Area 6 (Chats and inbox), read at 80647565. Line numbers are at that SHA; check them against current main first. Paths are under hub/src/maity_hub/. Finding numbers are the audit's.
These two items reshape user-facing rules (the §8.6 mention rule, and the chat-access lock order), so they carry medium risk and are apart from the other Area 6 cards filed at the same time.
Order:
- A6-5: tsk-yy88szfa7sfh (in progress, PR #1747) changes chat_gate.py (
GATED_WORK,hold). Start A6-5 after it merges. - A6-1 and A6-5 have no order between them. The Area 6 shared-helpers card (A6-11) also reshapes mentions.resolve's member read; do that part together with A6-1.
A6-1. Duplication: the cross-chat mention resolver is a copy of mentions.resolve
- Files: cross_chats.py:812-899 (
_resolve) copies mentions.py:158-276 (resolve): the same alias matching, the same "a human with that handle comes first" rule, the sameambiguous_mentionerror and the same MAX_MEMBERS/MAX_OCCURRENCES caps. cross_chats.py:902-924 (_known_instances) is the same credential/successor SQL as mentions.py:290-315. cross_chats.py:797-809 (_charge) repeats the place/raise/on_rollback pattern of mentions.py:360-370 with its own limiter. - What is wrong: §8.6 is implemented twice. A change to the mention rule (aliases, ambiguity, instances) has to be made in both places, and nothing makes sure it is.
- Proposal: split mentions.resolve into a member read and a pure core,
resolve_among(conn, candidates, members, field), that takes a list of (member_id, human?, handle, shown, names, owners). Group chats keep the project read; cross_chats builds the list from_peopleand calls the same core. One_known_instancesthat takes {member_id: membership ids}, and onecharge(limiter, key, count). - Effort: M. Risk: medium (the user-facing mention rule). test_mentions.py and test_cross_chats.py cover it.
A6-5. Design: the chat-access modules reach into each other's private helpers, and an allow entry has two write paths
- Files: chat_rules.py:80, 85, 90, 97 use
chat_gate._names_agent,_allowsand_Entries. chat_request.py:403 useschat_gate._entries. chat_gate.py:221, 431 and chat_rules.py:176 usechat_access._lock. chat_gate.py:244 and 259 usechat_access._roomand_write_agents. The hub/context/events.md:838 and :848 notes rely on these names too. - The owner's entries are read twice, in different ways: chat_gate.py:109-125 uses two statements over many owners; chat_rules.py:90-111 uses one joined statement, written so that PostgreSQL gives one snapshot (v5vp on #1733).
- chat_gate.owner_yes (chat_gate.py:226-259) inserts allow rows itself, next to chat_access.create_allow (chat_access.py:236-271).
- What is wrong: the private names are a de facto API across three modules, the entry reader is written twice, and the "owner's yes" bypasses the one place that builds allow rows.
- Proposal: make the shared pieces public and name them once:
chat_access.lock_owner,chat_access.check_room,chat_access.insert_allow(conn, owner, own, side, their_agents, their_human)(used by bothcreate_allowandowner_yes), andchat_gate.entries(conn, owners)using the single-statement join from chat_rules, plusnames_agent/allows. Keep the lock order unchanged and update the context notes. - Effort: M. Risk: medium. The lock-order comments depend on the call order, so nothing may move, only be renamed or shared.
Effort sum: M+M = 6 points.