{"record":{"id":"c37833f7a91df69e","repo":"rohitg00/ai-engineering-from-scratch","slug":"buffer-cannot-discard-a-final-response","errorCode":null,"errorMessage":"buffer cannot discard a final response","messagePattern":"buffer cannot discard a final response","errorType":"exception","errorClass":"ReliabilityError","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py","lineNumber":469,"sourceCode":"        return False\n\n    def push_progress(self, token: int | str, value: float) -> None:\n        if self.events and self.events[-1].get(\"kind\") == \"progress\":\n            if self.events[-1].get(\"token\") == token:\n                self.events[-1] = {\"kind\": \"progress\", \"token\": token, \"value\": value}\n                self.dropped_progress += 1\n                self.needs_refetch = True\n                return\n        if len(self.events) >= self.capacity and not self._drop_oldest_progress():\n            self.dropped_progress += 1\n            self.needs_refetch = True\n            return\n        self.events.append({\"kind\": \"progress\", \"token\": token, \"value\": value})\n\n    def push_final(self, response: dict[str, Any]) -> None:\n        while len(self.events) >= self.capacity:\n            if not self._drop_oldest_progress():\n                raise ReliabilityError(\"buffer cannot discard a final response\")\n        self.events.append({\"kind\": \"final\", \"response\": response})\n\n    def drain(self) -> list[dict[str, Any]]:\n        drained = list(self.events)\n        self.events.clear()\n        return drained\n\n\ndef sse_response_headers() -> dict[str, str]:\n    return {\n        \"Content-Type\": \"text/event-stream\",\n        \"Cache-Control\": \"no-cache\",\n        \"X-Accel-Buffering\": \"no\",\n    }\n\n\ndef sse_keepalive() -> str:\n    return \":\\r\\n\"","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py#L451-L487","documentation":"Error \"buffer cannot discard a final response\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}