oliver-zehentleitner / maity

clean-up: hub-wide: one handle lookup instead of 15 copies (_handle, _handles, _human_handle)

Sign in to report

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-46 handle_of (human; used by routes/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-176 owner_handles (human ids; used by routes/me.py:66, views.py:982).
  • chat_access.py:583-590 _handles: a line-for-line copy of views.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 the handles.of_human that 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 replaces views.owner_handles and 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_human and makes second_factor._handle public. Build on that instead of adding a second helper.
  • tsk-hzqerzwemvhz item 4 (_addressee_only in 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 _handle and its callers in auth/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

  1. 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-176 owner_handles; views.py:201-204 (inline in confirmed_by_of)
    • bridges.py:63-75 _handles, bridges.py:565 _human_handle
    • preferences.py:36-43; routes/preferences.py:188, :208
    • routes/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-787
    • briefings.py:46-57 writers and routes/overview.py:58-76 _reporters: batch principal lookups that should build on this card's batch helper
    • jourfixe/rounds.py:144 _handles; jourfixe/moderators.py:72 (in _title); memory.py:44 who