oliver-zehentleitner / maity

clean-up: G2 roles and forge reads: the done-authority table written six ways, one forge-error mapping, contract reads, line/admin proposals, instances helpers

Sign in to report

tsk-kj17zr6m1mv2 Open

From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G2 Cards, tasks, releases and roles), read at 9dfd4b65. Paths are under hub/src/maity_hub/. Line numbers are at 9dfd4b65; check them against current main first.

Rules that are written more than once, in different shapes.

1. "Who is the done authority" is written six ways (design: one rule, many shapes)

  • Sites:
  • cards.py:110-122 (has_done_authority: authority to scopes, as code)
  • cards.py:236-242 (authority_scope: authority to one scope; reviewer_and_tester maps to tasks:review only)
  • cover.py:112-117 (DONE_SCOPES: authority to a tuple of scopes)
  • merged.py:31-36 (AUTHORITY: authority to audience tokens)
  • events.py:1188-1192 (_DONE_ROLES: authority to role names)
  • routes/tasks.py:2073-2081 (task_reported's audience: role:tester only under tester or reviewer_and_tester, inline)
  • What is wrong: a new authority value, or a change to which scope signs, must be made in six places. The shapes already differ (authority_scope names one scope where DONE_SCOPES names two).
  • Proposal: one table in cards.py, for example DONE_AUTHORITY = {"reviewer": ("reviewer",), "tester": ("tester",), "reviewer_and_tester": ("reviewer", "tester"), "admin": ()}, with small derived helpers for the scopes (reviewer to tasks:review, tester to tasks:test, admin to tasks:admin), the role tokens and the error scope. All six sites use it.
  • Effort: S-M (count M). Risk: low. test_merged_closes.py, test_cover.py, test_review_delivery.py and the signature tests pin the outcomes.

2. The forge-read error mapping is copied in every route that reads the forge (duplication)

  • Sites:
  • routes/probe.py:45-48, 66-69, 84-88
  • routes/contract_text.py:37-40, 46-50, 76-79, 84-88
  • routes/board.py:682-694 (the import)
  • Each copy writes: for_project, then configured_for else probe_not_configured(fg.refused or "no_grant") shown only to project:admin; NotCoveredError to probe_not_configured(reason if admin); ForgeUnavailableError to 503 probe_unavailable with retry_at.
  • Proposal: forge_reads.reader(request, mine) -> Forge (the configured check) and a context manager forge_reads.answering(mine, last=None) that maps the two exceptions. routes/probe.py passes its details.last.
  • Effort: S. Risk: low. The error bodies are pinned by test_probe.py, test_contract_routes.py, test_contract_whole.py and the import tests.

3. contract_text.read and read_whole repeat the same fetch (duplication)

  • contract_text.py:311-345 and 351-393: the same branch-head read (315-318 / 360-363), the same file_at with the "too large" mapping, and the same UTF-8 decode (321-332 / 367-378). Only the error field differs (contract.path vs settings.contract_path).
  • Proposal: _head(fg, repository, branch, field) and _markdown(fg, repository, path, ref, field) -> (bytes, str), both used by both reads.
  • Effort: S. Risk: low.

4. The manager's and the admin agent's consent proposals are twins, and the manager's names members by id (design / naming)

  • line.py:252-265 (propose) and admin_agents.py:168-187 (propose): the same shape (title, summary, file_consent with a proposal).
  • line.py:258 binds handle = principal_id(conn, target.id). That is the member id (agt-…), not the handle. So the request a human reads is titled "Pause agt-…" or "Change agt-…'s lead". The admin-agent twin uses the real handle (admin_agents.py:174). The hub's own naming rule (rules.py:183-190) tells agents never to name a member by id in text a human reads.
  • Proposal: use the handle in line.propose (and for the asker in both summaries). Share one small title/summary builder if that stays readable.
  • Effort: S. Risk: low. Check test_manager.py for a pinned title.

5. instances.py: the owner-or-member resolution twice, and its own humans_only (duplication)

  • instances.patch_dormant (instances.py:860-877) repeats the resolution in team_target (693-716): the target by member id, "owns the agent, member or not", else a membership with not_found for a stranger. Only the final gate differs (_require_profile_owner vs members:admin).
  • instances.humans_only() (670-676) and takeovers.humans_only() (takeovers.py:123-126) each rebuild errors.humans_only(message) (errors.py:76-78) with their own message.
  • Proposal: one _owner_or_member(conn, caller, slug, member_id) -> (target, reader, owns) used by both. Replace the two local builders with errors.humans_only("…").
  • Effort: S. Risk: low.

6. instances.py: "the live sessions and who listens" is read four times (duplication)

  • instances.py:338-341 (views), 442-443 (unpaused_presences), 554-555 (round_robin), 618-619 (team_wakes): _live_sessions and then listening.which over the session ids, each time.
  • round_robin's online() (558-567) is another copy of the presence ladder's "online" rung (presence, 294-306).
  • Proposal: one _listening(conn, credentials) -> (sessions, heard). round_robin calls presence(...) == "online".
  • Effort: S. Risk: low.

Order

  • Item 6's presence part goes with tsk-z0tpe6pz3fjq item 14 (one presence ladder for runners, views and instances). Do it there or after it.
  • Item 2: tsk-e77g3nhqqnex item 2 adds public forge read methods; the mapping helper can sit next to them.
  • Item 5: tsk-9tj3p6ca30m6 lists instances.py:723 (owns_agent's owner select); the helper there can serve _owner_or_member.

Covered elsewhere

  • instances.INSTANCE_PATTERN (instances.py:29): tsk-53swp51q57tg item 3.
  • instances.presence vs views.presence vs runners.presence: tsk-z0tpe6pz3fjq item 14. round_robin.online (item 6 here) is a fourth copy it does not list.
  • routes/contract_text._matches (If-None-Match): tsk-k25qqhygend8 item 1.
  • line.py:256 importing file_consent from routes: tsk-dwrtrhdgzezs.
  • Searched: done_authority, DONE_SCOPES, probe_not_configured, probe_unavailable, contract_text, line.propose, patch_dormant, humans_only, round_robin.

Effort sum: M + 5S (about 8 points).