DocsThe loop
The loop
The loop is a flag on an issue (#204). While the flag is on, the desk server reads the "Done when" lines of the issue at each event of the server, does the work that a line needs, and closes the issue when every line is met. The design is #204; the owner decided it on 2026-11-12.
The loop runs on the server. A person sets it through the MCP (loop_*) or the CLI (desk loop …); nothing runs on the machine of the person, and the loop needs no file, job or timer there.
The flag and the lines
The flag is one line of the body of the issue:
**Loop:** on
on, yes and true switch the loop on, in any letter case. Any other word, and no flag line, leave the issue as it is today. desk loop remove sets the flag to off, and desk loop add writes on.
The loop reads the lines of the section ## Done when. Each line is a task with a verifier:
## Done when
- [ ] `npm test test/loop.test.mjs` passes — **test** npm test test/loop.test.mjs
- [ ] `npx tsc --noEmit` exits 0 — **check** npx tsc --noEmit
- [ ] the page `docs/loop.md` is in the landing — **docs** docs/loop.md
- [ ] the landing deploys `desk-server` — **deploy** desk-server
- [ ] a reader can follow the example end to end — **judge** a reader can follow the example end to end
The server decides a docs and a deploy line from the newest landing of the issue in this repository, after the start of the loop (#270):
- A
docsline is met when the landing changed the path. The path is a path of this repository: a path whose first folder is the name of another repository of the server (example-site/docs/BRIEF.md) can never be met, sodesk loop addrefuses it. For a file of another repository, write ajudgeline that reads the landing of that repository. - A
deployline names a deploy target or an image of.desk/config.json. It is met by a desk deploy of the landing, or by the promotion of the image of that name: the cluster follows the promoted tag (Keel). A deploy of a target carries the digests that its run set inruns.deploy.images, and the line is met when each of them is the newest build of that image; the run of a target has no artifact of its own, so a search for an image of the name of the target never finds one. A landing that changed no file of the image meets the line with the newest promotion before it.desk loop addrefuses a name that the config does not have, and names the ones it has. - While the issue has no landing, the loop starts the worker for the first open
docsordeployline: the landing is the work of the worker.
The checker gets the start of the loop: a landing, a run or a deploy of before that time is not the work of the issue, and it meets no line.
A test or check line runs its argument as a command line on a runner, and its exit code is the verdict. A line whose argument is only the path of a source file (test/x.test.mjs) is a problem of the issue: write the command that runs the file, such as node --test test/x.test.mjs.
A loop that is paused, set active again after a stop, or removed ends its queued run, so no runner starts a run that the loop no longer reads.
A line without a verifier is a problem of the issue, and the loop does not start. desk issue check names that line, because the loop reads every issue of the repository and not only the issue whose flag is on. desk loop add refuses the issue and names the line.
The default of a repository
The loop of every new issue follows the setting loop.default of the repository (#233). The setting has three values:
| Value | What it does |
|---|---|
on |
The issue enters its loop when its work starts: at a claim, or at the first change that names the issue with --intent. |
off |
The issue stays with its agent, and only desk loop add or **Loop:** on starts the loop. |
| no value | The repository takes the default of desk, which is off. |
An issue with no typed line in "Done when" takes no loop, because no verifier can decide its lines. The claim and the change still succeed, and the loop writes the reason to the log of the server.
A person sets the setting in three places:
- The API:
POST /v1/repos/<owner>/<repo>/settingswith the body{"loopDefault": "on"},{"loopDefault": "off"}or{"loopDefault": null}. The route answers the value that the repository keeps. - The config route and the UI:
GET /v1/config/<owner>/<repo>answersloopDefault, and the page of the repository shows a button for each value. - The CLI and the MCP:
desk repo lanes --repo <slug> --loop-default onsets the value,--loop-default defaultclears it, and the toolloop_defaultof the MCP runs the same command.desk repo lanesprintsloop.default <value>.
The migration 055_run_token.sql adds the column repos.loop_default, so the setting is one column of the repository and no file of the repository is necessary.
The token of a run of the loop
A line of the kind test, check or judge reads the server: the log of a landing, the state of a run and the body of its issue. A run of lane loop therefore holds a token of the server for the length of the run (#233):
- The claim of the run is on lane
loop, so the server mints a token for the identityloop-<owner/repo>, with the rightreadon that repository and the length of120minutes. - The claim carries the token, and the runner puts it into the run as
DESK_TOKEN. - The token needs no file and no secret of the repository, and it ends with the run. The column
identity_tokens.expires_atholds the end, and a token that expired answers nothing.
The step of a worker does not see that token, because sandboxEnv removes it: a worker edits the files and lands a change, and the loop reads the evidence.
The two lanes of a loop
A loop queues two kinds of run (#233):
- The command of a
testorcheckline runs on the laneloop, on the runners of the cluster. Its exit code is the verdict. Atestrun that exits 0 and ran no test is a miss:testsRunreads the summary of libtest, nextest,node --test, Buck2, pytest andgo test, and a filter that matches no test (running 0 testsin each binary) gives the evidence "passed and ran no test". A lineSKIP: <why>in the log is a test that skipped because its service is absent, and it does not count; atestline of such a test runs with-- --nocapture, so libtest prints the line. - The checker, the review and the worker run on the lane
agent. A runner on the machine of the owner claims that lane (desk runner service install <name> --lane agent --org <org>), so the agent harness uses the login of that machine, and no test of a line runs there. A run of that lane keeps the variables of the login of the runner (AGENT_VARSinsrc/server/sandbox.ts:HOME, theXDG_*folders, the session bus,PI_CODING_AGENT_DIR), sopireads its provider in~/.pi/agentand its key fromproxium token. The token of the runner stays out.
A missed line sends the worker back with the evidence of the verifier, up to maxRespawns times, when the worker kind runs in the foreground (paseo, pi, claude, opencode, codex or command). The worker gets the open lines and the findings, makes a work folder with desk checkout, runs desk try, and lands; the landing wakes the loop, and the loop runs the line again. A worker kind that returns at once (pool, herdr), or a loop that used its respawns, writes the report and waits. A line that the checker answers with waits (time to pass, a release to production, or data that only real use makes) sends no worker back: the loop writes what the line waits for, sets waiting, and runs the line again after 6 hours (RECHECK_HOURS, column loops.recheck_at). A checker run that no model answered (a breaker, a used-up quota, a rate limit or a 503: VENDOR_FAULT) is no verdict and does not stop the loop: the loop waits and runs the checker again after 30 minutes (VENDOR_RECHECK_MINUTES). A worker run that failed for the same cause did no work: the loop gives its respawn back, waits 30 minutes, and runs the open line again, so a missed line sends the worker again.
A run of the lane loop also gets the secrets that .desk/config.json names in loopSecrets ({"VAR": "<id>"}), so a check line can call the dev deployment with its key (munhq/axon#601). The claim of a run of the lane loop carries the token of the run (mintRunToken), and the runner puts it into the step as DESK_TOKEN and keeps it out of the live log. A run of the lane agent gets no run token: its checker and its worker use the login of the machine, and a worker lands its change with it. Each checker and worker run gets PROXIUM_GOAL: one ASCII line with the open lines of the issue (goalLine), and the pi extension proxium-loop-goal.js of the machine sends it as the header x-proxium-goal, so Proxium shows the goal of the conversation in its Loops view and checks the answers against it. A pi checker or worker logs only the message_end events of the assistant, so a long worker stays under the log limit of the run.
The pod of a run of the lane loop
A run of lane loop starts the agent harness inside the pod of its runner, and the pod holds the harness and the key of its model:
- The image of the runner carries the harness.
piis in the image of the pool (docker/base/runner-rust.Dockerfile,ARG PI_VERSION), so a runner of the lane loop startspi -p <prompt> --mode jsonwith no other image. - The harness reads its model from the setting
modelof the loop (or--model), and its provider frommodels.jsonin the agent directory.PI_CODING_AGENT_DIRmoves that directory, so a deployment mounts the file it names and needs no id of a gateway in the image. - The key of the gateway arrives as an environment variable of the pod, and
models.jsonnames it as$NAMEinapiKey. The chart of munhq/k3s-gpu copies the key from Vault intoPROXIUM_API_KEY.
The close of an issue
The loop closes the issue when every line is met, and a person closes any issue. An agent cannot close an issue whose "Done when" holds a line with a verifier, because the agent that closes the issue would write the check itself. The server refuses that close with the name of the loop command, and the issue stays open. desk loop tick --repo <slug> --issue <n> is the way for the loop to close it.
The five verifiers
| Verifier | What the line names | How the loop decides |
|---|---|---|
test |
A command that runs the tests | The loop queues a run on lane loop with the command of the line. The line is met when the run passes. |
check |
A command, or GET <url> answers <code> |
The same, and a GET line becomes test "$(curl -sS -o /dev/null -w '%{http_code}' <url>)" = "<code>". |
docs |
A path of the repository | The loop reads the tree of the newest landing of the issue. The line is met when the tree holds the path. |
deploy |
The name of a deploy target or of an image | The loop reads the deploy of the newest landing of the issue. A target is met when each image that its containers run is the newest pushed build of that image (runs.deploy.images); an image is met when the landing deployed or promoted it, and it is the newest one pushed. |
judge |
The sentence that a reader must agree with | The loop queues the checker with the prompt, and reads its verdicts from the log of the run. |
The loop closes the issue only when all five kinds of line are met. A line that fails sends the worker back with the evidence of the failure; a docs or deploy line that the newest landing does not meet also sends the worker back. After maxRespawns failures the loop stops and writes a question to the issue, and the issue stays open.
The settings of one loop
| Setting | Default | Meaning |
|---|---|---|
worker |
pool |
The kind that does the work of a failed line: pool, paseo, pi, opencode, claude, codex, herdr or command. |
model |
none | The model of the worker, for the kinds that take one. |
template |
none | The command line of the kind command, with {prompt} or {text}. |
checker |
judge |
The kind that reads a judge line. |
checkerModel |
none | The model of the checker. |
maxRespawns |
3 | How many times the loop sends the worker back before it asks the owner. |
maxCostUsd |
20 | The limit of the cost of the loop. A loop at its limit stops and asks the owner. |
A worker or a checker of the kind pool has no agent to run, so the loop refuses it with a question to the owner and names the setting to change. command needs a template with {prompt} or {text}.
A checker answers in the log of its run, so it runs in the foreground: paseo (paseo run --provider pi/<model> --output-schema <the verdict schema>, which waits for its agent and shows it in paseo ls), pi (pi -p … --mode json), claude (claude -p … --output-format json), opencode, codex or command. The loop refuses pool and herdr as a checker, because each returns before it answers. The loop reads the answer from the last assistant event of pi, or from the result of claude, and not from the rest of the log, which repeats the prompt. The program must be on the machine of the runner of the lane agent.
A checker run that does not pass, or whose answer holds no verdict, decides no line and writes no evidence on it. The loop stops once with the cause and the end of the log of the run, for example the checker run 8969 ended failed (exit 127); the end of its log: /bin/sh: 1: claude: not found.
The events
The loop does not poll the issue. It ticks at these events of the server:
- A landing of the repository: the tick reads the issue of the landing.
- The end of a run of the repository, and this covers a stopped agent and a model call of the runner: the tick reads the line of that run.
- A comment on the issue: the tick reads the answer of the owner to a question of the loop.
- A tick that a person asks for:
POST tickordesk loop tick.
The events of one repository are coalesced into one tick. The server also ticks every 3 minutes and 45 seconds, the fallback for an event that was lost; a lease in close_sweep_leases named loop gives one server process the tick, so two servers never tick the same loop.
The routes
All routes are under /v1/loop/<owner>/<repo>/ and need Authorization: Bearer <token>.
| Route | Right | Answer |
|---|---|---|
GET list |
read | {"loops": [<loop>]} |
GET status?issue=<n> |
read | {"loop": <loop>}; 404 when the issue has no loop |
GET config |
read | The kinds of worker, the five verifiers, the defaults and fallbackMinutes |
POST add {"issue", <settings>} |
merge | The loop of the issue; 422 when the body has no typed line |
POST set {"issue", <settings>} |
merge | The loop, with the settings that the body names |
POST remove {"issue"} |
merge | {"removed": true}, and the flag is off |
POST tick {"issue"?} |
run | The loop of the issue, or every loop of the repository |
A loop answers with repo, issue, title, state (active, paused, done or blocked), worker, model, template, checker, checkerModel, maxRespawns, maxCostUsd, respawns, costUsd, run, blockedReason, startedAt, tickedAt and lines: ordinal, text, verifier, arg, met and evidence.
A repository that does not run the loop opens its lane at the first loop: a caller with the right merge on the repository does it, and the server writes the field loop of the repository. A caller without that right reads 409, and a person opens the lane with desk repo lanes --loop.
The CLI and the MCP
desk repo lanes --loop
desk loop add --issue 12 --worker paseo --checker pi --checker-model <a model of another family>
desk loop status --issue 12
desk loop list
desk loop tick --issue 12
desk loop set --issue 12 --max-respawns 5
desk loop remove --issue 12
desk loop config prints the kinds, the verifiers and the defaults. The MCP has one tool for each subcommand: loop_add, loop_set, loop_remove, loop_tick, loop_list, loop_status and loop_config. desk loop reads the repository of --repo or of the folder; desk repo lanes takes --runner, --base and --loop, each with a --no- form.
A worked example
- A person writes the issue with the five lines above and runs
desk loop add --issue 12 --worker paseo. - The server writes
**Loop:** on, reads the five lines, and postsThe loop starts.to the issue. - The worker lands
docs/loop.mdand the test of the loop. The landing wakes the loop. - The tick reads the tree of the landing: the
docsline is met. It queues the run of thetestline and the run of thecheckline on laneloop. - Both runs pass. The tick queues the checker with the
judgeline and the evidence of the other lines. - The checker answers that the line is met. The
deployline reads the image of the landing. - Every line is met: the loop posts
The loop verified 5 of 5 lines of "Done when", ticks each line in the body, and closes the issue.
The limits
- One loop for each issue.
- 50 loops for each tick of a repository.
- One tick for each 15 minutes of a lease, and one tick of the fallback for each 3 minutes and 45 seconds.
- The loop never writes to the machine of the person: every action of the loop runs on the server.
desk and Proxium
The loop and the verification of this page rest on one contract, and Proxium keeps the same contract. Each product keeps the contract alone. When both products are present, one product owns each part, so no part runs twice. The Proxium twin of this contract is munhq/axon#589.
The six rules of both products:
- The agent does not grade its own work. Only a verifier outside the agent decides that a goal is met.
- The goal is held out. After the owner approves it, an agent cannot change the goal or its checks. A change becomes a question for the owner.
- The checker is independent. A checker that reads a sentence (
judge) is of another model family than the worker. It gets the evidence and the goal, and not the dialogue of the worker. - The checks cannot get weaker in silence. The system holds or reports a change that removes or narrows a check.
- The checker is measured. Each product replays known cases, and it reports how many its verifier finds.
- Each product works alone. When both are present, each part has one owner, so no part runs twice.
The table of the parts. The words are the same in both repositories: goal, line, verifier, verdict, checker, worker and stall.
| Part | desk alone | Proxium alone | Both present: owner of the part |
|---|---|---|---|
| The goal | The "Done when" lines of an issue, each with a typed verifier (test, check, docs, deploy, judge) (munhq/desk#204) |
The stop condition of a conversation, from a header, an MCP call or a link (munhq/axon#578) | desk: Proxium reads the lines of the linked desk issue as its stop condition |
| The verdict | The loop on the desk server runs each verifier and ticks the line (munhq/desk#204) | The verifier of munhq/axon#578 scores the stop condition with the goal check of munhq/axon#548 | desk ticks the lines; the goal score of Proxium is evidence for a judge line |
| Held-out goal (rule 2) | munhq/desk#206, item 1 of comment 4503 | munhq/axon#589, step 1 | desk |
| Independent checker (rule 3) | munhq/desk#206, item 3 of comment 4503 | munhq/axon#578, and step 2 of munhq/axon#589 | The product that runs the check |
| Weaker checks (rule 4) | munhq/desk#206, part 2: the weakening guard on landings | munhq/axon#589, step 3: a stop condition that narrows during a run, and a "done" of the agent that the verifier refuses | desk for code and checks; Proxium for the conversation |
| Measured checker (rule 5) | munhq/desk#207: replay old fixed bugs | munhq/axon#589, step 4: replay recorded runs with a known outcome against the verifier of munhq/axon#548 | Each product for its own verifier |
| The live guard of a run | The loop counts respawns and cost (maxRespawns, maxCostUsd) (munhq/desk#204) |
The loop guard of munhq/axon#576: iterations, cost and stalls on the request path | Proxium counts and reports the stall; desk decides |
| Continue or restart a stopped run | The loop sends the worker back (munhq/desk#204) | The runner of munhq/axon#578 continues the loop server-side | desk; the runner of Proxium continues a run only when desk asks for it |
| The status for the owner | loop_status (munhq/desk#204) |
The Loops view of munhq/axon#576 | Each product shows its own part, and the status that an agent reports reads both, not the words of the worker |
A row stays in the table when a landing builds it. scripts/check-loop-contract.mjs refuses a page that drops a rule, a row or an issue of the table, and it checks each issue number against the list of the contract.
The tests
test/loop.test.mjs reads the lines and their problems. test/server-loop.test.mjs ticks a loop against a real Postgres: one tick closes the issue from the tree of a landing, one tick sends the worker back with the evidence of a failed run, and one tick asks the owner when the retries reach the limit. One pass of the reported line of a waiting loop puts the loop back to active, and the loop reads the next line.
Release
The release v0.21.17 of 2026-11-13 is the first release whose package carries the desk loop (#204).