clean-up: hub-wide: one handle lookup instead of 15 copies (_handle, _handles, _human_handle)
tsk-ee3z4rakddq9 Open
From the clean-up audit tsk-hgnbapyw7hnh (findings A5-3, A6-4, A8-7), 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 handle of this principal" (agent profile or human) is read by private helpers in many modules. They differ only in the fallback (None, scalar_one raise, the principal id, the agent id). One module also calls another's underscore names: foreign_agent.py:168, :170, :349, :350 call cross_owner._handle and cross_owner._human_handle.
Sites
One principal at a time:
cross_owner.py:61-68_handle(row)(agent or human, falls back to the principal id) and:71-72_human_handle.cover.py:35-44_handle(same logic as cross_owner's, raises).admin_agents.py:161-165_handle(agents only).bridges.py:549-550_human_handle(identical to cross_owner's).subagents.py:42-46handle_of(human; used byroutes/joins.py:294,:799).reports.py:64-73_handle(None fallback).preferences.py:36-43_handle(kind, principal).notifications/items.py:1347-1351_handle(agent_id).isolation.py:118-120, inline in_tell_owner.handles.py:420-421_owner_handle(found while grepping; not in the audit).
Many at once:
views.py:170-176owner_handles(human ids; used byroutes/me.py:66,views.py:982).chat_access.py:583-590_handles: a line-for-line copy ofviews.owner_handles.chat_request.py:191-200_handles(agent or human, the id as fallback).jourfixe/rounds.py:144-154_handles(agents only).
Not copies: bridges.py:67 _handles (membership ids to (kind, handle) pairs), namespace.py:109 _handle and routes/requests.py:1000 _handle do other things.
Proposal
- One public set in
handles.py, next to thehandles.of_humanthat tsk-j967n09yz6ps item 8 adds: of_human(conn, human_id),of_agent(conn, agent_id)of(conn, principal_id) -> str | None(agent or human by id; a row-taking variant if the callers need it)of_many(conn, ids) -> dict[str, str](agents and humans), which replacesviews.owner_handlesand the three_handles.- Each caller keeps its own fallback with
or(principal id, agent id) or raises itself where it does today. - foreign_agent then calls the public helper, not cross_owner's underscore names.
Effort and risk
- Effort M (15 sites, each S).
- Risk low. Watch the fallbacks: cross_owner falls back to the principal id where cover raises, and chat_request falls back to the id. Messages and notice texts that contain the handle are pinned by tests.
Order
- After, or together with, tsk-j967n09yz6ps item 8, which creates
handles.of_humanand makessecond_factor._handlepublic. Build on that instead of adding a second helper. - tsk-hzqerzwemvhz item 4 (
_addressee_onlyin foreign_agent, cross_owner, bridges) and tsk-5whysgm79amz (cross_owner) touch the same modules; rebase rather than conflict. - Can share a PR with the hub-wide agent-to-owner card tsk-9tj3p6ca30m6 (same files: cross_owner, preferences, reports).
Covered elsewhere
auth/second_factor.py:816-817_handleand its callers inauth/second_factor_reset.py:111,:170,:189: tsk-j967n09yz6ps item 8.- Searched: _human_handle, owner_handles; no other card covers these helpers.
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.
instances.py:147-149: the team editor's handle lookup (not on this card yet)views.py:170-176owner_handles;views.py:201-204(inline inconfirmed_by_of)bridges.py:63-75_handles,bridges.py:565_human_handlepreferences.py:36-43;routes/preferences.py:188,:208routes/requests.py:1051-1085_asker_handles(borderline)project_names.py:220;routes/projects.py:824;routes/joins.py:724-726,:729-734(agent or human),:785-787briefings.py:46-57writersandroutes/overview.py:58-76_reporters: batch principal lookups that should build on this card's batch helperjourfixe/rounds.py:144_handles;jourfixe/moderators.py:72(in_title);memory.py:44who