Repository navigation
Description
Problem
Every call to Agent.step() does 4 full O(N) passes over the entire event history, where N is the total number of events ever produced:
ConversationState.get_unmatched_actions()— reverse iteration over all events (state.py:504)View.from_events()— forward iteration, deserializing every event (view.py:126)enforce_properties—BatchAtomicityPropertyscans all events (batch_atomicity.py:24)enforce_properties—ToolLoopAtomicityPropertyscans all events (tool_loop_atomicity.py:60)
Each pass involves Pydantic model_validate_json deserialization with an uncached class hierarchy walk (get_known_concrete_subclasses). Nothing is cached between steps.
Evidence
2000-step conversation: step time grows from 36ms (step 1) to 331ms (step 2000) — a 9.1× slowdown. Total conversation time: 367 seconds. At 100 steps the early-to-late slowdown is 7.7×. The _validate_subtype + get_known_concrete_subclasses family accounts for ~47% of per-step self-time in the 100-step wall profile.
Severity: Critical
Impact of fix
Per-step cost becomes O(1) amortized instead of O(N). A 2000-step conversation that currently takes 367s would take ~5-10s. Long conversations (thousands of steps) become viable at consistent speed.
Suggested fixes
- Cache deserialized Event objects in EventLog (keyed by event ID) so re-iteration doesn't re-deserialize. Medium effort, large impact.
- Make
View.from_events()incremental — append new events to the existing view instead of rebuilding from scratch. High effort, eliminates the O(N). - Cache
get_known_concrete_subclasses()result (the class hierarchy is static after import). Low effort, eliminates ~47% of per-step time.
Related issues and PRs
- Make View construction incremental and tied to ConversationState #3053 — Make View construction incremental and tied to ConversationState (open issue)
- Proposal: don't use full events history in the OH ecosystem #1824 — Proposal: don't use full events history in the OH ecosystem (open issue)
- fix: Incremental view construction #2586 — Incremental view construction (closed PR, prior attempt)
- feat(view): Incremental view construction and conversation state view property #2141 — Incremental view construction and conversation state view property (closed PR, prior attempt)
- perf: parallelize event reading and minimize lock scope in event_service #2170 — perf: parallelize event reading and minimize lock scope (closed PR)
- Fix server stalls by implementing lock-free event search and count operations #1401 — Fix server stalls by implementing lock-free event search and count (closed PR)
- OpenHands#12616 — Web: avoid full-history events loading/retention (open issue)
Discovered during profiling investigation (austin wall-time profiler), May 2026. openhands-sdk v1.19.1.
Activity
github-actions commentedon Jun 18, 2026
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.
VascoSch92 commentedon Jun 22, 2026
Hey @csmith49
I'm closing the issue as it seems complete. (both fixes were merged)
Feel free to re-open if it is the case.