Skip to content

Add limits and cancellation support to RemoteEventsList.getEvents() #113

@rbren

Description

@rbren

Problem

RemoteEventsList.getEvents() fetches ALL events from the server with no upper bound:

async getEvents(start?: number, end?: number): Promise<Event[]> {
  const remote: Event[] = [];
  let pageId: string | undefined;

  while (true) {
    const params: any = { limit: 100 };
    if (pageId) params.page_id = pageId;
    const response = await this.client.get<EventPage>(...);
    remote.push(...data.items);
    if (!data.next_page_id) break;
    pageId = data.next_page_id;
  }
  // ...
}

For long conversations with thousands of events, this creates an unbounded waterfall of HTTP requests with no way to cancel. The start/end parameters only slice after all events are fetched.

Proposed Fix

  1. Accept a maxEvents parameter to cap total fetched events
  2. Accept an AbortSignal parameter for cancellation
  3. Make start/end work server-side (pass as query params if the API supports it)
  4. Consider returning an async iterator instead of loading everything into memory
async getEvents(options?: {
  start?: number;
  end?: number;
  maxEvents?: number;
  signal?: AbortSignal;
}): Promise<Event[]>

Impact

Low-Medium — prevents runaway network calls and OOM for long conversations.


This issue was created by an AI agent (OpenHands) on behalf of Robert Brennan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions