Repository navigation
feat(mocactl): sbx run and put retry a command refused before start; exit 75 - #761
Conversation
…exit 75
The relay's in-flight cap ("sandbox busy") and a template worker's admission refusals
("memory-budget:", "max-runs:", "busy: queue full") refuse an Exec before its command starts.
`mocactl sbx run` and `sbx put` reported that as an ordinary sandbox failure, exit 125, so a
caller could not tell "nothing ran, try again" from "it failed partway".
This is mocactl's half of the retry contract stated in rossoctl#728 (the Go client's half is rossoctl#729):
- Only an ExecMachineryError of kind `busy` or `template_busy` that did not run
(`mayHaveRun` false) is retried. A machinery failure, a token expiry, or any failure after the
command may have started is never retried, so the command still runs at most once.
- The command is sent again after a backoff of 1, 2, 4, 8 s (then 8 s each) with +/-25% jitter,
with one stderr note per retry ("nothing ran; retrying in N s (k/n)").
- MOCACTL_SBX_BUSY_RETRIES sets the number of retries: default 4, at most 20, 0 for none;
anything that is not a whole number is the default.
- Refused on every try: exit 75 (EX_TEMPFAIL). Interrupted while waiting: 130. 124 and 125 keep
their meanings.
`sbx mcp` is unchanged: its MCP server already reports a busy sandbox to the model. The usage
text, the user guide and the SBX0 design's exit codes describe the new exit.
The waits count against the sandbox token's lifetime: each retry's timeout is re-capped to what
the token has left (its lifetime less the 60 s margin, less the time waited), and with nothing left
the command is not sent again (exit 75).
Refs rossoctl#728
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Clawgenti Code Review
Summary
The retry is scoped tightly: only busy/template_busy with mayHaveRun false is sent again, everything else still exits on the first answer, and the tests cover each refusal kind, the off switch, the 20 cap, the jitter bound and an interrupt during the wait. No must-fix issues. One suggestion inline: the re-cap of each retry's timeout looks unnecessary, and it cuts the user's own --timeout without saying so.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl sbx run/put, exec exit codes), tests, docs/spec
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing
All checks pass. Ready for human review.
Verified by: reading the PR head's sandboxTokenFn/openExec (packages/mocactl/src/sbx/exec.ts) and SandboxExecConn.prepare (packages/sandbox-client/src/exec-conn.ts). This was a static review; I ran no code from the PR.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| let waitedMs = 0; | ||
| for (let attempt = 0; ; attempt++) { | ||
| let attemptOpts = opts; | ||
| if (capS !== undefined && waitedMs > 0) { |
There was a problem hiding this comment.
suggestion: The re-cap here is meant to stop the backoff from spending the token's lifetime. As far as I can tell, each Exec already gets its own token. SandboxExecConn.prepare asks sandboxTokenFn for one with timeoutS + 60 s left, and get mints a new one when cur falls short (exec.ts, cur.expiresAt - now()/1000 < need). So a token that is up to 15 s older does not shorten the next try. Instead, this branch cuts the requested timeout without saying so. With --timeout 840, the fifth try is sent with 825 s (your test at sbx-exec.test.ts:508 pins [840, 839, 837, 833, 825]). Unlike the --timeout clamp above it, this cut prints no note, and r.capped stays false, so the user is not told.
Suggested fix: drop capS/waitedMs and send opts unchanged on every try. prepare already fits the timeout to the token it actually sends and sets capped when it has to. If the cut is meant to stay, print a note like the --timeout clamp does, so a long job does not time out early with no explanation.
| if (attempt >= retry.retries) { | ||
| execFailed(c, err); | ||
| c.io.err( | ||
| `sbx: the sandbox refused the command ${attempt + 1} time${attempt ? 's' : ''} before starting it; nothing ran (exit ${EXIT_BUSY})`, |
There was a problem hiding this comment.
nit: The 0-retry message reads "refused the command 1 time before starting it" even when retries are off (MOCACTL_SBX_BUSY_RETRIES=0). That is correct, but saying "(retries off)" in that case would tell the user why nothing was retried.
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
mocactl sbx run and sbx put now resend an Exec that the relay or template worker refused before it started (ExecMachineryError kind busy/template_busy, mayHaveRun false). The backoff is 1/2/4/8 s then 8 s, with ±25% jitter. When every try is refused the command exits 75, and an interrupt during a wait exits 130. The retry gate, the exit mapping and the abort handling are correct. Nothing blocks merge. The remaining points are where this PR differs from the #728 contract and the Go client (#729, now merged): the knob is a retry count where #728 specifies a time budget, and bad values are silently ignored. There is also a latent at-most-once gap in sandbox-client that this PR now relies on, plus small notes and doc points.
- Author: webchang (MEMBER — maintainer)
- Areas reviewed: packages/mocactl/src/sbx/{run,exec,cli}.ts, packages/mocactl/test/sbx-exec.test.ts, docs/sbx/user-guide.md, SBX0 design spec §6.1/§10; cross-checked packages/sandbox-client/src/exec-conn.ts and remote-worker/cmd/sbx/sbx.go (origin/main)
- Agent/IDE config: none
- Commits: 1, all signed-off: yes
- CI status: passing
I agree with clawgenti's suggestion at run.ts:99: prepare() already fits each Exec's token to timeoutS + 60 and caps the timeout itself (with capped), so the re-cap in execRetrying is redundant and silently shortens an explicit --timeout.
| export function busyRetries(env: NodeJS.ProcessEnv): number { | ||
| const raw = env.MOCACTL_SBX_BUSY_RETRIES?.trim(); | ||
| if (raw === undefined || raw === '' || !/^\d+$/.test(raw)) return DEFAULT_BUSY_RETRIES; | ||
| return Math.min(Number(raw), 20); |
There was a problem hiding this comment.
suggestion: This PR is described as "mocactl's half of the retry contract stated in #728", and #728 says "the same in every client". The contract there is a time budget: SBX_BUSY_RETRY_S, default 30 s, 0 = no retries. That is what #729 implemented in remote-worker/cmd/sbx/sbx.go. mocactl instead takes a count, MOCACTL_SBX_BUSY_RETRIES (default 4, at most 20). Three differences follow:
- A harness that sets
SBX_BUSY_RETRY_S=0to disable retries everywhere still gets 4 retries frommocactl sbx run. - At the maximum of 20 retries the total wait is (1+2+4+8+16·8)·1.25 ≈ 179 s, nowhere near 30 s.
- A typo like
MOCACTL_SBX_BUSY_RETRIES=offor-1silently means 4 retries. The Go client refuses a malformedSBX_BUSY_RETRY_Swith an error, so a user who meant "none" gets the opposite with no message.
Suggested fix: either honour SBX_BUSY_RETRY_S, stopping when the next wait would exceed the remaining budget (as sbx.go does), or state the difference in #728 and the user guide. Either way, print a one-line warning when the value is not a whole number, rather than defaulting silently.
| return ( | ||
| err instanceof ExecMachineryError && | ||
| (err.kind === 'busy' || err.kind === 'template_busy') && | ||
| !err.mayHaveRun |
There was a problem hiding this comment.
suggestion: refusedBeforeStart is now the only thing ensuring that sbx run and put run a command at most once. It relies on mayHaveRun, but sandbox-client never sets that flag for template_busy. In exec-conn.ts, workerFailure builds new ExecMachineryError(\template busy: ${message}`, code, 'template_busy')withmayHaveRunleft at its defaultfalse. It does not consult output, which the machinery` branch right beside it does. As a result:
- An in-stream
memory-budget:/max-runs:/busy: queue fullExecError that arrives after stdout chunks would be retried, and the command would run twice. - The test case
new ExecMachineryError('template busy: max-runs: full', 2, 'template_busy', true)covers an error the real client never produces.
The Go client's refusalClass is only consulted before the first Chunk ("any failure after a Chunk or End is """). Today's worker sends these refusals before starting, so this is latent, not live. It is still cheap to close in sandbox-client: pass output as mayHaveRun in the TEMPLATE_BUSY branch of workerFailure. Then add a sandbox-client test showing that a chunk followed by busy: queue full is mayHaveRun: true.
| ); | ||
| await retry.sleep(waitMs, c.signal); | ||
| waitedMs += waitMs; | ||
| if (c.signal?.aborted) return 130; |
There was a problem hiding this comment.
nit: When Ctrl-C lands during the backoff, execRetrying returns 130 without writing anything to stderr. The last line the user saw is "retrying in 4.0s (3/4)", so they cannot tell whether the command ran. The Go client prints sbx: interrupted while waiting to retry; nothing ran. Suggest c.io.err('sbx: interrupted while waiting to retry; nothing ran') before return 130.
| | `sbx push [--force]` | Push again. Refuses if the sandbox holds changes not yet pulled, unless `--force` | | ||
| | `sbx pull [--apply] [-o FILE]` | Capture the patch (§6.2). `--apply` applies it locally (plain, else a checked 3-way merge; refused for agent-config files), then advances the sandbox's baseline | | ||
| | `sbx run [--timeout S] [-- CMD…]` | Runs `CMD`, or the script on stdin, in `/workspace`. CMD's words are quoted (shell syntax via stdin or `-- sh -c`). Exits with the command's code. 124 means the command timed out or was killed (`ExecError{"timeout:<n>"}`, or a signal), 125 means the sandbox failed, and 75 means it refused the command before starting it on every try (retried `MOCACTL_SBX_BUSY_RETRIES` times, default 4, at most 20) | | ||
| | `sbx put PATH` | Writes stdin to `PATH` under `/workspace`, creating parent directories | |
There was a problem hiding this comment.
nit: The usage text and the user guide both say put exits 75 when every try is refused, and that an interrupted wait exits 130. In the spec, only the sbx run row (§6.1) gets 75. The sbx put row is unchanged, and the §10 "Exit codes" bullet lists neither put's 75 nor the 130. Suggest adding "; 75 if refused before start on every try, as run" to the put row, and adding 130 to the exit-codes bullet.
Conflicts and resolutions: - packages/mocactl/src/sbx/cli.ts, SbxDeps: both sides add the same sleep(ms, signal) seam. Kept one, its comment naming both users (the template commands' waits and run's wait between tries after a refusal before start), with this branch's random (run's jitter) and main's now (the template commands' clock). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
|
Merged main (d4babb8). Tests ran locally on the existing node_modules, since a fresh install is held by the new hono pin's release-age window; CI is the full check. Assisted-By: Claude Code |
Upstream main (f60db30) adds mocactl's retry for run and put (rossoctl#761). No API version change: this branch claims none. Conflicted: - packages/mocactl/src/sbx/cli.ts: SbxDeps keeps main's random (run's jitter) and its sleep doc for run's retry wait, joined with this branch's mentions of token --renew-every's waits and --record's clock. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Conflicts: the sbx Go client, its tests, build-snapshot.sh and test_sandbox_v1_client.py take upstream's reviewed versions, a superset of webchang's (rossoctl#727, rossoctl#729, rossoctl#757, rossoctl#761, the build-snapshot PRs). packages/sandbox-relay/src/main.ts keeps webchang's per-client tokens beside upstream's set-mode tokens, and direct clients' Execs are normalized to per-exec like the harness's. sbx.py keeps the per-client-token environment line. Signed-off-by: Rong Chang <[email protected]>
Part of #728: mocactl's half. The Go and Python clients' half is #729.
What it does:
mocactl sbx runandsbx putfollow #728's contract.memory-budget:,max-runs:orbusy: queue full. Anything that may have run is never retried.MOCACTL_SBX_BUSY_RETRIES: default 4, at most 20, 0 for none.One signed-off commit.
Tests:
test/sbx-exec: 56 passed after the final re-cap change;tsc --noEmitis clean.6 files, +367 / -41.
Assisted-By: Claude Code