oliver-zehentleitner / maity
runner: placements keep scratch inside their workspace, and the runner cleans up after them
tsk-dpe3d5g5eh4k Done An agent
The maintainer, 2026-11-16: on the old VM, the agents' home directory filled up with leftovers because no agent cleans up. Reviews leave evidence folders, temporary clones, worktrees and venvs behind.
On the runner, this should not happen in the first place:
- Each placement's workspace has a known place, and the runner can show its size.
- Scratch space for a review or test leg lives inside the placement's workspace, not in the shared home.
- The runner cleans up the scratch of a finished or removed placement. An admin can see what was removed.
- Agent briefings (the reviewer and tester roles) say: delete your own scratch after you report.
Design note to the lead first: what the runner owns, what the agent owns, and what is never deleted (the clone and the agent's memory).
Notes
Lotse · Nov 17, 2026, 21:19 UTC
#1917 description of record for head 475e30de7b8d9997c11331952a2a5da2db90c0e7, part 1 of 2 (GitHub body with the "Ran" and "Fixes from review" lines from q445 155732):
Cards: tsk-dpe3d5g5eh4k (part 2, the runner's side of the scratch) and tsk-0yzfd6aq44e6 (part b, reading a named file from the scratch). Based on main since #1915 (the contract) is merged as 05a275c0. The change is the diff against main,
git diff origin/main...HEAD.A placement's scratch, as docs/api.md §15.5 describes it after #1915:
- Made at the start for Claude Code, Codex and the stub:
<workspaces>/<project_id>/.scratch/<placement id>withtmpin it, as the agents' user (Supervisor._scratch). A scratch, or a.scratchabove it, that is a link: no scratch, one log line, the session starts without one. agy and opencode get none (workspace.SCRATCH_HARNESSES). - Told to the session:
MAITY_SCRATCH, andTMPDIRinside it. Claude Code:sandbox.filesystem.allowWriteplus Read/Edit/Write rules for the file tools. Codex: the path opened aswriteunder the hidden workspaces root. The path also goes into the runner's records for the agent (clonecheck.SCRATCH_RECORD, besidegitandpull_requests). - Read from: under a placement,
inclone.readtakes a path outside the clone when it lies in the recorded scratch. It uses the same walk: no link at any step, a regular file, one hard link. The record names the directory, never the variable (inclone.recorded_scratch). This coverscli._placed_readandmaity gh --body-file. Writing (files get -o) stays in the clone. - Removed: after each read of the active placements,
servealso readsGET /runner/placements?closed=true. A 4xx is logged and skipped, a 5xx/429 retried like the other reads.Supervisor._clear_scratchremoves the scratch of each closed placement once no session of it runs, on every reachable target, and never through a link (logged once). Each removal goes to the log and toremoved.jsonlin the state directory (the newest 1000 lines are kept). Removal after a stop comes with the clone's retention clock (tsk-34gb7frfbsk7, not here).
- Made at the start for Claude Code, Codex and the stub:
Lotse · Nov 17, 2026, 21:19 UTC
#1917 description of record for head 475e30de7b8d9997c11331952a2a5da2db90c0e7, part 2 of 2 (GitHub body with the "Ran" and "Fixes from review" lines from q445 155732):
- Operator's view:
maity runner statusshows each placement's clone and scratch size, measured at most every 10 minutes as the agents' user (the clone withdu -sbP, the scratch with the runner's own scratch operation).--removedlists the last 20 removals, also in--json.maity runner gc --scratch [--yes]lists every scratch whose placement is not active, and removes it with--yes. Entries not named like a placement, and links, are listed as left. - Briefing: the reviewer and tester role texts (hub
guide.ROLE, the contract table, the web fixture) say to keep evidence, scratch clones and venvs in$MAITY_SCRATCHand delete them after reporting. docs/agents.md says how to check out another head there: a clone of the clone, because the runner refuses worktrees and Claude Code protects.git/worktrees. It also says thatenv/git cloneneed the repository's grant under Claude Code. - docs/runners.md section, KTW entry 783e476c extended (the read reaches the recorded scratch, plus why not the variable), changelog.
Tests: supervisor (made with tmp, env, record; removed only after the session is gone, once; links never made, never removed, logged once; harness choice; sizes saved), adapters (Claude/Codex grants, nothing without a scratch), placed reads (sent from the scratch; refused beside it, through a link, with a linked scratch, without a record, with an empty record or a record into the clone), serve (closed read after the active one), gc --scratch, status sizes and --removed.
Ran: CLI suite: the affected suites pass. black/ruff/mypy clean. Hub contract tests as CI runs them 207 passed. web check 0 findings,
LANGUAGE=en_US make smokeall ok. ktw-lint ./cli/hub 0/0. Changelog ok.Fixes from review:
maity runner scratchopworks only on a placement's scratch below the root it is given, andmaity runnerrefuses its operator commands to a placed agent; the remaining in-session commands are tracked on tsk-54492gk4xp69. What is emptied when a scratch is removed is the directory that was measured; its name is checked just before the removal. Removal after a stop on the clone's clock is marked as not built yet.- Operator's view: