Skip to content

fix(sandbox): keep host sleep out of the exec stall window - #5081

Closed
tale-code-bot wants to merge 1 commit into
mainfrom
fix/stall-watch-monotonic-clock
Closed

tale-code-bot wants to merge 1 commit into
mainfrom
fix/stall-watch-monotonic-clock

Conversation

@tale-code-bot

Copy link
Copy Markdown
Collaborator

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 with Date.now (exec-stall.ts:303 on main). The first sample after the sleep therefore spanned the whole gap with almost no CPU ticks, and isStalled read that as a quiet, idle window. The platform settles EXEC_STALLED as turn_stalled, which deliberately gets no automatic retry. A laptop running tale sandbox connect that slept for an hour failed all of its running agent turns when it woke.

The watch now:

  • Measures time with performance.now(). That is the monotonic clock inner-docker-health.ts already 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).
  • Restarts every window after a long gap. A round more than three sampling intervals after the one before it means the watch was not running in between: 3 minutes at the default 60 s interval. This covers a paused VM whose guest clock jumps on resume. Every exec's samples are dropped, so its window starts again from that round and it can only be ended after a whole window watched since.
  • Keeps the window across rounds that could not read the process table. Such a round still counts as a round, because the CPU counters are cumulative and the next readable round reads them whole.

Unchanged: the window, the 1% rule, isStalled, the runnerd protocol and the platform's turn_stalled mapping. 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:

  • Root cause: Date.now in StallWatch (exec-stall.ts:303), judged in isStalled (:238-258).
  • Fix: a monotonic default clock, plus the gap reset. No new concept. The one consumer, exec-manager.ts, passes options.stall through unchanged.

Closes #4721

Checklist

  • bun run check: run for the touched workspace only. These parts ran and passed at 15c0f5f01:

    • oxfmt --check on the changed files. Markdown is outside the formatter by its config.
    • lint:conflicts, lint:links and lint:manual.
    • The daemon's typecheck (tsc --noEmit, TypeScript 5.9.3) and lint (oxlint --type-aware).
    • The daemon's whole bun test. 4 tests fail there that fail the same way on main in 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 in services/sandbox-runtime/README.md and a clause in the stall row of services/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:

  • a host that slept is no quiet time: the default 45-minute window, sampled once a minute. After 10 quiet minutes the injected clock jumps an hour between two samples. There is no stall at the first sample after the jump. The exec stays quiet and idle and is ended exactly when 45 more minutes have been watched.
  • measures on the monotonic clock: the watch's default clock and interval, with Date.now and performance.now both 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.
  • a round three intervals after the one before is no sleep and rounds that cannot read the process table are no sleep: the exec is still ended on time.

Each new test fails against the variant it targets:

exec-stall.ts variant exec-stall.test.ts
main (9be5cadac) 26 pass, 2 fail: host slept, monotonic clock
gap rule only, Date.now default 27 pass, 1 fail: monotonic clock
monotonic clock only, no gap reset 27 pass, 1 fail: host slept
threshold of 2 intervals 27 pass, 1 fail: three-intervals control
gap measured between samples, not rounds 27 pass, 1 fail: unreadable-rounds control
this change 28 pass

Commands, run in services/sandbox-runtime/daemon unless noted, at the head 15c0f5f01 with a clean tree, Bun 1.4.2:

Command Result
bun test src/exec-stall.test.ts src/exec-manager.stall.test.ts 35 pass
bun test src/exec-stall.test.ts, 15 runs 28 pass in each
bun test src/exec-manager.stall.test.ts, 5 runs (real timers at a 20 ms interval, so the gap threshold is 60 ms) 7 pass in each
bun run --filter @tale/sandbox-runtime-daemon test (the whole daemon suite) 634 pass, 10 skip, 4 fail. The same 4 fail on main at 9be5cadac in this worker: three real-shim tests in exec-rotation.test.ts, because there is no cc to build the shim, and main.test.ts › health describes process activity without viewer state, because the worker's readable cgroup adds a memory block.
bun run --filter @tale/sandbox-runtime-daemon typecheck exit 0
bun run --filter @tale/sandbox-runtime-daemon lint exit 0. A probe file with debugger and an unused variable made the same command exit 1, so the pass isn't vacuous.
oxfmt --check on the changed files (repo root) exit 0
bun run lint:conflicts, lint:manual, lint:links (repo root) exit 0
commitlint on the commit message exit 0

Not run:

  • lint:sast (see above).
  • The other workspaces' checks, E2E, and the jobs that run only in the merge queue. Nothing they cover changed.
  • A real host sleep or VM pause, which can't be reproduced in the authoring worker. The injected-clock tests above are the proof. To check on a device: start a long agent turn on a laptop running 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".

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.
@tale-code-bot

Copy link
Copy Markdown
Collaborator Author

CI was read once, at 15c0f5f01.

Sandbox on Incus failed at its Install Incus, skopeo and ZFS step. services/sandbox/e2e/incus/lab.sh:48 pins INCUS_VERSION_RESOLUTE=1:7.5.1-ubuntu26.04-202610160649, and Zabbly's stable channel no longer serves that build. It now lists …202610261818 and …202610262256 (run 40917404622). This workflow last passed on 2026-10-26.

This change didn't cause the failure, and the job isn't one of the required CI ready checks. Any PR that triggers this workflow will hit it until the pin is updated. That re-pin belongs in its own change, so it isn't in this PR.

At that read:

  • Passed: Format, Lint, Type check, Knip, Unit (workspaces), Unit (platform 1/2), and CI ready for Build, CLI, Commitlint, E2E and Security.
  • Still running: Unit (platform 2/2) and Opengrep.

@tale-review-bot tale-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at head 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb (base main 9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2).

Scope. The PR does what TALE-130's triage and plan asked, and nothing else:

  • StallWatch defaults to performance.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's turn_stalled mapping 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. No Date.now remains 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: lastRoundAt resets when the watch stops.

What I ran at this head (credentials removed):

  • bun test src/exec-stall.test.ts src/exec-manager.stall.test.ts in services/sandbox-runtime/daemon: 35/35.
  • With main's exec-stall.ts put 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:manual ok, lint:conflicts exit 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.

@tale-review-bot
tale-review-bot added this pull request to the merge queue Oct 29, 2026
@yannickmonney
yannickmonney removed this pull request from the merge queue due to a manual request Oct 29, 2026
@yannickmonney yannickmonney reopened this Oct 29, 2026
@tale-review-bot

Copy link
Copy Markdown
Collaborator

Not landed yet: its CI must re-run under the new landing rule. (Reviewer tale-review-bot, run 1f1d8573, 20:27 UTC.)

  • What changed. main no longer lands through a merge queue: commit 0da08205, and since about 20:25 UTC the ruleset holds only the seven required CI ready (…) contexts. This PR left the queue without merging. It is not merged, and auto-merge is off.
  • The new rule. .agents/repo.md ("Each PR lands on its own") and .github/CI.md#landing-on-main say a PR's own CI runs every suite its paths owe, the heavy ones included, and the PR squash-merges once the seven contexts pass on its head.
  • Why I'm not landing it now. The seven green contexts on the approved head 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb ran under the pre-0da08205 workflows. Those skipped Build, E2E, CLI, UI, Browser, Performance and backend integration on pull requests and left them to the queue, which never ran them for this PR. Enabling auto-merge now would merge it at once without those suites. A skipped check is not a pass, so I am not landing it on that evidence.
  • Next. Re-run this PR's CI on the same head; any new pull-request run uses the new workflows. Once all seven CI ready contexts pass on that run, the Reviewer lands it with gh pr merge 5081 --repo tale-project/tale --squash --auto --match-head-commit 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb. The approval stands while the head is unchanged.

@tale-review-bot

Copy link
Copy Markdown
Collaborator

Reviewer: the CI on this head since the 20:13 UTC reopen can't be used to land it (head 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb, still the approved head).

It ran the workflows from before 0da08205. Its checkout merged this head into the old base 9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2 (job 123705576679: HEAD is now at 99e4b38 Merge 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb into 9be5cadac…). As a result:

  • E2E's PR scope logged e2e runs only in the merge queue; this pull request skips it (job 123705573971).
  • These runs skipped every heavy job:
    • Checks 40947199982: UI shards, UI, Browser, Build, Performance and Backend integration;
    • Build 40947200006: all 13 jobs;
    • CLI 40947199830: all 5 jobs;
    • E2E 40947199962: all of its Playwright and bundle jobs.

Without a merge queue, those suites never run before landing. So these runs' CI ready contexts don't show what the contract now requires: "A pull request runs every suite its paths owe, the heavy ones included" (.github/CI.md, Landing on main). I won't enable auto-merge on them, even once they are green. The SAST, Commitlint and Security workflows didn't change in 0da08205.

Next. This PR's merge ref is now based on 0da08205 (merge commit f36daac0bf56). A new pull_request run on the same head, for example closing and reopening the PR as at 20:13, would run the current workflows. Once that run's seven CI ready contexts pass on 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb, the Reviewer lands it with gh pr merge 5081 --repo tale-project/tale --squash --auto --match-head-commit 15c0f5f01ad6fb60ce5175d50be68e490f4f58eb.

@yannickmonney

yannickmonney commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Reopened so the checks run again. The 20:13–20:15 UTC reopen started its runs from a test merge into 9be5cada (before 0da08205), because GitHub had not refreshed it yet. This reopen's runs start from the test merge 083f8e977a, into 0da08205. The head is unchanged (no new commit).

@yannickmonney

Copy link
Copy Markdown
Contributor

Landed on train as d133464: squashed at the approved head after the fast gate (formatting, typecheck, build). It reaches main with the merge train's pull request, so this pull request closes without merging.

yannickmonney pushed a commit that referenced this pull request Oct 30, 2026
Reviewed and approved in pull request #5081 at 15c0f5f.

Closes #4721
Task: TALE-130
@yannickmonney
yannickmonney deleted the fix/stall-watch-monotonic-clock branch October 30, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(sandbox): the stall watch counts wall-clock time, so a host that slept ends running turns as stalled

3 participants