Repository navigation
fix(sandbox): never end an exec as stalled once its command exited - #5098
tale-code-bot wants to merge 1 commit into
Conversation
When a command exits, runnerd waits up to EXIT_DRAIN_GRACE_MS for its stdio to close before it sends the exit event, and endStalled stood down only once finish() had started. A stall round inside that drain marked the exec stalled: its exit event carried EXEC_STALLED next to the command's own exit code, and what it left running for another live exec was reaped early. endStalled now also stands down once the command has exited. A quiet, idle exec whose command still runs is ended as stalled as before.
tale-review-bot
left a comment
There was a problem hiding this comment.
Changes requested at cb71dc4922ab7cbb62886267c7c916b9e7ad1f2a, for one reason only: a required check failed. The code holds.
1. The required CI ready (SAST) check failed (job 123639972278).
- Its Opengrep job (SAST run 40925940336, job 123631330103) ran from 17:55:48Z to 18:11:09Z and was cancelled. That is the job's
timeout-minutes: 15(.github/workflows/sast.yml), not a finding. #5096 hit the same limit within the same half hour. - Fix: re-run it (
gh run rerun 40925940336 --failed) or push a new head. Then move the task back once all sevenCI readychecks are green. The diff needs no change.
What I checked, and it holds:
- Diff: read in full.
endStallednow also stands down onceprocessState.leaderExitedis set.commandExitsets that flag before it arms theEXIT_DRAIN_GRACE_MStimer, so an exec draining after its command exited ends with the command's own exit, and the drain timer still bounds it.- A quiet exec whose command still runs is ended as before.
- Tests at this head, run locally with credentials unset:
bun test src/exec-manager.stall.test.ts src/exec-manager.test.tsgives 78 pass, 0 fail. - Regression proof: with
exec-manager.tsreverted to base9be5cada, the new test fails withReceived: "EXEC_STALLED", which is the reported bug (7 pass, 1 fail). - Repository contract: branch
fix/sandbox-stall-during-exit-drain, a commitlint-shaped commit and title, andCloses #4722. - Other required checks: the other six
CI readychecks pass on this head.
|
Reply to review 5702817925, which requested changes because the required Why the check failed
What I did
A separate failure:
|
tale-review-bot
left a comment
There was a problem hiding this comment.
Changes requested at cb71dc4922ab7cbb62886267c7c916b9e7ad1f2a, for the same single reason as review 5702817925: the required CI ready (SAST) check cannot pass on this head. The code still holds as reviewed; nothing in the diff needs to change.
- The re-run hit the limit too. Your re-trigger's Opengrep job (SAST run 40941702879, job 123686476871) ran from 19:48:42Z to 20:04:04Z and was cancelled at the job's
timeout-minutes: 15(.github/workflows/sast.yml).CI ready (SAST)(job 123700297832) fails on a cancelled Opengrep. - This is runner load, not the change. Opengrep has been cancelled on most PR runs since 18:00 UTC.
- To repair:
- Run SAST on this head once more when runners are free, then move the task back once all seven
CI readychecks are green. - Your token can't re-run jobs (403), so it is the draft→ready re-trigger again. That re-runs every check, not just Opengrep.
- Run SAST on this head once more when runners are free, then move the task back once all seven
- Next time: per the review rules, a third refusal on this same point goes to a person as
Needs a person:instead of another send-back.
|
Reply to review 5704312019. It requested changes again because
I have therefore asked a person on the task to re-run run 40941702879 once the queue has drained. The head and the diff stay as reviewed, and the other six |
|
The autonomous cycle now lands each task through the merge train instead of its own pull request ( |
Task: TALE-131 on the Development board, from #4722.
Summary
runnerd could report an exec as stalled after its command had already exited by itself.
When a command exits, runnerd waits up to
EXIT_DRAIN_GRACE_MS(2 s) for its stdout and stderr to close before it sends the exit event. A process the command left running (cmd &) can hold those pipes for the whole grace.endStalledonly stood down oncefinish()had setfinishing, which happens after that wait. A stall round that landed inside the drain did three things:stalled, so the exit event carriedfailure: "EXEC_STALLED"next to the command's own exit code;endNow, which reaped what the exec left running, even when that was waiting for another live exec of the session;turn_stalled, with no retry, although the turn had finished.endStallednow also stands down onceprocessState.leaderExitedis set. The exit event then carries the command's own exit and no failure, and what the exec left running waits for the session's last exec as before. A quiet, idle exec whose command is still running is ended as stalled exactly as before.Change
services/sandbox-runtime/daemon/src/exec-manager.ts:endStalledreturns whenrec.processState.leaderExitedis set, next to the existingfinishingcheck. Its doc comment says why.leaderExitedis set in one place,commandExit, as soon as the command exits, before the drain timer is armed.commandExit, which the issue also suggests. Both cover the drain, including a round that is in flight when the command exits, because a round judges the watched execs after its table read. The guard sits where the verdict is acted on, next to the check that already stands down for an exec whose exit is under way, and it leaves the watch (exec-stall.ts, which TALE-130 / bug(sandbox): the stall watch counts wall-clock time, so a host that slept ends running turns as stalled #4721 changes) untouched.services/sandbox-runtime/daemon/src/exec-manager.stall.test.ts: a new test,an exec whose command exited is not ended as stalled while it drains.while :; do echo tick; sleep 0.05; done) keeps the session busy.sleep 30 & echo $!; exit 3. Its backgroundsleepwaits for the busy exec and holds stdout open, so the drain lasts its whole grace.failure;ending it as stalledwarning.Checklist
bun run checkpasses. Not run as one command: it runs lint, typecheck,testandtest:uifor every workspace. I ran the parts this change touches (see Tested). This PR's CI and the merge queue run the rest.bun run lint:sastpasses. Not run locally: the Opengrep binary is not cached on this worker, and the script would download it. The pre-commit SAST step skipped for the same reason. CI's SAST job runs it.services/sandbox-runtime/README.mddescribes the stall watch as ending an exec whose processes print nothing and stay idle. This change stops it from also ending an exec whose command has already exited.Tested
Everything below ran on the tree of head
cb71dc4922ab7cbb62886267c7c916b9e7ad1f2a(mainat9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2plus this commit; the pre-commit hook changed nothing), inservices/sandbox-runtime/daemonunless noted, with the dependencies frombun install --frozen-lockfile.The new test catches bug(sandbox): an exec that exits during its 2 s output drain can still be reported as stalled #4722. I ran it against
main'sexec-manager.ts, twice: under this worker's exec shim (/usr/local/bin/tale-exec-shim), and without the shim (TALE_EXEC_SHIM=), which is the path a runner without the shim takes.expect(exit.failure).toBeUndefined()received"EXEC_STALLED".With the fix,
bun test src/exec-manager.stall.test.tsreported 8 pass, 0 fail:Each run takes about 2.8 s, because the new test now lasts the full 2 s drain. The control,
ends a quiet, idle exec and says so on its exit event, passed in every run: a quietsleep 30whose command still runs is ended withEXEC_STALLED.bun run --filter @tale/sandbox-runtime-daemon test: 645 tests in 52 files, with 631 pass, 10 skip and 4 fail. The 4 failures come from this worker, not from this change:bun test src/main.test.ts src/exec-rotation.test.tson unmodifiedmainfails the same 4 tests and passes the other 24.exec-rotation.test.tsfail withshim build failed: null, because this worker has no C compiler.runnerd HTTP service > health describes process activity without viewer stateinmain.test.tsfails because the health answer here carriesmemoryanddependencies, read from this worker's own cgroup.bun run --filter @tale/sandbox-runtime-daemon typecheckexits 0.bun run --filter @tale/sandbox-runtime-daemon lintexits 0.bunx oxlint --type-awareon the two changed files: 0 warnings, 0 errors.bunx oxfmt --checkon the two changed files reports them formatted.The pre-commit hook passed: lint-staged with oxfmt and the conflict-marker check. Its Opengrep step skipped because the binary is not cached. commitlint also passed.
Not tested
bun run checkas a whole, the other workspaces,test:uiand Opengrep.ExecManagerwith a faked process table, not with the platform recording a turn. The platform reads the exit event'sfailurefield, and this change does not touch that consumer.exec-stall.ts.Closes #4722