{"record":{"id":"c41a15087dfa79d8","repo":"rohitg00/ai-engineering-from-scratch","slug":"sse-buffer-capacity-must-be-at-least-two","errorCode":null,"errorMessage":"SSE buffer capacity must be at least two","messagePattern":"SSE buffer capacity must be at least two","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":438,"sourceCode":"    def worker_checkpoint(self, task_id: str) -> DurableTask:\n        task = self.tasks[task_id]\n        if task.status == \"working\" and task.cancel_requested:\n            task.status = \"cancelled\"\n        return task\n\n    def finish(self, task_id: str) -> DurableTask:\n        task = self.tasks[task_id]\n        if task.status == \"working\":\n            task.status = \"completed\"\n        return task\n\n\nclass BoundedSseBuffer:\n    \"\"\"Bound progress memory while preserving a final response.\"\"\"\n\n    def __init__(self, capacity: int) -> None:\n        if capacity < 2:\n            raise ReliabilityError(\"SSE buffer capacity must be at least two\")\n        self.capacity = capacity\n        self.events: list[dict[str, Any]] = []\n        self.dropped_progress = 0\n        self.needs_refetch = False\n\n    def _drop_oldest_progress(self) -> bool:\n        for index, event in enumerate(self.events):\n            if event.get(\"kind\") == \"progress\":\n                del self.events[index]\n                self.dropped_progress += 1\n                self.needs_refetch = True\n                return True\n        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}","sourceCodeStart":420,"sourceCodeEnd":456,"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#L420-L456","documentation":"Error \"SSE buffer capacity must be at least two\" 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:438 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"}