Skip to content

feat(sandbox): attribute OOM kills and retry out-of-memory runs after a pause - #4633

Merged
yannickmonney merged 3 commits into
mainfrom
fix/sandbox-oom-attribution
Oct 9, 2026
Merged

yannickmonney merged 3 commits into
mainfrom
fix/sandbox-oom-attribution

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What

Item 3 of the run guards, which the owner approved: say when the sandbox's memory limit ended an agent, and stop retrying it at once.

runnerd. The exec manager reads the session cgroup's oom_kill count (memory.events, which covers the whole subtree) when an exec starts and again when it ends.

  • An exec counts as OOM-killed when it died of a SIGKILL (exit 137, with or without the subreaper shim), none of runnerd's own cancel, deadline or stall watch sent that SIGKILL, and the count rose meanwhile. Its exit event then carries oomKilled: true. Another exec's OOM kill does not turn an ordinary failure into one.
  • The exit also carries the session's memory.peak where the kernel reports it.
  • /healthz reports the session's memory: current, limit, peak and OOM kills.
  • Both protocol copies take the fields as additive, so older spawners ignore them; the mirror test keeps the copies identical.

Spawner. runnerd's oomKilled becomes the OOM_KILLED error code. When a stream ends without an exit because the container died, the eviction check now runs before the result is sent, and the inspect it already makes also reads State.OOMKilled (no extra fork). A container Docker recorded as OOM-killed ends the exec as SESSION_OOM instead of SESSION_LOST. Kubernetes restarts an OOM-killed runner inside its Pod, so it keeps SESSION_LOST.

Platform.

  • On the task and automation hosts, OOM_KILLED and SESSION_OOM settle the turn with the new resource_exhausted code and a reason naming the memory limit.
  • It is retried, but not at once: both the task auto-retry and the automation re-kick wait 2, 10, then 30 minutes by attempt.
  • The task card shows a new out_of_memory sentence (EN/DE/FR), and the inbox body falls back to the generic one.
  • The automation's public Run.failureCode stays turn_crashed, so the OpenAPI enum doesn't move.
  • The legacy agent-flow guard passes: only section-pinned files were touched, and none of their pinned functions changed.

Tests

  • Runtime: exec-manager.stall.test.ts (OOM attribution: a kill with a rise, no rise, a plain failure, unreadable counts) and session-memory.test.ts (reading memory.events and the peak).
  • Spawner: session-routes.test.ts (OOM_KILLED with the peak; a dead container read as SESSION_OOM or SESSION_LOST, evicted before the result) and docker-session-backend.test.ts (OOMKilled read from the same inspect, once per incarnation).
  • Platform: the three *.sandbox_ended suites, the retry delays, the i18n message tests and the legacy guard. Type-checks for runtime, spawner and platform are clean.
  • Not covered by a unit test: the task retry's startAfterMs wiring in failAgentRunFromTurn. It is DB-bound and belongs to the backend integration lane.

runnerd reads the session cgroup's oom_kill count (memory.events, the
whole subtree) as an exec starts and as it ends. An exec that died of a
SIGKILL (exit 137) no cancel, deadline or stall watch sent, while that
count rose, carries oomKilled: true on its exit event; another exec's
OOM kill does not turn an ordinary failure into one. The exit also
carries the session's memory.peak where the kernel reports it, and
/healthz reports the session's memory: in use, limit, peak and OOM kills.
Both runnerd protocol copies take the fields as additive.
The spawner forwards runnerd's oomKilled as the OOM_KILLED error code,
with the session's peak in the message. When an exec's stream ends with
no exit because its container died, the eviction check now runs before
the result is sent, and the inspect it already makes reads
State.OOMKilled as well: a container Docker recorded as OOM-killed ends
the exec as SESSION_OOM instead of SESSION_LOST. Kubernetes restarts an
OOM-killed runner in its Pod, so it keeps SESSION_LOST.
A turn whose exec result reads OOM_KILLED or SESSION_OOM settles with
the new resource_exhausted code and a reason naming the memory limit,
on the task and automation hosts. It is retried, but not at once: the
task retry and the automation re-kick wait 2, 10, then 30 minutes by
attempt, since an immediate retry would meet the same limit. The task
card shows an out-of-memory sentence (EN/DE/FR); the run's public
automation code stays turn_crashed.
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.

1 participant