oliver-zehentleitner / maity
clean-up: runners and placements: split runner/supervisor.py, dead code, idle writes of actual.json
tsk-ch70sv61w8f4 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 cli/src/maity/.
This card holds the CLI runner's supervisor and dead-code clean-ups.
22. Debt: runner/supervisor.py (1291 lines) does at least five jobs, and repeats rules inside itself
- Besides the reconcile loop it holds: the join (
:50-114and:958-1006); the §15.14 idle and nudge check (:605-732); reading the limit file (:734-780); the sandbox's private paths (:1204-1259); helpers for other modules (:1262-1277). - Rules written twice inside it:
- The restart decision after an exit:
:596-603and:937-944. Only the first logs the crash loop. - A generation change resets
Recordfully at:495-501, but only partly at:425-427:retry_at,hung_exits,resumeandlimits_unknownare kept there. That is harmless today only becausefailedwaits for the next generation. - "rm as the agents' user, else unlink":
:753-758and:972-976. - The repository grant lookup:
:803-804and:1020/1029. - Proposal: move the join, the idle check and the private paths to their own modules. Add
Record.new_generation(),_restart_or_fail()andAsUser.remove_file(). - Effort M. Risk low to medium.
23. Debt: dead or test-only code (callers grepped across cli/src and cli/tests)
- Written but never read:
Supervisor.advertised_running(runner/supervisor.py:282, set at:1144). - No caller:
Supervisor.agent_path()(supervisor.py:1076-1078) andclonecheck.config_names(clonecheck.py:228-231). - Used only by tests:
Supervisor.as_user(supervisor.py:1067-1071);tmux.attach_hint(runner/tmux.py:163-165; production usesTarget.attach_hint, which repeats it);Tmux.type_line(tmux.py:345);Tmux.environment_of(tmux.py:350). operate.not_inspectable(runner/operate.py:223-225) is a pass-through.capabilities.build(running=...)is never given a value.- Proposal: delete these, or inline them.
- Effort S. Risk low.
25. Debt and slow path: actual.json is written every tick even when nothing changed
Supervisor.tickcallsself.save()unconditionally (runner/supervisor.py:402). Each save is an atomic write with fsync (state.py:190-197). An idle runner therefore writes and syncs the file about 17,000 times a day.- Proposal: skip the write when the serialised text is unchanged. Keep the save before a
seqis sent (supervisor.py:1188). - Effort S. Risk low.
Minor: a broad except without a log line
runner/supervisor.py:776hasexcept Exception: return None, so a bug in reading the limit file silently becomes "no exit code".- Proposal: narrow it to
(OSError, subprocess.TimeoutExpired, ValueError). - Effort S. Risk low.
Order
- Do items 23, 25 and the minor one first (small, independent), then item 22 in its own PR.
- tsk-34gb7frfbsk7 (in review: remove a stopped placement's workspace) changes the runner's stop path and
operate.py. Rebase item 22 on it if it has not merged yet. - Item 22's
AsUser.remove_file()and tsk-1xv8fjfzbh93 (bug: GNU-onlyfind -printf) both touchrunner/asuser.py; rebase rather than conflict.
Covered elsewhere
- None. Searched: supervisor.py, actual.json, advertised_running. The open P3 roll-up tsk-9466cn6bnbgz matches supervisor.py only in its notes; check it before starting.
Effort: 3S+1M.
Notes
Maity Coder Claude 003 · Nov 20, 2026, 11:52 UTC
Audit round 3 (tsk-hgnbapyw7hnh), read at 588f911b:
cli/src/maity/runner/supervisor.pygrew from 1292 to 1947 lines in 19ed029a..588f911b, with four broad excepts (:445, :494, :1027, :1267) and atype: ignoreat :1628. The new scratch,/tmpscratch and worktree-prune code (:515-590, :1395-1525, :1188-1197) is a natural first module to split out.