Skip to content

feat(agent-server): reclaim Docker runtime caches and disable core dumps - #5263

Merged
VascoSch92 merged 14 commits into
mainfrom
vasco/5260-prune-runtime-caches
Oct 6, 2026
Merged

VascoSch92 merged 14 commits into
mainfrom
vasco/5260-prune-runtime-caches

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Docker runtimes kept every conversation's package caches forever and wrote 1–2 GB core dumps into the workspace, which repeatedly filled the OSS VM's disk. This adds a small storage module that drops those caches when a container stops and blocks core dumps. An earlier version of this ran on the OSS VM and freed about 44 GB.


AGENT:
Stack: #5263 (this) → #5407 → #5429 → #5433

Why

With conversation_runtime="docker", every conversation keeps its own $HOME under runtime-data/<id>/persistence. Package caches pile up there and nothing removes them short of deleting the conversation, which also deletes its history. Measured on the OSS VM:

  • the per-conversation uv caches were about 26 GB
  • npm caches in .npm were 17.3 GB across 111 runtimes
  • crashing processes wrote 1–2 GB core files into the workspace (8.2 GB across 8 runtimes)

The disk filled and crashed the server seven times between 2026-09-28 and 2026-09-30.

Summary

  • New agent_server/storage/, shared by every runtime mode:
    • Trash: the only delete path. One rename into <root>/.trash, emptied in the background and swept on the next start. Each entry is tried once per run, so an undeletable one cannot spin (safe_rmtree reports failure instead of raising).
    • Tier: what may be dropped.
    • StoredRuntime / ReclaimableStorage: how a runtime mode stores conversations.
    • Reclaimer: start / on_stop / shutdown. It moves files only inside the storage's idle() guard.
  • DockerRuntimeStorage for runtime-data/<id>. The registry now only calls reclaimer.on_stop() / start() / shutdown(). idle() also refuses a runtime that is being deleted; the old prune did not check that.
  • CACHES tier: persistence/.cache and persistence/.npm are dropped when a container stops (idle eviction, DELETE …/runtime, shutdown), and for every runtime at startup. The workspace (including .venv), the rest of persistence/, the manifest and the conversation history are untouched, so resume keeps working.
  • --ulimit core=0 on every conversation container.

