Skip to content

perf: agent server loads all conversations eagerly at startup #3140

Closed

Description

@csmith49

Problem

On startup, ConversationService.__aenter__ iterates every conversation directory on disk and calls _start_event_service for each one. Each call creates a LocalConversation (with agent, LLMs, event log), a lease-renew background task, and subscriber registrations. With 1000 persisted conversations, startup creates 1000 full conversation objects serially.

Location: conversation_service.py:742–785

Evidence

Code review of conversation_service.py:742–785. The startup loop is serial with no concurrency limit or lazy loading.

Severity: High

Impact of fix

Startup time drops from O(N) to O(1). Memory at startup is bounded regardless of how many conversations are persisted on disk.

Suggested fix

Load only conversation metadata at startup. Hydrate the full LocalConversation on first access (lazy loading). Consider LRU eviction for idle conversations.

Related issues and PRs

  • OpenHands#13193 — add auto_pause_existing flag and fix sandbox eviction order (open PR, eviction for sandboxes)
  • OpenHands#13892 — lazy-load models per provider (closed PR, similar lazy-loading pattern)
  • OpenHands#9156 — Improve runtime startup performance with container reuse strategies (open issue)

Discovered during profiling investigation (code review), May 2026. openhands-agent-server v1.19.1.

Activity

  1. added
    bug
    performance
    on May 8, 2026
  2. github-actions commented on Jun 22, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.

  3. jamiechicago312 commented on Jun 25, 2026

    @jamiechicago312
    Contributor

    👋 Also hitting this on Windows with npm run dev against openhands-agent-server v1.28.1. With ~89 conversations persisted under ~/.openhands/agent-canvas/conversations/, the agent-server spends ~12 s during startup walking them all before /server_info starts returning 200. The frontend blocks the whole UI on /server_info during that window, so the user-perceived "npm run dev takes a while" is dominated by this loop.

    Quick log evidence (counts from a single boot):

    • 89 × Resumed conversation <id> from persistent storage
    • 133 × Added N secrets to conversation (distribution: 3×36, 4×86, 5×8, 1×3)
    • First successful GET /server_info lands ~40 s after npm run dev

    One adjacent observation worth flagging while you implement lazy loading: the resume loop also silently re-injects the user's current saved secret set (/api/settings/secrets) into every dormant conversation, even ones the user has never reopened since the secret was saved. With lazy hydration that naturally falls out — secrets only need to be reattached when the conversation is actually opened — but it's a small behavior issue that piggybacks on this one.

    Happy to test a PR when one lands.

    (This comment was drafted by an AI agent (OpenHands) on behalf of the user, using their log evidence.)

  4. neubig commented on Jul 13, 2026

    @neubig
    Member

    Duplicate issue #4102 merged here

    Issue #4102 covers the same problem (lazy hydration of persisted conversations to avoid eager startup memory). Closing it as a duplicate and consolidating here.

    Additional context from #4102

    Summary: Agent Server startup currently reconstructs every persisted conversation and its complete event history. Large historical corpora can consume gigabytes of idle memory before any conversation is used, causing watchdog failures and OOM termination. Persisted conversations should instead load into a lightweight catalog and hydrate exactly one runtime only when an operation needs it.

    PR evidence acceptance criteria (from #4102)

    • Current main evidence: With a reproducible persisted corpus containing at least 100 conversations and 50,000 event files, start and restart the real Agent Server on current main. Record exact commit, corpus size, startup logs, live-runtime count, and RSS after readiness; show that historical conversations and event histories are eagerly hydrated before any conversation is used.
    • PR branch evidence: Repeat the identical full-process startup/restart on the PR branch. Show search, count, and metadata reads returning the full catalog without runtime hydration; then use a real runtime/event operation to hydrate one conversation and verify that only it hydrates. Exercise simultaneous first access, running-conversation recovery, and a duplicate fork ID, proving one runtime is created and persisted metadata is not overwritten.
    • Required evidence package: Record both exact SHAs, OS/runtime versions, corpus generator and commands, readiness/restart logs, sanitized HTTP or service outputs, and comparable RSS samples. The live Agent Server process—not only direct unit calls—must demonstrate materially lower idle memory on the PR branch while preserving on-demand behavior.

    Fixing PR

    PR #4100 implements the lazy hydration approach described in this issue.

    This comment was posted by an AI agent (OpenHands) on behalf of Graham Neubig.

  5. self-assigned this
    on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugperformance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions