Skip to content

Sandbox: an agent session that fails after its container was created leaves the container behind #3494

Closed

Description

@yannickmonney

What happens

When createOrAcquireSession fails for a new agent session, the catch in
agent_session.ts
marks the app.sandbox_sessions row failed and rethrows. It does not ask the spawner to
destroy what it may already have created. If the spawner had created the session container before
the failure, that container stays in Docker state created (never started) with no owner that
will ever remove it:

  • the watchdog's reconcile pass only probes creating, active and degraded rows
    (watchdogs.ts),
    so a failed row is never reconciled and its destroyed_at_ms stays empty;
  • the spawner's idle reaper does not collect a container that never started.

Observed (self-hosted, 2026-09-24 to 2026-09-26)

A workflow agent session was provisioned while the host's Tale runtime was being upgraded. Four
attempts within 50 seconds all ended failed; the first one's container
(tale-sbx-ses-wf-…, labels tale.sandbox-session=1, tale.profile=agent) was created
at the same millisecond as its row and was still in state created two days later, after the
workflow run itself had completed successfully.

Why it matters

The container names the tale-sandbox-runtime image of the release that was running then. Any
image reclaim that keeps images a container still refers to therefore keeps that image and, when
it keeps whole releases, the entire superseded release: on the affected host one leaked container
held back about 12.5 GB (eight images) through every later deploy, and the host reached 88 % disk
use. Its session directory under /var/lib/tale-sandbox/sessions/ also stays.

Suggested fix

  • On the failure path, make a best-effort spawner-side destroy of the session (container and
    workspace) before marking the row failed, logging rather than throwing if that destroy fails.
  • And/or let the reconcile or reclaim pass pick up failed rows whose destroyed_at_ms is
    empty, so leftovers from a failure that raced the destroy are still collected.

To find existing leftovers on a host:

docker ps -a --filter name=tale-sbx --filter status=created --filter status=exited \
  --format '{{.Names}} {{.Status}} {{.Image}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions