can1357/oh-my-pi · error · RpcError

Compacted agent_end references {streamed_prefix_count} strea

Error message

Compacted agent_end references {streamed_prefix_count} streamed messages, but only {len(streamed_messages)} were retained

What it means

When a run ends with an AgentEndEvent that reports compaction, the client reconstructs the full message list by prepending streamed messages it captured during the run. This RpcError is raised when the terminal event claims more streamed (dropped-by-compaction) messages than the client actually retained, meaning the reconstruction would be incomplete and possibly silently truncated.

Source

Thrown at python/omp-rpc/src/omp_rpc/client.py:1319

        if terminal.message_count is None or terminal.message_count <= len(
            terminal.messages
        ):
            return terminal.messages

        run_start = 0
        for event_index in range(len(events) - 1, -1, -1):
            if isinstance(events[event_index], AgentStartEvent):
                run_start = event_index + 1
                break

        streamed_messages = tuple(
            event.message
            for event in events[run_start:]
            if isinstance(event, MessageEndEvent)
        )
        streamed_prefix_count = terminal.message_count - len(terminal.messages)
        if streamed_prefix_count > len(streamed_messages):
            raise RpcError(
                "Compacted agent_end references "
                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))

View on GitHub (pinned to 9690622007)

Solutions

  1. Increase max_event_history when constructing the RpcClient so all streamed MessageEndEvents are retained
  2. Remove or fix custom listeners that consume events from the shared history during the run
  3. Upgrade the library — this is a client-side consistency check; newer versions may stream messages differently
  4. If reproducible, file a bug with the run's event trace since server and client disagree on message accounting

Example fix

// before
client = make_client(max_event_history=64)
// after
client = make_client(max_event_history=2048)  # retain all streamed MessageEndEvents for compaction reconstruction
Defensive patterns

Strategy: try-catch

Validate before calling

if client_max_event_history < expected_streamed_messages:
    raise ValueError("max_event_history too small for compaction reconstruction")

Try / catch

try:
    messages = client.collect_messages()
except RpcError as exc:
    if "streamed messages" in str(exc):
        raise RuntimeError("history too small; raise max_event_history") from exc
    raise

Prevention

When it happens

Trigger: Calling wait for agent_end / collecting events after a run where terminal.message_count - len(terminal.messages) exceeds the number of MessageEndEvents the client buffered between run_start and the terminal event — typically when max_event_history evicted early streamed events or a listener consumed/dropped events.

Common situations: Long agent runs with many streamed messages exceeding max_event_history; hosts that attach custom event listeners that dequeue events; client started with a small event-history buffer then running a compacting session.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/d6f3037dc2aedfc0. Report an issue: GitHub.