Skip to content

Idle/expiry sandbox reap (lifecycle worker) skips workspace archiving on all non-remote backends #1457

In review

Description

@juanmichelini

Summary

The lifecycle worker (sandbox/lifecycle/tasks.py) pauses and deletes sandboxes on idle / max-session / inactivity rules for the Docker, E2B, and K8s-agent backends with no archive step, for any backend. Under Helm, runtime-api's cleanup cron covers idle capture — but only for the RemoteSandboxService backend. On every other install (Docker Compose, self-hosted Docker, E2B, K8s-agent), an idle/expiry reap silently tears a sandbox down with zero workspace capture, even when RUNTIME_FILE_ARCHIVE_ENABLED=true.

This is the larger, cross-backend sub-issue of #1456. Its sibling #1458 covers the explicit-delete-while-running path (the conversation-delete finalizer) for Docker. This issue covers the idle/expiry reap path, which is the dominant deletion mode in practice — the workspace-artifact pipeline (final archives with enriched manifests: repo_remote/branch/head_commit, pip/npm deps, runtime versions — PRs #14953 / #15058 / #15059) never runs for a reaped sandbox on any non-remote backend.

Current behavior

The lifecycle worker (openhands/app_server/sandbox/lifecycle/tasks.py) evaluates idle / max-session / inactivity rules and, when a rule fires, acts directly on the sandbox service with no archive call:

  • Action.PAUSE (idle / max-session) → sandbox_service.pause_sandbox(sandbox_id) (tasks.py:211)
  • Action.DELETE (inactivity past the paused-window) → sandbox_service.delete_sandbox(sandbox_id) (tasks.py:218)

Neither path calls SandboxService.archive_conversation_workspace. So:

The result: under any non-remote backend with RUNTIME_FILE_ARCHIVE_ENABLED=true, an explicitly-deleted conversation is captured (once #1458 lands), but an idle/expiry-reaped one is not — and nothing tells the operator. The feature looks enabled, the Laminar traces flow, but the artifacts don't, for the majority of deletions.

Expected behavior

An idle/expiry reap should capture the workspace to the configured store (local / s3 / google_cloud) before pausing or deleting the sandbox, on every backend — the same capture the explicit-delete finalizer performs, via the same archive_conversation_workspace entry point and the same workspace_archive.archive_workspace() sink.

Suggested fix

Add an archive hook in the lifecycle worker before Action.PAUSE / Action.DELETE:

  1. When a rule fires and the sandbox is still running, call sandbox_service.archive_conversation_workspace(sandbox_id, conversation_id=..., workspace_path=...) before the pause/delete transition.
  2. Honor the same REQUIRED-vs-best-effort contract the conversation-delete finalizer uses: if archiving is REQUIRED and fails, leave the sandbox running (skip the pause/delete) so the next reap cycle retries — mirroring the durability backstop in _finalize_sandbox_delete (app_conversation_router.py:1134).
  3. Key the capture per conversation, not per sandbox: under a grouping strategy a sandbox is shared by sibling conversations, and only the conversation that triggered the reap should be captured at that moment (the sibling's work is captured when its own reap or explicit delete fires). This means the worker likely needs the conversation id associated with the idle signal — the same per-conversation keying archive_conversation_workspace already uses.

Open questions worth resolving in the design:

  • Which conversation is "the" conversation for a grouped sandbox reap? The idle signal is per-sandbox (agent-server /server_info idle_time), but capture is per-conversation. Options: capture every conversation referencing the sandbox (cheap to enumerate, but N captures per reap), or capture only when the sandbox has exactly one conversation (the common NO_GROUPING case) and defer grouped reaps to explicit delete. Worth a quick design pass.
  • Where does workspace_path come from at reap time? The explicit-delete path reads it from the conversation's ARCHIVE_WORKSPACE_PATH_TAG_KEY tag. The reap path doesn't have a request-bound conversation context, so it needs to resolve the path another way (re-derive via grouped_workspace_dir from the spec's working_dir + the conversation id, or read the tag from the stored conversation info).
  • Backstop vs. primary. Under Helm-remote, runtime-api's cron already captures at pause. Adding an app-server archive hook there would double-capture. Either gate the hook on backend != REMOTE_BACKEND, or accept the duplicate (the sink already favors capture completeness over upload dedup — see workspace_archive.py:408-410).

Why this matters

This is the only capture path that covers the dominant deletion mode (idle/expiry reap) on non-remote backends. Without it, RUNTIME_FILE_ARCHIVE_ENABLED=true is a partial feature on Docker Compose / self-hosted / E2B / K8s-agent: explicit deletes are captured (after #1458), but the vast majority of sandboxes — which are reaped, not explicitly deleted — are not.

Environment

  • Install: any non-remote backend (Docker Compose, self-hosted Docker, E2B, K8s-agent); also Helm with a non-remote backend
  • Relevant files: openhands/app_server/sandbox/lifecycle/tasks.py, managed_sandbox_service.py, sandbox_service.py (archive_conversation_workspace), workspace_archive.py, app_conversation/app_conversation_router.py (the finalizer contract to mirror)

Related


This issue was created by an AI agent (OpenHands) on behalf of Juan Michelini.

Activity

  1. added
    bug
    on Nov 19, 2026
  2. added a commit that references this issue on Nov 20, 2026
    6cd1392
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions