rohitg00/ai-engineering-from-scratch · error · ReliabilityError

SSE buffer capacity must be at least two

Error message

SSE buffer capacity must be at least two

What it means

Error "SSE buffer capacity must be at least two" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py:438

    def worker_checkpoint(self, task_id: str) -> DurableTask:
        task = self.tasks[task_id]
        if task.status == "working" and task.cancel_requested:
            task.status = "cancelled"
        return task

    def finish(self, task_id: str) -> DurableTask:
        task = self.tasks[task_id]
        if task.status == "working":
            task.status = "completed"
        return task


class BoundedSseBuffer:
    """Bound progress memory while preserving a final response."""

    def __init__(self, capacity: int) -> None:
        if capacity < 2:
            raise ReliabilityError("SSE buffer capacity must be at least two")
        self.capacity = capacity
        self.events: list[dict[str, Any]] = []
        self.dropped_progress = 0
        self.needs_refetch = False

    def _drop_oldest_progress(self) -> bool:
        for index, event in enumerate(self.events):
            if event.get("kind") == "progress":
                del self.events[index]
                self.dropped_progress += 1
                self.needs_refetch = True
                return True
        return False

    def push_progress(self, token: int | str, value: float) -> None:
        if self.events and self.events[-1].get("kind") == "progress":
            if self.events[-1].get("token") == token:
                self.events[-1] = {"kind": "progress", "token": token, "value": value}

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py:438 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/c41a15087dfa79d8. Report an issue: GitHub.