oliver-zehentleitner / maity

clean-up: cards and reviews: one dependency check, edge helpers, takeover helpers, a brittle test

Sign in to report

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) and routes/tasks.py:1087-1097 + 1141-1143 (PATCH).
  • What is wrong: every path that calls set_depends_on with ids has already called check_subtask_graph with the same depends_on, under the same lock. That call checks self, unknown targets and cycles over one in-memory graph that includes the parent gates. set_depends_on then checks self again, calls check_edge_targets again and walks the graph again in would_cycle, with 2 queries per visited node. The comment at routes/tasks.py:1100-1101 exists only to keep the two checks in step.
  • Proposal: make set_depends_on a plain replace-the-edges write (keep the no-change early return), document that the caller must have run check_subtask_graph, and delete would_cycle (no other caller, repo-wide grep).
  • Effort S. Risk low. test_subtasks.py covers 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_with only calls set_symmetric(..., "ships_with"), but the routes call set_symmetric(..., "related") directly. edges() says it returns "depends_on and ships_with", but it also returns related. set_symmetric also holds an inline field == "ships_with" release-card rule (cards.py:419-427) that belongs to one kind only.
  • Proposal: drop set_ships_with and call set_symmetric(..., "ships_with") at both sites, or add a matching set_related. Fix the edges() 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_dependencies filters them; releases._shipped uses it as it is.
  • Effort S. Risk low.

6. Repeated shapes inside takeovers.py (duplication)

  • Files: takeovers.py:188-205 vs takeovers.py:736-760 (two near-identical insert(t.takeover) blocks: open_takeover and record_lease_expired). The outcome dict {"how", "by", "reason", "at"} is built at takeovers.py:260, 365 and 751-756. settle (takeovers.py:810-826) restates the two "due" conditions that due_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 by settle and due_projects.
  • Effort S. Risk low (test_takeovers.py covers 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:27 fails 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:27 and 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_proposal from routes/): the route-import pattern, see tsk-dwrtrhdgzezs.
  • Audit 5 (takeovers._owner vs cross_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.