can1357/oh-my-pi · error · RpcError
Event history limit was exceeded while waiting for agent_end
Error message
Event history limit was exceeded while waiting for agent_end. Increase max_event_history to retain more streamed events.
What it means
Raised while waiting for agent_end when the requested start_index falls before the beginning of the retained event ring buffer (self._events.offset), i.e. events the waiter needs were evicted because max_event_history was too small for the run's event volume.
Source
Thrown at python/omp-rpc/src/omp_rpc/client.py:1339
f"{streamed_prefix_count} streamed messages, but only "
f"{len(streamed_messages)} were retained"
)
return streamed_messages[:streamed_prefix_count] + terminal.messages
def _wait_for_agent_end(
self,
start_index: int,
start_async_error_index: int,
timeout: float | None = None,
) -> tuple[RpcAgentEvent, ...]:
deadline = time.monotonic() + (timeout if timeout is not None else 60.0)
with self._event_condition:
while True:
if self._closed_error is not None:
raise RpcProcessExitError(str(self._closed_error))
if start_index < self._events.offset:
raise RpcError(
"Event history limit was exceeded while waiting for agent_end. "
"Increase max_event_history to retain more streamed events."
)
if start_async_error_index < self._async_errors.offset:
raise RpcError(
"Async error history limit was exceeded while waiting for agent_end. "
"Increase max_event_history if your host needs to retain more background failures."
)
async_errors = self._async_errors.snapshot_from(start_async_error_index)
if len(async_errors) > 0:
raise async_errors[0]
event_payloads = self._events.snapshot_from(start_index)
if any(
payload.get("type") == "agent_end"
and payload.get("isTerminal") is not FalseView on GitHub (pinned to 9690622007)
Solutions
- Increase max_event_history at client construction to exceed the expected event count for your runs
- Consume events incrementally (listeners/callbacks) instead of batch-waiting from a very old index
- Start waits from a recent index rather than an index captured many events earlier
- Split very long runs into shorter prompts so per-run event volume stays within the limit
Example fix
// before client = RpcClient(..., max_event_history=100) // after client = RpcClient(..., max_event_history=50_000) # headroom for long streaming runs
Defensive patterns
Strategy: validation
Validate before calling
start_index = client.current_event_index()
if start_index < client.events_offset():
raise RuntimeError("event index already evicted; increase max_event_history") Try / catch
try:
events = client.wait_for_agent_end()
except RpcError as exc:
if "Event history limit" in str(exc):
client = make_client(max_event_history=larger_limit) # replay lost work
else:
raise Prevention
- Set max_event_history generously for long streaming runs
- Capture wait start indices close to the wait call
- Use incremental listeners instead of batch-waiting from ancient indices
When it happens
Trigger: Calling wait_for_agent_end with a start index captured early in a run that emitted more events than max_event_history holds; also hit when the client is shared across multiple long runs on one history buffer.
Common situations: Long-running prompt sessions emitting thousands of MessageUpdate/ToolExecution events with a default (small) history limit; multiple sequential prompts reusing one client without draining events.
Related errors
- RPC chunk sequence was interrupted
- Compacted agent_end references {streamed_prefix_count} strea
- Async error history limit was exceeded while waiting for age
- Timed out waiting for agent_end. Stderr: {self.stderr}
- Unsupported language '{value}'. Supported: {}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/40b33f693a4bc883.
Report an issue: GitHub.