oliver-zehentleitner / maity

hub: one quota and above_ceiling refusal through ceilings (instances.refuse_over_quota, placements.refuse_over_instances, routes/projects inline copy)

Sign in to report

tsk-w0erv9pya971 Open

Audit round 3 (tsk-hgnbapyw7hnh), read at 588f911b. Kind: duplication / design.

What is wrong

  • The 409 instance_quota refusal is written twice: hub/src/maity_hub/instances.py:216-240 (refuse_over_quota) and hub/src/maity_hub/placements.py:776-799 (refuse_over_instances). Both read the project, call max_instances_limit and raise with ceilings.details; they differ only in the count function (active_count vs instances_held) and the message ("the team has as many instances…" vs "the agent runs as many instances…"), so one code carries two texts. instances.py:768-774 repeats the project/owner lookup of max_instances_limit (instances.py:203-213).
  • The same quota-refusal shape (ceilings.resolve, count, ApiError(…, ceilings.details(…))) is in hub/src/maity_hub/routes/placements.py:308-325 (_refuse_over_placements) and hub/src/maity_hub/routes/joins.py:524-541 (_require_slot); placements.py:1183-1202 (runner_quota) builds the §6.31 details dict by hand.
  • The above_ceiling refusal exists twice with different messages: hub/src/maity_hub/ceilings.py:176-185 ("the value is above its ceiling") and the inline ApiError at hub/src/maity_hub/routes/projects.py:645-650 ("the request does not validate"). _check_bound (routes/projects.py:656-673) re-reads the project per policy field (:669) although the caller holds it.

Proposal

  • One refuse_over_instances(conn, member, count, adding, caller_id) in instances.py that takes the count; delete the placements copy; the member PATCH calls max_instances_limit.
  • A ceilings.refuse(code, status, message, …) helper used by the placement, join and runner quotas; move _refuse_over_placements into placements.py.
  • One ceilings.above_ceiling used by both callers; pass the project into _check_bound.

Effort / risk: S-M. Low risk; tests that pin the details and texts need updating.