Repository navigation
Description
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:
- On Docker Compose / self-hosted Docker: the container is stopped/removed with no capture. (Docker: conversation-delete workspace archive is a silent no-op (implement archive_conversation_workspace on DockerSandboxService) #1458's fix to
DockerSandboxService.archive_conversation_workspacedoes not help here, because the reap path never calls it.) - On E2B / K8s-agent: same — the sandbox is paused/deleted at the provider with no capture.
- On Helm with the remote backend: runtime-api's own cleanup cron captures at pause time, so the gap is covered for that backend only.
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:
- 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. - 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). - 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_workspacealready 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_infoidle_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_pathcome from at reap time? The explicit-delete path reads it from the conversation'sARCHIVE_WORKSPACE_PATH_TAG_KEYtag. The reap path doesn't have a request-bound conversation context, so it needs to resolve the path another way (re-derive viagrouped_workspace_dirfrom the spec'sworking_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 — seeworkspace_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
- Parent: Workspace archiving (RUNTIME_FILE_ARCHIVE_*) is remote-backend-only: no capture on any non-remote backend #1456
- Sibling: Docker: conversation-delete workspace archive is a silent no-op (implement archive_conversation_workspace on DockerSandboxService) #1458 (explicit-delete path for Docker)
- Docs: https://docs.openhands.dev/enterprise/environment-variables (
RUNTIME_FILE_ARCHIVE_*)
This issue was created by an AI agent (OpenHands) on behalf of Juan Michelini.
Activity
Archive conversation workspaces in the lifecycle reap path