The follow-ups build on this: dependencies under a disk budget (#5407), retiring old runtimes (#5429), and the same storage layer for host-local worktrees (#5433).

Issue Number

#5260

How to Test

uv run pytest tests/agent_server/docker_runtime tests/agent_server/storage -q   # 76 passed
uv run pytest tests/agent_server -q -n 8                                        # 7 failed (pre-existing), rest passed

The 7 failures are the pre-existing canvas_extensions/test_canvas_extension_backend.py ones (macOS), identical without this change, diffed by test id.

The tests run on a real filesystem. tests/agent_server/storage/test_reclaimer.py drives the reclaimer through a minimal fake storage, showing the core has no Docker knowledge. Mutation-checked, each makes its test fail when removed:

  • the _deleting check
  • symlinks being unlinked rather than followed
  • the try-once rule for undeletable entries
  • the idle gate

End to end against real Docker (Docker 29.2.1, ghcr.io/openhands/agent-server:1.44.1-python), driving the real DockerConversationRegistry: real docker run, /health, and uv inside the container. The same result on the top of the stack (#5433).

== prune + resume ==
  $ uv venv /workspace/.venv -> rc=0 Creating virtual environment at: /workspace/.venv
  $ uv pip install --python /workspace/.venv six -> rc=0  + six==1.17.0
  cache files before stop: 16
  after stop: .cache exists = False | .venv exists = True | trash = []
  ulimit -c inside the container: 0
  $ uv pip install --python /workspace/.venv requests -> rc=0  + urllib3==2.8.0
  cache files after resume + install: 138
OK
Script
import asyncio, json, os, subprocess, sys, tempfile
from pathlib import Path
from uuid import uuid4
from pydantic import SecretStr

root = Path(tempfile.mkdtemp(dir=os.environ["CLAUDE_JOB_DIR"] + "/tmp"))
os.environ["OH_PERSISTENCE_DIR"] = str(root / "persistence")
from openhands.agent_server.config import Config
from openhands.agent_server.docker_runtime.registry import DockerConversationRegistry

IMAGE = "ghcr.io/openhands/agent-server:1.44.1-python"

def files(path: Path) -> int:
    return sum(1 for p in path.rglob("*") if p.is_file()) if path.exists() else 0

def uv(container, *args):
    r = subprocess.run(["docker", "exec", container.container_id, "uv", *args],
                       capture_output=True, text=True)
    print(f"  $ uv {' '.join(args)} -> rc={r.returncode}", (r.stderr.strip().splitlines() or [""])[-1])
    assert r.returncode == 0, r.stderr
    return r

def seed(reg):
    cid = uuid4()
    reg.provisioning.create(cid)
    d = reg.conversation_dir(cid); d.mkdir(parents=True)
    (d / "base_state.json").write_text(json.dumps({"execution_status": "finished"}))
    return cid

async def main():
    common = dict(conversations_path=root / "conversations", secret_key=SecretStr("k"),
                  conversation_image=IMAGE, conversation_idle_ttl_seconds=None)
    print("== prune + resume ==")
    reg = DockerConversationRegistry(Config(**common))
    cid = seed(reg)
    rdir = reg.provisioning.runtime_dir(cid)
    cache = rdir / "persistence/.cache/uv"
    c = await reg.get_or_create(cid)
    uv(c, "venv", "/workspace/.venv")
    uv(c, "pip", "install", "--python", "/workspace/.venv", "six")
    print("  cache files before stop:", files(cache))
    assert files(cache) > 0
    await reg.stop(cid)
    await reg.reclaimer.trash.drain()
    print("  after stop: .cache exists =", (rdir / "persistence/.cache").exists(),
          "| .venv exists =", (rdir / "workspace/.venv/pyvenv.cfg").exists(),
          "| trash =", list(reg.reclaimer.trash.dir.iterdir()) if reg.reclaimer.trash.dir.exists() else [])
    assert not (rdir / "persistence/.cache").exists()
    assert (rdir / "workspace/.venv/pyvenv.cfg").exists()
    assert not reg.reclaimer.trash.dir.exists() or not list(reg.reclaimer.trash.dir.iterdir())
    c = await reg.get_or_create(cid)   # resume: real health check
    core = subprocess.run(["docker", "exec", c.container_id, "sh", "-c", "ulimit -c"],
                          capture_output=True, text=True).stdout.strip()
    print("  ulimit -c inside the container:", core)
    assert core == "0"
    uv(c, "pip", "install", "--python", "/workspace/.venv", "requests")
    print("  cache files after resume + install:", files(cache))
    assert files(cache) > 0
    await reg.stop(cid)

    print("OK")

asyncio.run(main())

On the OSS VM (the pre-refactor implementation of the same behaviour, 72f6942): the first startup freed ~26 GB of uv caches and the next one 18 GB of npm caches; 108 idle stops pruned with 0 failures overnight; no core dump has been written since. The refactored code is not on the VM yet.

Video/Screenshots

N/A (server-side).

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • Pruning caches on stop is on by default, with no opt-out: $HOME/.cache and $HOME/.npm only hold rebuildable package caches.

🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:5e1ddaa-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-5e1ddaa-python \
  ghcr.io/openhands/agent-server:5e1ddaa-python

All tags pushed for this build

ghcr.io/openhands/agent-server:5e1ddaa-golang-amd64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-golang-amd64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-golang-amd64
ghcr.io/openhands/agent-server:5e1ddaa-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:5e1ddaa-golang-arm64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-golang-arm64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-golang-arm64
ghcr.io/openhands/agent-server:5e1ddaa-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:5e1ddaa-java-amd64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-java-amd64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-java-amd64
ghcr.io/openhands/agent-server:5e1ddaa-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:5e1ddaa-java-arm64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-java-arm64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-java-arm64
ghcr.io/openhands/agent-server:5e1ddaa-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:5e1ddaa-python-amd64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-amd64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-amd64
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-amd64
ghcr.io/openhands/agent-server:5e1ddaa-python-arm64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-arm64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-arm64
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-arm64
ghcr.io/openhands/agent-server:5e1ddaa-python-minimal-amd64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-minimal-amd64
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:5e1ddaa-python-minimal-arm64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-minimal-arm64
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:5e1ddaa-python-slim-amd64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-slim-amd64
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:5e1ddaa-python-slim-arm64
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-slim-arm64
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:5e1ddaa-golang
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-golang
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-golang
ghcr.io/openhands/agent-server:5e1ddaa-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:5e1ddaa-java
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-java
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-java
ghcr.io/openhands/agent-server:5e1ddaa-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:5e1ddaa-python-minimal
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-minimal
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-minimal
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-minimal
ghcr.io/openhands/agent-server:5e1ddaa-python-slim
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python-slim
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python-slim
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime-slim
ghcr.io/openhands/agent-server:5e1ddaa-python
ghcr.io/openhands/agent-server:5e1ddaa4e8f39bd45962000c6dc25fd871a7bd3a-python
ghcr.io/openhands/agent-server:vasco-5260-prune-runtime-caches-python
ghcr.io/openhands/agent-server:5e1ddaa-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 5e1ddaa-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 5e1ddaa-python-amd64) are also available if needed

… cache

Each Docker conversation keeps a private $HOME/.cache (uv alone is ~1.4 GB)
under runtime-data/<id>/persistence, and nothing removed it short of deleting
the conversation, so self-hosted boxes filled their disks.

- Prune persistence/.cache after a runtime stops (idle eviction or
  registry.stop) and once at startup, unless the persisted status is RUNNING.
  The cache is renamed out of the bind mount under the registry lock and
  deleted afterwards, so a concurrent resume never sees a half-deleted cache.
  Workspace, history and the manifest are untouched, so resume keeps working.
- Add conversation_shared_cache_dir: an existing absolute host directory
  bind-mounted into every container as UV_CACHE_DIR. Off by default;
  single-tenant only.

Fixes #5260
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server/docker_runtime
   registry.py2965781%59, 64, 67, 174, 212, 226–227, 230, 248, 258–262, 268, 272–273, 282, 297–301, 320, 324–327, 332, 351, 353, 355, 360–365, 408, 472, 479, 487–489, 492–500, 509–512
openhands-agent-server/openhands/agent_server/storage
   trash.py50394%32–34
TOTAL477591912660% 

VascoSch92 and others added 3 commits September 23, 2026 15:43
…background

Review follow-up for #5260.

- Drop the persisted-status check from the prune. It only ever runs once
  the container is gone (stop, idle eviction, or startup after stale
  containers are removed), so a RUNNING status on disk is stale there and
  only pinned ~1.4 GB per crashed or force-stopped conversation. Live runs
  stay protected by idle eviction, which skips RUNNING conversations.
- Detach caches synchronously but delete them in background tasks, so
  startup with a large backlog, DELETE .../runtime and shutdown no longer
  wait on rmtree. Shutdown cancels pending deletions; the next start sweeps
  whatever they left behind.
…e dumps

Prune persistence/.npm alongside .cache: npm ignores XDG and keeps its
cache in ~/.npm, which the uv-only prune never touched (17 GB across 111
runtimes on the OSS VM).

The shared cache now sets XDG_CACHE_HOME, which uv, pip and yarn follow,
plus npm_config_cache, instead of UV_CACHE_DIR alone.

Conversation containers run with --ulimit core=0: crashing processes
were writing 1-2 GB core dumps into the bind-mounted workspace.
# Conflicts:
#	openhands-agent-server/openhands/agent_server/docker_runtime/registry.py
@VascoSch92
VascoSch92 added this pull request to stack #5431 October 1, 2026 08:50
agent_server/storage/ owns reclaiming disk the server stores per
conversation, independent of the runtime mode:

- Trash: the only delete path. One rename into <root>/.trash, emptied
  in the background, swept on the next start. Each entry is tried once
  per run, so an undeletable one (safe_rmtree reports failure instead of
  raising) no longer spins.
- Reclaimer: on_stop / start / shutdown, reclaiming by Tier, with the
  move done inside the adapter's idle() guard.
- StorageAdapter protocol; DockerStorageAdapter implements it for
  runtime-data/<id>. Its idle() also refuses runtimes being deleted,
  which the registry's own prune did not check.

Caches set aside by earlier builds (.cache-pruned-*) are moved into the
trash at startup. Behaviour is otherwise unchanged.
@VascoSch92 VascoSch92 changed the title feat(agent-server): reclaim Docker runtime caches and add a shared uv cache feat(agent-server): reclaim Docker runtime caches and add a shared package cache Oct 1, 2026
- Final[...] on the registry's and selectors' module constants.
- DockerStorageAdapter is a frozen dataclass; no __future__ import, the
  registry annotation is quoted instead.
- Drop the .cache-pruned-* migration and StorageAdapter.leftovers(): only
  unreleased builds of this branch ever created those dirs.
- contextlib.suppress for UUID parsing (scoped to a _parse_id helper)
  and Trash._entries.
- Document what idle() means for a Docker runtime.
…escribe

DockerStorageAdapter -> DockerRuntimeStorage and the protocol
StorageAdapter -> ReclaimableStorage: they describe a runtime mode's
stored conversations for the Reclaimer, which now calls it storage.
Per review.
Caches are now dropped whenever a container stops, so sharing them saved
little disk while weakening isolation between conversations and adding a
single-tenant-only setting nobody uses. Removes
conversation_shared_cache_dir and its XDG_CACHE_HOME / npm_config_cache
mount. Per review.
@VascoSch92 VascoSch92 changed the title feat(agent-server): reclaim Docker runtime caches and add a shared package cache feat(agent-server): reclaim Docker runtime caches and disable core dumps Oct 1, 2026

@malhotra5 malhotra5 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Few questions

  1. if we run two agent servers on the same machine with shared persistence dir, are we checking which one owns the conversation prior to reclaiming space? maybe we don't need to over engineer here but seems like they'll step over each if that's the case

  2. path based cleanup means this won't work for remote sandboxes. i suppose we're ok with that as we assume any remote sandbox should run an agent server which will perform the cleanup there

  3. when the trash is shutdown deletion still occurs in a separate thread await asyncio.to_thread(_remove, entry); maybe we should document that in the docstring more concretely as its not a true deletion interrupt

inside it are not in use.
"""
registry = self.registry
async with registry._lock:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we're leaking internal locks in this class

Maybe the registry can expose explicit methods like registry.runtime_idle(conversation_id) that wrap this logic

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, fixed in a4bb58b. The lock logic moved to a public DockerConversationRegistry.runtime_idle(conversation_id) context manager; DockerRuntimeStorage.idle() now only delegates to it, the same way LocalWorktreeStorage.idle() delegates to the service. #5429 still reads registry._service in on_retired; I will give that a public registry method there too.

try:
last_active = state.stat().st_mtime
except OSError:
last_active = runtime_dir.stat().st_mtime

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If runtime dir is deleted in the middle of execution could runtime_dir.stat() also throw an error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. The base_state.json stat was guarded, but the fallback runtime_dir.stat() was not: a DELETE removing the dir between the is_dir() check and the stat raised FileNotFoundError, and since runtimes() builds the whole list it aborted the pass (and, from Reclaimer.start(), server startup). Fixed in a4bb58b: that runtime is skipped. test_startup_prune_skips_runtime_deleted_mid_listing reproduces the race and fails without the fix.



class Reclaimer:
"""Frees what a runtime mode stores per conversation, by tier.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@OpenHands what is a runtime mode? Investigate the codebase deeply. I thought it would be only docker or local but local is in the same place so I guess only docker, but you need to correct me if it means something else or there are more modes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm on it! enyst can track my progress at all-hands.dev

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"runtime mode" is the value of Config.conversation_runtime, the Literal["local", "docker"] at openhands-agent-server/openhands/agent_server/config.py:367, selected once in create_conversation_registry() (conversation_registry.py:84). That factory returns the registry — the runtime-mode adapter — that the rest of the server programs against:

  • conversation_runtime == "docker" → DockerConversationRegistry (a subclass of ConversationRegistry) is the only registry that constructs a Reclaimer today (docker_runtime/registry.py:85), backed by DockerRuntimeStorage, the only ReclaimableStorage implementation.
  • anything else — only "local" — → the base ConversationRegistry, which has no reclaimer and no storage adapter.

So your guess needs one correction. Local mode is not "in the same place" in the sense this module cares about: a host-local conversation has no per-conversation sandbox $HOME. The agent runs in-process on the host and uses the host's own $HOME/.cache / .npm, so there is nothing per-conversation to reclaim — which is exactly why local has no ReclaimableStorage implementation. The per-conversation storage this module targets (runtime-data/<id>/persistence, the sandbox's own $HOME) exists only in docker mode.

That's also why the abstraction is a Protocol rather than docker-only: the per-conversation things that do pile up in local mode are the git worktrees under conversation_worktree_root, and the follow-up #5433 is the same storage layer for those. So today there are two runtime modes, only one of which has reclaimable per-conversation storage; the generic ReclaimableStorage/Reclaimer shape is there so the layer isn't tied to Docker.


This reply was authored by an AI agent (OpenHands).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've investigated the codebase and answered the reviewer's question directly on the thread.

Answer to the comment

I found and confirmed the facts, then posted a reply to enyst on PR #5263 (thread r4166906195):

"Runtime mode" is the value of Config.conversation_runtime — a Literal["local", "docker"] at openhands-agent-server/openhands/agent_server/config.py:367. It's selected exactly once, in create_conversation_registry() (conversation_registry.py:84), which returns the registry (the runtime-mode adapter) and:

  • "docker" → DockerConversationRegistry, the only registry that constructs a Reclaimer (backed by DockerRuntimeStorage, the only ReclaimableStorage implementation).
  • anything else (only "local") → the base ConversationRegistry, which has no reclaimer and no storage adapter.

The key correction to the reviewer's mental model: local mode is not "in the same place." A host-local conversation runs in-process on the host and uses the host's own $HOME/.cache / .npm, so there's no per-conversation sandbox $HOME to reclaim — which is exactly why local has no ReclaimableStorage implementation. The per-conversation dir this module targets (runtime-data/<id>/persistence) only exists in docker mode.

I also explained why the abstraction is a Protocol rather than docker-specific: the per-conversation things that do pile up in local mode are the git worktrees under conversation_worktree_root, and follow-up #5433 reuses the same ReclaimableStorage/Reclaimer layer for those. So today there are two modes, one of which has reclaimable per-conversation storage, and the generic shape is future-proofing so the layer isn't tied to Docker.

I left the thread unresolved since it's a pure question and the reviewer may want to follow up or confirm before I mark it resolved.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The answer above is right: a runtime mode is Config.conversation_runtime, local or docker. In this PR only Docker has a storage adapter; #5433 adds the local one (git worktrees). The ReclaimableStorage docstring now says so (5e1ddaa).

# Conflicts:
#	openhands-agent-server/openhands/agent_server/docker_runtime/registry.py
#	tests/agent_server/docker_runtime/test_registry.py
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🧹 PR Artifact Cleanup Queued

The .pr/ directory reached main after merge. A cleanup PR has been opened or updated: #5482

@VascoSch92

Copy link
Copy Markdown
Member Author

@malhotra5 thanks for the review! On your three questions:

  1. Two agent-servers sharing a persistence dir. Not handled, and partly already unsupported on main. The container owner is sha256(conversations_path + persistence_dir), so two servers sharing both paths share an owner, and each one's startup cleanup_stale_containers() already does docker rm -f on the other's containers. With the same persistence dir but different conversations paths, the owners differ but runtime-data/ is shared; the reclaimer only knows its own containers, so its startup pass could move caches out of the other server's running runtime. I'd rather document "one Docker-mode agent-server per persistence dir" than build cross-process ownership now. If we need it later, an owner lock file on runtime-data/ would close it.
  2. Remote sandboxes. Yes, that's the assumption we settled on in Slack: every sandbox runs an agent-server, and from its point of view everything is local, so the path-based cleanup runs inside the box. Whatever creates the box owns its lifecycle (pause/delete). The HTTP endpoints that let an orchestrator see and trigger this are tracked in [Feature]: Agent-server storage API: status, reclaim-now, per-conversation retention #5544; landing this stack is [Feature]: Land the conversation-storage PR stack (#5263 → #5433) on current main #5543.
  3. Trash shutdown. Right, cancelling can't interrupt a _remove already running in a worker thread. Trash.close()'s docstring now says so (5e1ddaa); test_shutdown_abandons_deletions_and_next_start_sweeps_them covers it (the in-flight deletion finishes, the queued one waits for the next start).

Also merged main (f10ef3e). That picks up #5403, which fixes the ConversationRunLimitExceeded failure in the stress tests further up the stack.

@VascoSch92
VascoSch92 marked this pull request as ready for review October 6, 2026 09:40
@VascoSch92
VascoSch92 merged commit 92e1424 into main Oct 6, 2026
69 of 71 checks passed
@VascoSch92
VascoSch92 deleted the vasco/5260-prune-runtime-caches branch October 6, 2026 10:22
@github-actions github-actions Bot mentioned this pull request Oct 8, 2026
3 of 7 tasks
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.

3 participants