oliver-zehentleitner / maity

clean-up: runners and placements: one agents' user helper, one harness probe, a light gc client, small runner helpers

Sign in to report

tsk-es92hh4pk6tc 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 duplicated helpers and docs drift, outside the supervisor (the supervisor items are on tsk-ch70sv61w8f4).

19. Duplication: the "agents' user" rule is written out four times

  • AsUser(local.agent_user if local and local.layout == "agent_user" else None) appears at runner/supervisor.py:1262-1265 (agents_user), runner/operate.py:68-70 (_as_user), runner/targets.py:91 and runner/capabilities.py:189.
  • runner/commands.py:287 checks the same condition differently (and local.agent_user).
  • Proposal: one config.Local.as_user() that every caller uses. Drop operate._as_user and supervisor.agents_user.
  • Effort S. Risk low.

20. Duplication: harness probing has one copy for local hosts and one for ssh hosts

  • The version regex: runner/capabilities.py:26 and runner/targets.py:31.
  • The --version probe and its parsing: capabilities.py:68-88 (probe) and targets.py:168-180 (probe_remote).
  • The Codex sandbox trial: capabilities.py:125-136 and targets.py:186-192.
  • The Claude sandbox tools: targets.py:28 SANDBOX_TOOLS and capabilities.py:91-101.
  • Finding the binaries: capabilities.which and targets.WHICH, with a third parse of the output in commands.py:455-457.
  • AsUser and Ssh both have .run(), so one probe(runner, harnesses, agent_path) could serve both.
  • Effort M. Risk medium: local probing runs with cwd=Path.home(), and that must be kept.

24. Design and slow path: maity runner gc builds the whole service for one GET

  • runner/operate.py:267 (_active) calls serve.open_service. That runs --version on every harness, tries the Codex sandbox, logs the availability lines and builds a Supervisor with tmux, all for one GET /runner/placements.
  • Proposal: split open_client(cfg, state) out of runner/serve.py:281-298, and use it in _active.
  • Effort S-M (counted as M). Risk low.

26. Duplication: small helpers repeated across the runner

  • The guard load_state(...) if state_dir.is_dir() else {} appears at runner/commands.py:506, 585, 587, 592-596, runner/supervisor.py:319, 1277, runner/workspace.py:122-124 and runner/operate.py:39-42. It is redundant: state.load_state already returns {} for a missing file (state.py:379-380).
  • The UTC stamp is formatted in three places: runner/serve.py:56-58, runner/supervisor.py:184-187 and runner/install.py:404.
  • The pairing-code reader exists twice and behaves differently: commands.py:48-57 lets OSError and UnicodeDecodeError escape, while install.py:797-812 refuses cleanly.
  • TOML quoting: install.py:127-138 (_toml_str) says json.dumps is wrong for TOML, yet commands.py:83-84 and adapters.py:463-489 use json.dumps. In adapters.py the hosts come from the free-form grant.network.
  • config.REMOTE_PATH (config.py:547) is the same regex as asuser.REMOTE_HOME (asuser.py:43).
  • LOGS = "logs" is defined twice: supervisor.py:121 and targets.py:24.
  • Proposal: one helper for each, and drop the redundant guard. Use _toml_str for every TOML value; check whether a grant.network host with a quote or backslash today produces a TOML file that means something else (if it does, that part is a bug, not a clean-up).
  • Effort S. Risk low.

28. Docs drift: the help and docstrings say logs and agent files live in state_dir

  • The maity runner logs help (runner/commands.py:828) says <state_dir>/logs/<placement>.log. The code reads target.agent_files/logs/ (runner/operate.py:96). That is the agents' user's home in the agent_user layout, and the remote home over ssh.
  • runner/adapters.py:5 and :170 (Context.agent_dir) say <state_dir>/agents/<placement>, "the runner's, never the agent's". The code uses target.agent_files / "agents" (supervisor.py:1018), written as the agents' user.
  • Proposal: reword both to "the agents' files directory".
  • Effort S. Risk none.

Order

  • Item 24: tsk-34gb7frfbsk7 (in review) changes operate.py cmd_gc. Do item 24 after it merges.
  • Item 19 removes supervisor.agents_user, and tsk-ch70sv61w8f4 splits supervisor.py. Do item 19 first, or rebase.

Covered elsewhere

  • Audit 27 (the project full-name regex defined three times: runner/config.py:38 with parts of 2-63, runner/workspace.py:31 and cli.py:128 with 1-63, the hub's namespace.py:33 with owner 2-31 and slug 2-63): tsk-egaycsbdwmeq item 9 (one maity/names.py, which already names runner/workspace.py:31). runner/config.py:38 should be added to that item.
  • Searched: agent_user, probe_remote, capabilities.py, open_service, runner gc, load_state, _toml_str, REMOTE_PATH, agent_dir.

Effort: 3S+2M.

Notes

  1. Maity Coder Claude 003 · Nov 13, 2026, 23:16 UTC

    From the clean-up audit tsk-hgnbapyw7hnh (round 2, CLI/runner changes since 80647565), read at 19ed029a. This adds to item 20 (harness probing for local and ssh hosts). Paths are under cli/.

    Done since round 1: the version regex has one copy now, capabilities.VERSION (src/maity/runner/capabilities.py:29), and targets.py:178 uses it. The rest of item 20 is still open.

    New, same topic: the rule "may the sandbox be switched on" is put together in five places. #1752 added a version gate, capabilities.sandbox_version_ok (capabilities.py:53-67). Each caller joins it to sandbox_available or to the tools check itself:

    • capabilities.py:196-199, harness_entry (local, when sandbox is None)
    • runner/targets.py:111-112, local (target.sandbox)
    • runner/targets.py:193-198, probe_remote (ssh hosts)
    • runner/commands.py:404, _check_claude_code, which works out the reason again (OS, missing tools, version)
    • runner/commands.py:500-505, _check_host. When the sandbox is off it works out the reason again and hard-codes "(bwrap or socat missing)" next to targets.SANDBOX_TOOLS.

    On the local target, harness_entry and targets.local make the same which calls and the same version check twice: once for the advertised capabilities and once for the placement.

    • Proposal: when item 20 creates the shared probe, give it a single sandbox_on(harness, tools_found, version) -> (bool, reason). Both targets store its result, harness_entry and check read the stored result, and the reason text is built in one place. capabilities.build can pass target.sandbox instead of calling sandbox_available again.
    • Small: on = sandbox at capabilities.py:200 is an alias left over from the change. Use sandbox directly.

    Tests: the version table is tested four times. The full unit table is in tests/test_adapters.py:206-226, which is the wrong file because the function lives in capabilities. Parts of it are repeated end to end in tests/test_ssh.py:579-598 (7 cases, each runs the fake ssh host), tests/test_supervisor.py:354-382 (9 cases, each builds a Supervisor) and tests/test_serve.py:259-273. Once the rule is one helper:

    • Move the unit table to a capabilities test.
    • Keep one passing and one refused case per integration path.

    Effort: adds S to item 20 (M). Risk: low. check output and the sandbox_unavailable detail must stay the same, and tests/test_runner.py:584-600 pins the check text.