oliver-zehentleitner / maity

clean-up: runners and placements: placement start rules, close loop, Refusal no-op, enumerations, slow report path

Sign in to report

tsk-j0vqtv3zhacw Open

From the clean-up audit tsk-hgnbapyw7hnh, Area 9 (Runners and placements), 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/.

This card holds the hub clean-ups around placements: placements.py, routes/placements.py and routes/runner.py. All are S and keep behaviour the same.

4. Debt: converting placements.Refusal back into an ApiError is a no-op

  • Refusal subclasses ApiError (placements.py:118), and the app's handler (errors.py:205) also catches subclasses. _still_allowed already lets its Refusal through uncaught via settle. Even so, routes/placements.py:153-154 (_refused), :182-186, :341-344, :652-657 and routes/runner.py:444-446, :495-497 catch it and rebuild an identical ApiError.
  • Proposal: delete _refused and the six try/except blocks.
  • Effort S. Risk low: the same status, code, message and details come out.

5. Design: the "may this placement start" rules are implemented twice

  • routes/placements.py:166-174 _require_open and _require_live raise the same codes and messages as placements.py:970-974 inside _still_allowed.
  • routes/placements.py:585-587 (_settle_by_right) repeats the allowed_projects.admits_membership check of placements.py:975-976.
  • Proposal: placements exports require_open(project) and require_live(conn, runner_id), which raise Refusal (see 4). Both the routes and _still_allowed use them.
  • Effort S. Risk low.

6. Duplication: the same "withdraw the request, then close now or close uniform" loop is written three times

  • placements.py:861-871 detached and placements.py:874-882 project_archived are line for line the same apart from the reason strings.
  • routes/placements.py:676-686 (delete_placement) is the same decision for one placement, plus the closing escape.
  • Proposal: one placements.close_for(conn, placement, closed_reason, why, actor, by). Both loops call it, and so does the delete route.
  • Effort S. Risk low.

7. Duplication: the join pickup revokes unused joins inline

  • routes/runner.py:571-580 runs the UPDATE that placements.revoke_unused_joins(conn, t.join_link.c.placement_id == placement.id) (placements.py:885-894) already provides.
  • Proposal: call the helper.
  • Effort S. Risk low.

8. Duplication and dead code: the placement enumerations are listed twice, and two constants have no reader

  • routes/runner.py:57-63 (Harness, Mode, REPORTED_STATES) repeat placements.py:35-46 (HARNESSES, MODES, STATES). Only REPORTED_STATES is tied to the constant by a test (hub/tests/test_placements.py:726).
  • routes/runner.py:452 Literal["retained", "removed", "kept"] repeats WORKSPACE_STATES (placements.py:110).
  • routes/placements.py:41 Retention repeats RETENTIONS (placements.py:109).
  • WORKSPACE_STATES and RETENTIONS have no reader anywhere in hub/src or hub/tests.
  • Proposal: build the Literals from the tuples (Literal[HARNESSES] etc.), or add the same tie-test for each pair; delete the unread constants otherwise.
  • Effort S. Risk low.

9. Debt: slow path on the runner's report routes

  • routes/runner.py:382-387 _runner_answer builds the whole human view, pl.view(...), only to read its "reported" key, which is _shown_report(placement.reported). That costs about eight extra queries on every POST /runner/placements/{id}/status and /workspace: the runner row, the project name, the agent profile, the owner's handle, avatars, _continues, the open request and proposed_by.
  • routes/placements.py:467 (_file) does the same to get the agent's handle.
  • Proposal: make _shown_report public and call it. In _file, read the handle with one query (or pass it in from create_placement, which already has it).
  • Effort S. Risk low.

Order

  • Do item 4 before item 5: item 5's new helpers raise Refusal straight through.
  • Item 6 calls close_request from routes/requests.py, which tsk-dwrtrhdgzezs moves to a domain module. Either order works; the second one rebases.
  • tsk-mrt77xgrexx4 (bug: runner_credential_gone missing on suspension and re-pair) touches placements.runner_credential_gone; rebase rather than conflict.

Left out (hub-wide patterns, filed on shared cards by the lead)

  • Audit 1 (the agent profile's owner looked up in four places in placements.py, routes/placements.py, routes/runner.py): the agent-to-owner lookup pattern.
  • Audit 17 (placements.py imports close_request, file_hub_notice, withdraw_hub_notice from routes/requests.py): the route-import pattern, see tsk-dwrtrhdgzezs.
  • Audit 18 (RFC 3339 .replace("Z", "+00:00") at placements.py:999, and _stamp = views.ts at placements.py:1144-1145): the RFC 3339 pattern.

Covered elsewhere

  • None of these six. Searched: _still_allowed, Refusal, revoke_unused_joins, REPORTED_STATES, runner_removed.

Effort: 6S.

Notes

  1. Maity Coder Claude 003 · Nov 20, 2026, 11:50 UTC

    Audit round 3 (tsk-hgnbapyw7hnh), read at 588f911b: two additions to this card's items 8 and 9.

    • Item 9 grew: hub/src/maity_hub/placements.py:323-337 owner_line (new) calls the full _agent() (4 reads: profile, _name->profile_owner, owner's handle, avatar; placements.py:165-194) only for ["handle"]; placements.py:375-417 for_runner calls _agent() per row on hello, GET /runner/placements and every status report. view runs profile_owner twice per row (_name and foreign at :309), and owner_line repeats the foreign rule (:335). _runner_answer is now routes/runner.py:553-558, _file is routes/placements.py:597. Proposal: a light agent_ref(conn, placement) reading id and handle only; profile_owner once inside view.
    • Item 8 grew: routes/runner.py:116-128 ToolId repeats the harness list plus maity, beside Harness (routes/runner.py:61-72) and placements.py:35-38 HARNESSES; antigravity was added to all three by hand in this range. Proposal: ToolId derived as HARNESSES + ("maity",).