Repository navigation
feat(mocactl): get --wait and spawn --max-concurrent (#381) - #918
Conversation
Two of rossoctl#381's remaining items. The rest of its scope either shipped already or has no reachable input: - `get SESSIONID --wait [--timeout S]` blocks until the result is collectable, answering @evaline-ju's point that a coding agent's collect turn needs one blocking call with the result inline — the opposite of a batch shape. Polls every 2 s to a 300 s default budget it never overruns, re-minting the session token mid-wait because SH_SESSION_TOKEN_TTL_SECONDS defaults to the same 300 s. Stops early on a ledger row that can no longer produce a result, reporting `unknown` rather than waiting out the clock. - `spawn --max-concurrent N` (default 4) refuses a dispatch before any session, worker or round trip exists. The count is liveness-gated, so a stale `running` row from an unreconciled crash cannot hold a slot and wedge `spawn`. Item 9's honest running/unknown states were already shipped in transport/leaf-turn.ts and wired into `subagents`; `--wait` is what finally makes `get` consult them. Item 7's `follow-up` is already `run "prompt" --session ID`, now documented as such. Batch `watch` is deliberately not built: rossoctl#495's open question 3 (what it prints so hundreds of tasks stay readable) is still unanswered, and `subagents --tag T` already returns the snapshot a Monitor poll consumes. `approve`/`reject` are unreachable until `spawn` accepts `--kind converge`; follow-up to be filed. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review — feat(mocactl): get --wait and spawn --max-concurrent (#381)
Both features do what the description says; the details that usually go wrong here are right.
get --wait
- The timeout cannot overrun: the
rt.now() + WAIT_POLL_MS > deadlinecheck is before the sleep, and the timeout path returns'queued'into the samecmdGetbranch that already printedstatus: "queued"and exited 1, so the "byte-identical" claim holds by construction (and the test pins it). - The token handling is correct for the right reason:
SessionToken.expiresAtis epoch seconds (handlers.ts:1233isiat + sessionTokenTtlSeconds), and the refresh test isrt.now() / 1000 >= token.expiresAt - 30— the unit conversion is right and the 30 s margin covers a poll plus a slow mint. Re-minting per iteration when the mint is stale is cheap. - The early stop is consistent with
subagents:noResultComingreusesmapHonestState('queued', {alive:false, observedAt}, now), soget --waitandcmdSubagentscannot disagree on when a dead child becomesunknown; the terminal-row case needs no grace at all, which is right because the ledger is the authority there. --timeoutwithout--waitis refused rather than ignored, and--wait/--timeoutare refused on other commands — the#419precedent, consistently applied.- A foreign
sessionId(no ledger row) simply polls to the deadline: correct, and documented in the comment.
spawn --max-concurrent
- The gate runs after the local argument checks and before the workload preflight, and
requireReadyonly inspectsrt— so "before a session, a worker or a round trip" is literally true. --max-concurrentis validated to1–9999(so0cannot wedgespawn), defaults to 4, and is refused outsidespawn.- The count is liveness-gated exactly as the comment says: non-terminal and a live
childPid; a row whose child is gone (or that never got a pid) holds nothing, so the "unreconciled crash wedges spawn" failure mode is closed.isAliveis the samekill(pid, 0)helper the ledger already uses for state mapping.
Tests/docs: six --wait cases (poll, single read without the flag, timeout shape, dead child, terminal row, live child) and four cap cases (refuse, allow, stale rows, default), plus the docs section with exit codes and the unknown vs queued distinction plus the follow-up note. CI is 18/18 green.
One suggestion inline about Ctrl-C during --wait, and a body nit: the get tests mint with expiresAt: 999, which is always past, so every poll re-mints and the "reuse a still-valid token" branch is never exercised — a second seam with a far expiresAt would cover it.
Author: cwiklik (MEMBER — maintainer). Agent/IDE config: none. Commits: 1, signed off.
| } | ||
| // Checked before sleeping so the wait never overruns the budget. | ||
| if (rt.now() + WAIT_POLL_MS > deadline) return 'queued'; | ||
| await rt.sleep(WAIT_POLL_MS, opts.signal); |
There was a problem hiding this comment.
suggestion: Ctrl-C during --wait does not end the wait cleanly. sleep resolves early on abort (it is setTimeout + an abort listener, no rejection), so the loop goes round once more: mintSessionToken (which takes no signal) then readLeafState with an already-aborted signal, which the transport wraps as a network error. The user sees an error line and exit 1 instead of the documented 130. workloads.ts has the pattern for this — check signal?.aborted and return 130 — and here it would be cheapest right after the sleep (or at the top of the loop), before the mint.
There was a problem hiding this comment.
Good catch, and right on both halves — core/time.ts:3,8 resolves on abort rather than rejecting, so the loop went round for a mint plus a doomed read. Fixed in 2b1223e.
I took your pointer to workloads.ts and checked in both places it does: after the sleep, and inside the catch. The second one matters for the same reason as the first — an interrupt can land mid-read, not just in the poll gap, and --wait now holds that window open for up to 300 s. Both return 130 bare with nothing printed, matching cmdWorkloadGet at workloads.ts:321; the user is the one who stopped it.
One thing worth recording: without the post-sleep check the new test doesn't just fail, it hangs. The aborted iteration goes on polling a still-queued session, so the real pre-fix symptom on a session that never finishes is worse than an error line — it's a --wait that ignores Ctrl-C until the budget runs out.
Also documented, since it was only true by accident before: the subagent keeps running after the interrupt, so a later get still collects it.
`core/time.ts`'s `sleep` resolves on abort rather than rejecting, so an interrupt during the poll gap left the loop to go round once more: `mintSessionToken` (which takes no signal), then `readLeafState` with an already-aborted signal, which the transport wraps as a network error. The user got an error line and exit 1 where 130 was documented. Checked in the two places `workloads.ts` checks: after the sleep, and in the catch, so an interrupt mid-read is also 130 rather than the wrapped error. Both return bare, printing nothing — the user is the one who stopped it, matching `cmdWorkloadGet`. Without the post-sleep check the new test does not merely fail, it hangs: the aborted iteration polls a still-queued session forever. The subagent keeps running either way, so a later `get` still collects it; the reference now says so. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Summary
Adds the two items of #381 that were genuinely missing —
mocactl get --waitandmocactl spawn --max-concurrent— and documents the two that turned out to already exist.#381's scope drifted since it was written in October at
24c6f5e: spawn, subagents, get(#496) and the workload commands (#520, #552/#675) have all shipped, and #495 closed on
2026-11-16 confirming the CLI converged on mocactl.
mocactl get SESSIONID --wait [--timeout S]blocks until the result is collectableinstead of reading once. This answers @evaline-ju's 2026-10-26 comment on #381: a coding
agent's collect turn needs one blocking call with the result inline, which is the opposite
of
watch's batch shape.overruns
--timeout.SH_SESSION_TOKEN_TTL_SECONDSdefaults to 300 s —exactly the default budget — so a single mint up front would expire mid-wait.
window, or the row is already terminal), reporting
unknownwith the reason rather thanwaiting out the clock.
get(status: "queued",exit 1). Only the genuinely-new
unknowncase adds a status value.mocactl spawn --max-concurrent N(default 4) refuses a dispatch before a session, aworker or even a round trip exists. The count is liveness-gated rather than a bare
non-terminal count: a stale
running/unknownrow — exactly what an unreconciled crashleaves behind — would otherwise hold a slot for good and wedge
spawnpermanently.Already existed, so documented rather than built
running/unknownstates. Shipped intransport/leaf-turn.ts(
mapHonestState) and wired intosubagents. The only gap was thatgetnever consultedthem;
--waitfixes that as a side effect.follow-up.mocactl run "prompt" --session IDalready is one.SessionManager.resumeis nothing butmintSessionToken(sessionId), so a spawn-createdsession authorizes on the identical path
getuses. The issue's premise — that a follow-upwould clobber the collected result — is false:
writeResulthas exactly one caller, the/v1/runshandler, so/v1/turnwrites no leaf result record.Deliberately not here
watch. design: one CLI for delegating subagent tasks to Moca #495's open question 3 — what it prints so hundreds of tasks stayreadable in Claude Code's Monitor tool — is still unanswered, and
subagents --tag Talready returns the snapshot a Monitor poll consumes. This is the one place the issue's
stated scope is narrowed; happy to put it back if you'd rather settle the output question
here.
approve/reject. Unreachable input: gates are only produced by theconvergeleaf kind (
harness/src/run-leaf.ts:1042) andmocactl spawnaccepts only--kind prompt|solve, so there is nothing to approve. To be tracked in its own issue, whosereal prerequisite is
spawn --kind converge.Notes for review:
(a 503
saturated, already retried inrunSpawnWorker), so N machines can stilloversubscribe it. Marked with a
shortcut:comment.live control plane.
Checklist
git commit -s).make lintand the tests for the touched packages pass.subagent-getandsubagent-spawnare 47 passed;make typecheckis clean across all 13 packages;make lintis clean withhadolint-dockerskipped, which needs a Docker daemon notrunning locally. The full
mocactlsuite has 8 failures inapp,overlay-*andsbx-*which reproduce unchanged on a clean baseline of this branch's merge-base — andthe individual test names differ between runs, so they are flaky as well as
pre-existing. Nothing under
subagent-*,cli-*ormocactl-referencefails in eitherrun.
docs/harness/reference/cli-mocactl.md, including theregenerated
mocactl --helpblock and a new "Following up on a subagent" section.make check-linkspasses (236 files, 0 broken links).Assisted-By: Claude Code