Repository navigation
Description
Is there an existing feature request for this?
- I have searched existing issues and feature requests, and this is not a duplicate.
Problem or Use Case
Part of #5260, after #5543 (PR stack #5263 → #5433) lands. Design: runtime-reclaimer rev 3. Everything is local to the agent-server, and orchestrators (Canvas, sandbox-server/runtime-api, the outer agent-server) reach it over HTTP. They currently cannot:
- see per-conversation activity, sizes or what a pass would free. 7 of 15 surveyed providers expose no last-activity time, so the agent-server should be the source of truth;
- shrink a box on demand before pausing, snapshotting or deleting it;
- give short-lived conversations (PR review, CI-style automations) a shorter retention than long-lived ones (Slack). Engel raised this on feat(agent-server): archive runtimes of long-inactive Docker conversations #5429.
Desired Behavior
Three HTTP-level additions on top of the existing Reclaimer, with no provider knowledge in the SDK.
Acceptance Criteria
PR A: one reclaimer seam (refactor)
- One attribute
registry.reclaimer: Reclaimer | None. Today it'sworktree_reclaimeron the base registry andreclaimeron the Docker one; Docker mode runs only one becauseconfigure_servicedoes not callsuper(). -
Reclaimersplit intoplan()(select paths outside the lock) andapply(plan)(move underidle()). - An
asyncio.Lockserializes passes. Today only the maintenance loop callsrun_pass().
PR B: storage status and reclaim-now endpoints (new storage_router under /api, so behind check_session_api_key; names TBD, e.g. GET /api/storage, POST /api/storage/reclaim)
- Status: root, usage fraction, free bytes, configured budget and retention. Per conversation:
id,state(running/stopped/archived),last_active, and, behind?sizes=true(walked in a thread), size and reclaimable bytes per tier. - Reclaim:
{dry_run, tier?, conversation_ids?}. With no tier it runs the configured pass; a dry run returns the plan. Archiving named conversations is Docker only. This also covers "archive a PR-review conversation after merge" and the "maintenance script" idea: it is a curl. - Neither endpoint calls
update_last_execution_time(), and a test assertsidle_timeis not reset (otherwise maintenance keeps boxes alive past runtime-api's idle reaper).
PR C: per-conversation retention
- Optional retention in days, fractional allowed, as a field appended last on
ConversationConfig(openhands-sdk/openhands/sdk/conversation/request.py) to pass the API breakage gate; persisted with the conversation; TypeScript client regenerated. -
_enforce_retentionuses a per-runtime cutoff (carried onStoredRuntime); the earlybreakon sortedlast_activeno longer holds. - Local mode rejects a value with 422 (local has no retention). The effective value is reported in storage status.
- No
on_stopvalue: containers stop afterconversation_idle_ttl_seconds(20 min default), and reused conversations (e.g. PR review across commits) would be archived on the first idle.
PR D: docs
- OpenHands/docs
agent-canvas/backend-setup/docker-execution.mdx: storage config, the endpoints, and retention-off guidance for boxes that a provider pauses.
Alternatives Considered
A RuntimeBackend hierarchy with provider adapters in the SDK (rev 1). Dropped: the box lifecycle belongs to whoever created it, and HTTP serves every provider.
Priority / Severity
Medium
Estimated Scope
Medium
Feature Area
Agent Server
Technical Implementation Ideas (Optional)
Out of scope here (Phase 2): a box-level adapter for local-mode boxes without worktrees. Today the stack frees nothing in Cloud sandboxes, because the workspace is caller-supplied and $HOME is shared. Also out of scope: Canvas/DigitalOcean delete flow and runtime-api calling reclaim before snapshots.
Additional Context
Depends on #5543.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Scope verified against the dependent stack head (vasco/5260-local-worktree-storage: #5263 → #5407 → #5429 → #5433) and parent #5260. The storage Reclaimer and its ReclaimableStorage implementations already exist there (openhands-agent-server/openhands/agent_server/storage/); the Docker registry owns reclaimer and the base registry owns worktree_reclaimer with no retention, and the Docker configure_service does not call super(). The three additions are agent-server-only and reachable over the existing session-key-guarded /api router.
Bounded scope: (A) collapse the two reclaimer attributes into one registry.reclaimer, split Reclaimer into plan()/apply(plan), and serialize passes with a reclaimer-owned lock; (B) add a /api storage router with a status endpoint and a reclaim endpoint behind check_session_api_key; (C) add an optional per-conversation retention-in-days field on ConversationConfig, carry a per-runtime cutoff on StoredRuntime, reject it in local mode with 422, and regenerate the TypeScript client; (D) document storage config, the endpoints, and retention-off guidance in OpenHands/docs.
Non-goals: a provider RuntimeBackend hierarchy or any provider knowledge in the SDK (HTTP is the interface); the Phase 2 box-level adapter for local-mode boxes without worktrees; the Canvas/DigitalOcean delete flow; runtime-api calling reclaim before snapshots; changing the default budget or retention; and adding an on_stop retention value (containers still stop after conversation_idle_ttl_seconds).
Endpoint names stay the implementer's choice (the author marked them TBD, e.g. GET /api/storage, POST /api/storage/reclaim), so the criteria below are stated functionally rather than pinning paths.
Acceptance Criteria
PR A — one reclaimer seam
-
registry.reclaimeris the single attribute exposing the activeReclaimerin bothlocalanddockerruntime modes; no caller branches onconversation_runtimeor reads a second attribute name to reach it. -
Reclaimerexposesplan()(selects paths without holding the storage idle lock) andapply(plan)(moves the selected paths while holdingidle()); the maintenance pass composes the two, and a pass with nothing to free leaves the filesystem and trash unchanged. - Two
run_pass()calls started concurrently are serialized by a reclaimer-ownedasyncio.Lock: neither moves the same path twice, and both complete without error.
PR B — storage status and reclaim endpoints
- Both endpoints live under
/apiand return 401 when the session API key is absent or invalid, like the other/apiroutes. - Status returns the storage root, usage fraction, free bytes, and the configured budget and retention, and for every conversation returns
id,state(running / stopped / archived), andlast_active. Without the sizes flag it does not walk any directory tree. - With the sizes flag set, each conversation additionally reports its size and reclaimable bytes per tier, and the walk runs off the event loop so it does not block other requests.
- Reclaim accepts
{dry_run, tier?, conversation_ids?}; with no tier it runs the configured pass. Withdry_run=trueit returns the plan and moves nothing (on-disk files unchanged). Archiving named conversations is available in Docker mode and rejected in local mode. - Neither endpoint calls
update_last_execution_time(): a test assertsidle_timeis unchanged after calling status and reclaim, so polling cannot keep a box alive past runtime-api's idle reaper. - Both response bodies are typed Pydantic models and appear in the generated OpenAPI schema.
PR C — per-conversation retention
-
ConversationConfighas an optional retention-in-days field, fractional allowed, declared last so payloads serialized before the change still load; it survives start → persist → resume and is reported as the effective value in storage status. - Retention enforcement uses a per-runtime cutoff taken from the runtime's own retention (falling back to the configured global retention when unset) instead of one global cutoff with an early
break; with two runtimes whose per-conversation retention differs, only the runtime past its own cutoff is retired. - In local mode, starting a conversation with a retention value is rejected with 422 and no conversation is created.
- A retired conversation keeps its history readable and is reported non-resumable, matching the existing stack behavior; no
on_stopretention behavior is added. - The regenerated TypeScript client contains the new field and the client drift check passes.
PR D — docs
- OpenHands/docs
agent-canvas/backend-setup/docker-execution.mdxdocuments the storage config, both endpoints, and retention-off guidance for boxes a provider pauses (docs live in the separateOpenHands/docsrepository).
Validation
- Automated tests cover the plan/apply split and lock serialization, both endpoints (including the no-idle-time-reset assertion and dry-run), per-conversation retention across two differing cutoffs, and the local-mode 422, using the existing docker-runtime/storage fixtures without an LLM.
Activity