oliver-zehentleitner / maity

clean-up: runners and placements: one revoke-and-tell, one due rule, one presence ladder, runner admin lookups

Sign in to report

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-64 revoke_agent; placements.py:1266-1286 _revoke_removed; auth/leaks.py:59-70 inside revoke_leaked; routes/members.py:1584-1595 revoke_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 to revoke, 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-41 due(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 of runner_revoke.REASON.
  • hub/context/placements.md:154-156 rejects "two functions ... repeat the same three-line check for no gain", yet views.py repeats it twice. The same entry, placements.md:146-147, says due is called on "revoke_agent's path". It is not: revoke_agent (runner_revoke.py:45) never calls due. The callers are auth/caller.py:505 (agent and runner rows), runner_revoke.py:70 (revoke_due) and not_listening.py:135.
  • Proposal: have views.py call runner_revoke.due and use REASON. Correct the caller list in placements.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 a runner_id parameter for exactly this. Its only caller (routes/placements.py:296) never passes it.
  • Proposal: use active_count in attachment_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-858 collects and returns still_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 same RUNNING_STATES test.
  • Proposal: make runner_removed return 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-107 presence; views.py:376-394 presence; instances.py:294-306 presence, with its own constants at instances.py:291 (ONLINE_SECONDS, AWAY_SECONDS) that repeat views.py:34-35. landing_stats.py:29 defines 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-93 administers() reads the membership and calls has_scope(..., "members:admin"). routes/runners.py:550-564 (list_runners) does the same in bulk, inline. visible_to (runners.py:196-203) also runs administers once per attached project.
  • Proposal: add runners.administered_project_ids(conn, human_id), and use it in both list_runners and visible_to.
  • Effort S. Risk low.

16. Design: worker_runs reaches into listening's private names

  • worker_runs.py:39, 88 and 97 use listening._DB_NOW (defined at listening.py:51), and worker_runs.py:106 uses listening.POD. The database clock expression has nothing to do with long-polls.
  • Proposal: move _DB_NOW to clock.py or db.py as a public name, and import it from there in both modules.
  • Effort S. Risk none.

Order

  • Do tsk-mrt77xgrexx4 (bug: runner_credential_gone missing on suspension and re-pair) first; item 2 touches the same functions.
  • Item 2: after tsk-f5sdcgr7vzj0 item 2, which moves revoke and revoke_runner_credential from auth/leaks.py to auth/revocation.py. Put the new helper there.
  • Items 2, 3 and 11: tsk-mknw2my8zq4c (security, in progress) is changing runner_revoke.py and routes/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.py imports remove from routes/runners.py; core runner removal living in a route module): the route-import pattern, see tsk-dwrtrhdgzezs, which lists account_deletion.py:324 routes.runners. The small extra in that finding (routes/runners.py:187-189 registers 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

  1. 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).