oliver-zehentleitner / maity

clean-up: isolation and other owners' agents: one entry point for the cross-owner consent split, foreign_agent duplicates

Sign in to report

tsk-0zr2x1qkkq17 Open

From the clean-up audit tsk-hgnbapyw7hnh, Area 5 (Isolation and other owners' agents), 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 both reshape foreign_agent.py and carry medium risk (the §6.2 consent flow and its pinned 202 replies), so they are apart from the low-risk Area 5 cards filed at the same time.

Order:

  • Do 6 first (small, inside foreign_agent.py), then 5.
  • tsk-dwrtrhdgzezs step 3 moves the member-change core (Change, apply_patch, validate_assignment, _require_owner_for_change) out of routes/members.py, and foreign_agent.py, cross_owner.py and admin_agents.py import it. Item 5 rewires the same call sites. Do 5 after that move, or agree with whoever takes tsk-dwrtrhdgzezs; don't run both at once.

5. Design: the "another owner's agent / cross-owner edge" orchestration is spread over three callers

  • Files: routes/members.py:810-850 (PATCH), admin_agents.py:301-353 (settling an admin agent's change), instances.py:891-894 (instance pause). Each sequences the same steps by hand: cross_owner.owners to find a cross boss, foreign_agent.is_foreign, withdraw_open(..., "superseded"), for_consent, file, without_consent, reset pause/instance, pop reports_to for the pair, cross_owner.withdraw_open, cross_owner.file, foreign_agent.remember_pair. Inside file, foreign_agent.py:84-90 (consented) filters the values that for_consent (93-98) already filtered at the caller.
  • What is wrong: the §6.2 rule "what waits for whom" is in three places. members.py and admin_agents.py already differ in detail (admin_agents nulls a departed boss first, and files the pair after apply_patch).
  • Proposal: one entry point, e.g. foreign_agent.split_for_consent(conn, project, mine, caller, target, values, pause, instance) -> (values_now, pause_now, instance_now, consent_id, pair_ids), that does the steps in one order. It replaces consented/for_consent/without_consent/remember_pair as public API. The callers then only apply the remainder and build their 202.
  • Effort: M. Risk: medium. The 202 replay shape and the order of request ids are pinned by test_foreign_agent.py (475-512, 637-662) and test_owner_reports_to.py; run those.
  • Open question: the two callers differ today (admin_agents nulls a departed boss first and files the pair after apply_patch). Is that difference intended? The single entry point has to pick one order; say which in the PR.

6. Duplication inside foreign_agent.py: current values and the credential lookup

  • The current value of a field is computed in _summary (foreign_agent.py:262-289: paused per member or instance, dormant, availability_policy, getattr) and again in _current (520-537), with the same branches.
  • _credential (175-186) is repeated inline in settle (499-506).
  • Proposal: _summary calls _current (and _quotes the result). settle calls _credential.
  • Effort: S. Risk: low. The summary text is pinned by tests (513-538, 720).

Effort sum: M+S = 4 points.