oliver-zehentleitner / maity
clean-up: runners and placements: placement start rules, close loop, Refusal no-op, enumerations, slow report path
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
RefusalsubclassesApiError(placements.py:118), and the app's handler (errors.py:205) also catches subclasses._still_allowedalready lets its Refusal through uncaught viasettle. Even so,routes/placements.py:153-154(_refused),:182-186,:341-344,:652-657androutes/runner.py:444-446,:495-497catch it and rebuild an identical ApiError.- Proposal: delete
_refusedand 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_openand_require_liveraise the same codes and messages asplacements.py:970-974inside_still_allowed.routes/placements.py:585-587(_settle_by_right) repeats theallowed_projects.admits_membershipcheck ofplacements.py:975-976.- Proposal:
placementsexportsrequire_open(project)andrequire_live(conn, runner_id), which raise Refusal (see 4). Both the routes and_still_alloweduse 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-871detachedandplacements.py:874-882project_archivedare 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 theclosingescape.- 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-580runs the UPDATE thatplacements.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) repeatplacements.py:35-46(HARNESSES,MODES,STATES). OnlyREPORTED_STATESis tied to the constant by a test (hub/tests/test_placements.py:726).routes/runner.py:452Literal["retained", "removed", "kept"]repeatsWORKSPACE_STATES(placements.py:110).routes/placements.py:41RetentionrepeatsRETENTIONS(placements.py:109).WORKSPACE_STATESandRETENTIONShave 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_answerbuilds 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 everyPOST /runner/placements/{id}/statusand/workspace: the runner row, the project name, the agent profile, the owner's handle, avatars,_continues, the open request andproposed_by.routes/placements.py:467(_file) does the same to get the agent's handle.- Proposal: make
_shown_reportpublic and call it. In_file, read the handle with one query (or pass it in fromcreate_placement, which already has it). - Effort S. Risk low.
Order
- Do item 4 before item 5: item 5's new helpers raise
Refusalstraight through. - Item 6 calls
close_requestfromroutes/requests.py, which tsk-dwrtrhdgzezs moves to a domain module. Either order works; the second one rebases. - tsk-mrt77xgrexx4 (bug:
runner_credential_gonemissing on suspension and re-pair) touchesplacements.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.pyimportsclose_request,file_hub_notice,withdraw_hub_noticefromroutes/requests.py): the route-import pattern, see tsk-dwrtrhdgzezs. - Audit 18 (RFC 3339
.replace("Z", "+00:00")atplacements.py:999, and_stamp=views.tsatplacements.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
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-337owner_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-417for_runnercalls_agent()per row onhello,GET /runner/placementsand every status report.viewrunsprofile_ownertwice per row (_nameandforeignat:309), andowner_linerepeats theforeignrule (:335)._runner_answeris nowroutes/runner.py:553-558,_fileisroutes/placements.py:597. Proposal: a lightagent_ref(conn, placement)reading id and handle only;profile_owneronce insideview. - Item 8 grew:
routes/runner.py:116-128ToolIdrepeats the harness list plusmaity, besideHarness(routes/runner.py:61-72) andplacements.py:35-38HARNESSES;antigravitywas added to all three by hand in this range. Proposal:ToolIdderived asHARNESSES + ("maity",).
- Item 9 grew: