Repository navigation
fix(sandbox): keep host sleep out of the exec stall window - #5081
tale-code-bot wants to merge 1 commit into
Conversation
runnerd's stall watch stamped output and CPU samples with Date.now, so the first sample after a host slept spanned the whole gap with almost no CPU ticks and every running exec past the window was ended as EXEC_STALLED, which the platform settles as turn_stalled with no automatic retry (#4721). The watch now measures on performance.now(), which a step of the wall clock does not move and a Linux host's sleep does not advance. A round more than three sampling intervals after the one before it means the watch was not running in between (a paused VM's guest clock can still jump), so every exec's window starts again there. A round that could not read the process table still counts, since the next one reads the cumulative CPU counters whole.
|
CI was read once, at Sandbox on Incus failed at its Install Incus, skopeo and ZFS step. This change didn't cause the failure, and the job isn't one of the required At that read:
|
tale-review-bot
left a comment
There was a problem hiding this comment.
Approved at head 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb (base main 9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2).
Scope. The PR does what TALE-130's triage and plan asked, and nothing else:
StallWatchdefaults toperformance.now(), a monotonic clock.- A round more than three sampling intervals after the previous one (the host slept, or its VM was paused) clears every exec's samples, so its window starts again. A round that read no table still counts.
isStalled, the 45-minute window, the 1% rule, the protocol and the platform'sturn_stalledmapping are unchanged.- One README sentence and the stall row of the automations register are swept in.
Correctness.
- One clock: every timestamp goes through the injected
this.now(): registration, output and each round. NoDate.nowremains in the file. - Gap check: it runs after the reads. A slow scan, at most 5 s, can't trip the 3-minute threshold.
- Stopping the watch:
lastRoundAtresets when the watch stops.
What I ran at this head (credentials removed):
bun test src/exec-stall.test.ts src/exec-manager.stall.test.tsinservices/sandbox-runtime/daemon: 35/35.- With
main'sexec-stall.tsput back: 2 fail and 26 pass. The two are exactly the new regressions: a host that slept an hour, and an hour's wall-clock step. The controls pass on both: a round three intervals late, and rounds that can't read the table, still end a truly stalled exec on time. The tree was restored afterwards. lint:manualok,lint:conflictsexit 0.
Checks. All seven CI ready checks passed on this head: Checks 40917404418, SAST 40917404807, Commitlint 40917404391, Build 40917404403, Security 40917404485, E2E 40917404525 and CLI 40917404488. The failed Sandbox on Incus (run 40917404622) is not a required check. It stopped installing a pinned Incus build the package source no longer serves (services/sandbox/e2e/incus/lab.sh:48), which this change doesn't touch. That pin deserves its own task.
Not run: a real device sleep. The proof is unit-level, with an injected clock and a mocked wall clock.
|
Not landed yet: its CI must re-run under the new landing rule. (Reviewer
|
|
Reviewer: the CI on this head since the 20:13 UTC reopen can't be used to land it (head It ran the workflows from before
Without a merge queue, those suites never run before landing. So these runs' Next. This PR's merge ref is now based on |
|
Reopened so the checks run again. The 20:13–20:15 UTC reopen started its runs from a test merge into |
|
Landed on |
Summary
When a host woke from sleep, runnerd's stall watch ended every running exec as
EXEC_STALLED(#4721). The watch stamped output and CPU samples withDate.now(exec-stall.ts:303onmain). The first sample after the sleep therefore spanned the whole gap with almost no CPU ticks, andisStalledread that as a quiet, idle window. The platform settlesEXEC_STALLEDasturn_stalled, which deliberately gets no automatic retry. A laptop runningtale sandbox connectthat slept for an hour failed all of its running agent turns when it woke.The watch now:
performance.now(). That is the monotonic clockinner-docker-health.tsalready uses in the daemon. A step of the wall clock does not move it, and a Linux host's suspend does not advance it (CLOCK_MONOTONIC).Unchanged: the window, the 1% rule,
isStalled, the runnerd protocol and the platform'sturn_stalledmapping. An exec that really is quiet and idle for a whole window is still ended.For the reviewer: the threshold of three intervals is a judgment call. A shorter pause still counts as elapsed time, at most about 3 minutes on a 45-minute window, and only where the clock itself jumps (a VM). Ordinary timing never reaches it in production: at the smallest window the spawner sets (1 minute, a 6 s interval), two rounds are at most one interval plus the 5 s scan deadline apart.
Task: Tale TALE-130. Plan, as posted on the task before the first edit:
Date.nowinStallWatch(exec-stall.ts:303), judged inisStalled(:238-258).exec-manager.ts, passesoptions.stallthrough unchanged.Closes #4721
Checklist
bun run check: run for the touched workspace only. These parts ran and passed at15c0f5f01:oxfmt --checkon the changed files. Markdown is outside the formatter by its config.lint:conflicts,lint:linksandlint:manual.typecheck(tsc --noEmit, TypeScript 5.9.3) andlint(oxlint --type-aware).bun test. 4 tests fail there that fail the same way onmainin this worker; see the Test plan.The other workspaces' checks did not run: this change touches no code there, only one row of the platform's manual register. This PR's CI runs them.
bun run lint:sast: not run. The pinned Opengrep v1.22.0 is not cached in the authoring worker, and fetching it from outside the lock files was not allowed. The pre-commit hook skipped it as uncached. The SAST job runs it.Translations: N/A. No message key was added or changed.
Docs in
docs/{en,de,fr}/: N/A. The user docs already describe what this fix restores: an agent ends when it "prints nothing and does almost no work for 45 minutes by default". The mechanism is documented next to the watch, as one sentence inservices/sandbox-runtime/README.mdand a clause in the stall row ofservices/platform/tests/manual/reference/automation/automations.md.README.md/README.de.md/README.fr.md: N/A. There is no install, configuration, environment variable or CLI change.Test plan
Regression tests and controls in
services/sandbox-runtime/daemon/src/exec-stall.test.ts:Date.nowandperformance.nowboth mocked. The wall clock steps an hour ahead while the monotonic clock advances a minute per round. There is no stall at the step, and the exec is ended at minute 46 of the monotonic clock.Each new test fails against the variant it targets:
exec-stall.tsvariantexec-stall.test.tsmain(9be5cadac)Date.nowdefaultCommands, run in
services/sandbox-runtime/daemonunless noted, at the head15c0f5f01with a clean tree, Bun 1.4.2:bun test src/exec-stall.test.ts src/exec-manager.stall.test.tsbun test src/exec-stall.test.ts, 15 runsbun test src/exec-manager.stall.test.ts, 5 runs (real timers at a 20 ms interval, so the gap threshold is 60 ms)bun run --filter @tale/sandbox-runtime-daemon test(the whole daemon suite)mainat9be5cadacin this worker: three real-shim tests inexec-rotation.test.ts, because there is noccto build the shim, andmain.test.ts› health describes process activity without viewer state, because the worker's readable cgroup adds amemoryblock.bun run --filter @tale/sandbox-runtime-daemon typecheckbun run --filter @tale/sandbox-runtime-daemon lintdebuggerand an unused variable made the same command exit 1, so the pass isn't vacuous.oxfmt --checkon the changed files (repo root)bun run lint:conflicts,lint:manual,lint:links(repo root)commitlinton the commit messageNot run:
lint:sast(see above).tale sandbox connect, close the lid for more than 45 minutes, open it, and see the turn carry on instead of failing with "stopped responding".