oliver-zehentleitner / maity
clean-up: hub-wide: one agent-to-owner lookup with one contract (4 helpers, 9 private copies, about 25 inline queries)
tsk-9tj3p6ca30m6 Open
From the clean-up audit tsk-hgnbapyw7hnh (findings A5-2, A6-3, A6-18 owner part, A7-5, A8-6, A9-1), read at 80647565. Line numbers are at that SHA; check them against current main first. Paths are under hub/src/maity_hub/.
What is wrong
The rule "the human who owns this agent" (and its variant "the human itself, or the agent's owner") is written in 37 places (counted below). The helpers that exist disagree on the contract: cross_owner.owner_of returns None for a missing profile, agent_owners.owner_of raises (scalar_one), and the inline copies use either scalar() or scalar_one(). Rules that depend on "same owner" (§6.2 cross-owner reports_to, the takeover refusal, chat gates, moderation) can drift apart.
Sites
Helpers that exist (four, two contracts):
cross_owner.py:33-40owner_of(row): None for a missing profile, a human's own id for a human.agent_owners.py:36-40owner_of: agents only, raises.moderation.py:129-139owner_account(principal): the human itself or the agent's owner. Used byroutes/joins.py:1045.chat_gate.py:78-88owners_of: the batch form. Used bychat_rules._owner(chat_rules.py:138).
Private copies:
group_chats.py:463-467_owner_of,preferences.py:244-248_owner_of(both identical to the above).jourfixe/series.py:94-98_agent_owner,jourfixe/moderators.py:38-43_owner.reports.py:51-58account_of(=owner_accountfor aCaller).takeovers.py:552-560_owner(from the membership id, a join) andtakeovers.py:531-549_same_owner(its own join).placements.py:184-191profile_owner_ofandplacements.py:194-204profile_owner(membership -> agent_profile join),routes/placements.py:445-449_profile_owner.
Inline single-agent selects, select(agent_profile.owner_id).where(agent_profile.id == ...) (git grep at 80647565, 17 sites outside the helpers above):
availability.py:251,avatars.py:350(also filtersdeleted_at),avatars.py:548,commitment.py:100,instances.py:723,jourfixe/circle.py:50,memory.py:283,not_listening.py:157routes/agents.py:354,routes/events.py:476,routes/members.py:949,:1155,:1539,routes/requests.py:570,:1735,:2133,:2616
Inline membership -> owner join: routes/runner.py:657-671 (_owner_audience, repeats placements.profile_owner including the fall-back to created_by).
Inline batch copies of chat_gate.owners_of, select(agent_profile.id, agent_profile.owner_id).where(agent_profile.id.in_(...)) (6 sites):
group_chats.py:158-164(observers; group_chats already imports chat_gate),conversation_list.py:209-212,conversation_list.py:375-385,jourfixe/rounds.py:282-285,maintenance.py:612-615,views.py:1288-1291.
Not copies (joins that read the owner as one column of a wider query, e.g. views.py:415, mentions.py:185, restricted.py:50): leave them.
Proposal
- One module owns the rule, for example
agent_owners.py(orviews.py), with: owner_of(conn, agent_id) -> str | Noneowners_of(conn, agent_ids) -> dict[str, str](moved from chat_gate)owner_behind(conn, principal_id) -> str | None(the human itself, or the agent's owner; replacesowner_account,reports.account_of,takeovers._owner,cross_owner.owner_of)owner_of_membership(conn, membership_id) -> str | None(replaces the placements pair and_owner_audience)- One contract: None when there is no profile. A caller that needs strictness raises itself, so the strictness each caller has today stays visible at the call site.
- Delete
agent_owners.owner_of's raising variant, the private copies andreports.account_of; switch the inline selects file by file. takeovers.is_cross_owner/_same_ownerandcross_owner.ownerscompare through the same helper.
Effort and risk
- Effort M: the helpers and the private copies S, the sweep of about 25 inline sites M (each change trivial).
- Risk low. Keep
avatars.py:350'sdeleted_atfilter and thecreated_byfall-back inplacements.profile_owner.scalar_onecallers that rely on the raise for an impossible row lose nothing if they assert.
Order
- Do this before, or rebase with, the area cards that touch the same code:
- tsk-5whysgm79amz item 2 (
cross_owner.new_agent/join_waits, which then use the new helper) and item 9 (agent_owners.py,is_outside). - tsk-es10trywfqs7 item 9 (
group_chats.people/principal,review_delivery). - tsk-z0tpe6pz3fjq (edits
views.py; matters if the helper goes into views). - tsk-j0vqtv3zhacw (
placements.py,routes/placements.py,routes/runner.py). - tsk-92tjmmcfvwm4 item 6 (
takeovers.py), tsk-cnyz6bb2vhkx (moderation.py, whereowner_accountlives), tsk-vt3nbqq1v4rz (conversation_list.py). - Can share a PR with the hub-wide handle-lookup card filed at the same time (same files: cross_owner, preferences, reports).
Open question
- Where does the helper live:
agent_owners.py(name fits, but it also holds the §6.2 policy) orviews.py(already imported almost everywhere)? Check for import cycles either way.
Covered elsewhere
cross_owner.new_agentandjoin_waits(area-local part of A5-2): tsk-5whysgm79amz item 2.- The rest of A6-18 (the query "agent ids owned by the observer", conversation_list.py:478-483 and routes/conversations.py:371-375): tsk-vt3nbqq1v4rz (A6-16).
- Searched: owner_of, owner_account, _owned_agents; no card covers the hub-wide lookup.
Effort sum: M (about 3 points).
Notes
Maity Coder Claude 003 · Nov 13, 2026, 23:11 UTC
More sites from the clean-up audit (tsk-hgnbapyw7hnh, uncovered-files pass at 9dfd4b65). Some may already be in the body, so check before you count them twice.
views.py:541-551_owners_of;views.py:1276-1282(inside_standing_of)environment.py:170-178(_announce)routes/requests.py:569,:1734,:2132,:2615availability.py:251;not_listening.py:157;preferences.py:244routes/events.py:475-477(chat_parties)jourfixe/series.py:94_agent_owner;jourfixe/circle.py:48_owns;jourfixe/moderators.py:38_owner;jourfixe/rounds.py:283(owner map)memory.py:281owner_ofroutes/jour_fixe.py:583(the observer's "owned" check)