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

buffer cannot discard a final response

Error message

buffer cannot discard a final response

What it means

Error "buffer cannot discard a final response" 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:469

        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}
                self.dropped_progress += 1
                self.needs_refetch = True
                return
        if len(self.events) >= self.capacity and not self._drop_oldest_progress():
            self.dropped_progress += 1
            self.needs_refetch = True
            return
        self.events.append({"kind": "progress", "token": token, "value": value})

    def push_final(self, response: dict[str, Any]) -> None:
        while len(self.events) >= self.capacity:
            if not self._drop_oldest_progress():
                raise ReliabilityError("buffer cannot discard a final response")
        self.events.append({"kind": "final", "response": response})

    def drain(self) -> list[dict[str, Any]]:
        drained = list(self.events)
        self.events.clear()
        return drained


def sse_response_headers() -> dict[str, str]:
    return {
        "Content-Type": "text/event-stream",
        "Cache-Control": "no-cache",
        "X-Accel-Buffering": "no",
    }


def sse_keepalive() -> str:
    return ":\r\n"

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:469 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/c37833f7a91df69e. Report an issue: GitHub.