oliver-zehentleitner / maity
clean-up: cards and reviews: one dependency check, edge helpers, takeover helpers, a brittle test
tsk-92tjmmcfvwm4 Open
From the clean-up audit tsk-hgnbapyw7hnh, Area 7 (Cards and reviews), read at 80647565. Every line number is at that SHA; check it against current main first. Numbers are the audit's finding numbers. Paths are under hub/src/maity_hub/ unless they start with hub/.
This card holds the clean-ups inside cards.py and takeovers.py, plus one brittle test. Each item is S and changes no behaviour.
1. The dependency cycle check runs twice, and the second one is slow (duplication / debt)
- Files:
cards.py:282-303(would_cycle),cards.py:378-397(set_depends_on),cards.py:306-365(check_subtask_graph). Callers:routes/tasks.py:907-915+946(create) androutes/tasks.py:1087-1097+1141-1143(PATCH). - What is wrong: every path that calls
set_depends_onwith ids has already calledcheck_subtask_graphwith the samedepends_on, under the same lock. That call checksself, unknown targets and cycles over one in-memory graph that includes the parent gates.set_depends_onthen checksselfagain, callscheck_edge_targetsagain and walks the graph again inwould_cycle, with 2 queries per visited node. The comment atroutes/tasks.py:1100-1101exists only to keep the two checks in step. - Proposal: make
set_depends_ona plain replace-the-edges write (keep the no-change early return), document that the caller must have runcheck_subtask_graph, and deletewould_cycle(no other caller, repo-wide grep). - Effort S. Risk low.
test_subtasks.pycovers the graph cases; add one test that a direct dependency cycle is still refused on PATCH.
2. The edge helpers have two names for one operation, and a stale docstring (design / docs drift)
- Files:
cards.py:400-405(set_ships_with),cards.py:408-433(set_symmetric),cards.py:466-473(edges). Callers:routes/tasks.py:947, 949, 1146, 1149. - What is wrong:
set_ships_withonly callsset_symmetric(..., "ships_with"), but the routes callset_symmetric(..., "related")directly.edges()says it returns "depends_onandships_with", but it also returnsrelated.set_symmetricalso holds an inlinefield == "ships_with"release-card rule (cards.py:419-427) that belongs to one kind only. - Proposal: drop
set_ships_withand callset_symmetric(..., "ships_with")at both sites, or add a matchingset_related. Fix theedges()docstring. - Effort S. Risk very low.
3. "The cards this card depends on" is written twice (duplication)
- Files:
cards.py:245-251(open_dependencies),releases.py:51-59(_shipped). - What is wrong: both run the same join,
card_edge.to_card = card.id WHERE from_card = ? AND kind = 'depends_on'. One selects(id, status)and filters closed cards in Python; the other selects whole rows ordered by id. - Proposal: one
cards.dependencies(conn, card_id)that returns rows ordered by id.open_dependenciesfilters them;releases._shippeduses it as it is. - Effort S. Risk low.
6. Repeated shapes inside takeovers.py (duplication)
- Files:
takeovers.py:188-205vstakeovers.py:736-760(two near-identicalinsert(t.takeover)blocks:open_takeoverandrecord_lease_expired). The outcome dict{"how", "by", "reason", "at"}is built attakeovers.py:260,365and751-756.settle(takeovers.py:810-826) restates the two "due" conditions thatdue_projects(takeovers.py:837-838) already has. - Proposal: an
_insert(conn, project_id, card, to, mine, *, status, reason, closed_at=None, outcome=None)helper, an_outcome(how, by, reason, now)helper, and module-level_DUE_OPEN(now)/_DUE_OBJECTED(now)conditions shared bysettleanddue_projects. - Effort S. Risk low (
test_takeovers.pycovers both paths).
11. test_open_claims.py pins line numbers of cards.py (debt: brittle test)
- File:
hub/tests/test_open_claims.py:82-93,assert found == ["cards.py:27", "cards.py:30"]. - What is wrong: the guard ("no module keeps its own copy of the closed statuses") is useful, but it compares file:line. Adding or removing any line above
cards.py:27fails it with no real regression. Its regex also only catches the order"done", "cancelled". A repo-wide grep at this SHA found no other copy in either order. - Proposal: assert on file names, or on the matching lines' text (
STATUSES =,CLOSED =), and match both orders. - Effort S. Risk none.
Order
- Do item 11 first or in the same PR: item 1 deletes lines above
cards.py:27and would trip that test. - Item 6 and the shared Worker-class card (see below) both touch
takeovers.py; rebase rather than conflict.
Left out (hub-wide patterns, filed on shared cards by the lead)
- Audit 4 (domain modules import
audience,close_request,file_proposalfromroutes/): the route-import pattern, see tsk-dwrtrhdgzezs. - Audit 5 (
takeovers._ownervscross_owner.owner_of): the agent-to-owner lookup pattern. - Audit 10 (the takeover sweep's Worker class): the Worker-loop pattern.
Covered elsewhere
- None. Searched: would_cycle, check_subtask_graph, set_ships_with, open_dependencies, record_lease_expired, test_open_claims.
Effort: 5S.