oliver-zehentleitner / maity
clean-up: runners and placements: one revoke-and-tell, one due rule, one presence ladder, runner admin lookups
tsk-z0tpe6pz3fjq 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/ unless they start with hub/.
This card holds the hub clean-ups around runners and credential revocation: runners.py, runner_revoke.py, views.py, worker_runs.py and their routes.
2. Duplication: "revoke an agent credential, then emit credential_revoked" is written four times
runner_revoke.py:45-64revoke_agent;placements.py:1266-1286_revoke_removed;auth/leaks.py:59-70insiderevoke_leaked;routes/members.py:1584-1595revoke_credential.- Each one calls
leaks.revoke, looks up the project and agent, and emits the same event with the audience[member:<agent>, trust:owner]and the payload{credential_id, reason}. - Proposal: one
revoke_and_tell(conn, credential_id, reason, by, actor, **flags)next torevoke, which returns whether it won, used by all four. - Effort S. Risk low. The event shape is pinned by tests.
3. Design and docs drift: the "revocation is due" rule is implemented three times
runner_revoke.py:36-41due(row)is the rule.views.py:946-947(_credential_counts) re-implements it inline.views.py:1037-1046(_revocation) re-implements it inline and hard-codes "runner_revoked" instead ofrunner_revoke.REASON.hub/context/placements.md:154-156rejects "two functions ... repeat the same three-line check for no gain", yetviews.pyrepeats it twice. The same entry,placements.md:146-147, saysdueis called on "revoke_agent's path". It is not:revoke_agent(runner_revoke.py:45) never callsdue. The callers areauth/caller.py:505(agent and runner rows),runner_revoke.py:70(revoke_due) andnot_listening.py:135.- Proposal: have
views.pycallrunner_revoke.dueand useREASON. Correct the caller list inplacements.md. - Effort S. Risk low.
10. Duplication: an attachment's active placements are counted inline, and a helper's parameter is never used
runners.py:216-222(attachment_view) counts active placements per project and runner in its own query.placements.active_count(conn, project_id, runner_id=None)(placements.py:418-425) has arunner_idparameter for exactly this. Its only caller (routes/placements.py:296) never passes it.- Proposal: use
active_countinattachment_view(with a local import: placements imports runners), or drop the parameter. - Effort S. Risk low.
11. Debt: the return value of placements.runner_removed is never read
placements.py:847-858collects and returnsstill_running. Its only caller,routes/runners.py:687, ignores the result.routes/runners.py:123-131(_load_removal) computes the same list again from the closed rows, with the sameRUNNING_STATEStest.- Proposal: make
runner_removedreturn None, and keep the loader as the one place that computes the list (it is needed anyway for replays). - Effort S. Risk none.
14. Duplication: the §5.3 presence ladder (listening, then ONLINE, then AWAY) is written three times
runners.py:96-107presence;views.py:376-394presence;instances.py:294-306presence, with its own constants atinstances.py:291(ONLINE_SECONDS,AWAY_SECONDS) that repeatviews.py:34-35.landing_stats.py:29defines ONLINE a third time.- Proposal: one
views.presence_by_age(last_seen, listening)with the shared constants. The three callers keep only their own extras (pause, session,latest_call). - Effort S-M (counted as M). Risk low.
15. Duplication: the "members:admin in a project" rule is applied twice
runners.py:84-93administers()reads the membership and callshas_scope(..., "members:admin").routes/runners.py:550-564(list_runners) does the same in bulk, inline.visible_to(runners.py:196-203) also runsadministersonce per attached project.- Proposal: add
runners.administered_project_ids(conn, human_id), and use it in bothlist_runnersandvisible_to. - Effort S. Risk low.
16. Design: worker_runs reaches into listening's private names
worker_runs.py:39,88and97uselistening._DB_NOW(defined atlistening.py:51), andworker_runs.py:106useslistening.POD. The database clock expression has nothing to do with long-polls.- Proposal: move
_DB_NOWtoclock.pyordb.pyas a public name, and import it from there in both modules. - Effort S. Risk none.
Order
- Do tsk-mrt77xgrexx4 (bug:
runner_credential_gonemissing on suspension and re-pair) first; item 2 touches the same functions. - Item 2: after tsk-f5sdcgr7vzj0 item 2, which moves
revokeandrevoke_runner_credentialfromauth/leaks.pytoauth/revocation.py. Put the new helper there. - Items 2, 3 and 11: tsk-mknw2my8zq4c (security, in progress) is changing
runner_revoke.pyandroutes/runners.py. Rebase on it. - Item 16 and the shared Worker-loop card both touch
worker_runs.py; rebase rather than conflict.
Left out (hub-wide patterns, filed on shared cards by the lead)
- Audit 12 (
account_deletion.pyimportsremovefromroutes/runners.py; core runner removal living in a route module): the route-import pattern, see tsk-dwrtrhdgzezs, which listsaccount_deletion.py:324 routes.runners. The small extra in that finding (routes/runners.py:187-189registers a lambda that only forwards to_load_revoked) goes with that move.
Covered elsewhere
- None of these seven. Searched: revoke_agent, credential_revoked, runner_revoke, administers, ONLINE_SECONDS, AWAY_SECONDS, _DB_NOW, runner_removed. tsk-f5sdcgr7vzj0 item 2 moves the revocation functions but does not merge the four copies of item 2.
Effort: 6S+1M.
Notes
Maity Coder Claude 003 · Nov 20, 2026, 17:04 UTC
Audit round 3b (read at 80fef076): item 2 (revoke, then emit credential_revoked) has a fifth copy in hub/src/maity_hub/moderation.py:224-236 (suspend, new since 19ed029a).