{"record":{"id":"1925556874ad39a3","repo":"MemPalace/mempalace","slug":"request-body-too-large","errorCode":null,"errorMessage":"request body too large","messagePattern":"request body too large","errorType":"http","errorClass":"ValueError","httpStatus":413,"severity":"warning","filePath":"mempalace/daemon.py","lineNumber":938,"sourceCode":"        def log_message(self, fmt, *args):  # pragma: no cover - stdlib access logging noise\n            return\n\n        def _authorized(self) -> bool:\n            auth = self.headers.get(\"Authorization\")\n            if auth and secrets.compare_digest(auth, f\"Bearer {token}\"):\n                return True\n            _json_response(self, 401, {\"error\": \"unauthorized\"})\n            return False\n\n        def _read_json(self) -> dict[str, Any]:\n            length = int(self.headers.get(\"Content-Length\", \"0\") or \"0\")\n            # Reject a negative Content-Length explicitly: self.rfile.read(-1)\n            # would read until the client closes the connection, blocking the\n            # worker and bypassing the MAX_BODY_BYTES cap (an auth-gated DoS).\n            if length < 0:\n                raise ValueError(\"invalid Content-Length\")\n            if length > MAX_BODY_BYTES:\n                raise ValueError(\"request body too large\")\n            raw = self.rfile.read(length)\n            return json.loads(raw.decode(\"utf-8\")) if raw else {}\n\n        def do_GET(self):\n            if not self._authorized():\n                return\n            try:\n                self._handle_get()\n            except Exception as exc:  # noqa: BLE001 - malformed query/DB error → 400\n                _json_response(self, 400, {\"error\": str(exc)})\n\n        def _handle_get(self):\n            parsed = urlparse(self.path)\n            if parsed.path == \"/health\":\n                _json_response(\n                    self,\n                    200,\n                    {","sourceCodeStart":920,"sourceCodeEnd":956,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/daemon.py#L920-L956","documentation":"ValueError('request body too large') raised in the daemon's HTTP handler (mempalace/daemon.py:938) when Content-Length exceeds MAX_BODY_BYTES. The cap bounds request memory use per authenticated request; the connection body is never read past the check. Like 208, this originates in the server and surfaces to a client as a 400 response with this message.","triggerScenarios":"POSTing a large transcript/payload to /jobs (e.g. a whole conversation transcript as one submit) whose serialized JSON exceeds MAX_BODY_BYTES; batching many entries into one request; base64-encoding binary content into a JSON body inflating its size.","commonSituations":"Hook submits an unusually long session diary; users ingest mega-file transcripts (see split_mega_files.py) in a single call; generation of a huge dedupe key list.","solutions":["Split the payload into smaller submits (chunk the transcript; see mempalace/split_mega_files.py for oversized transcript files).","Trim needless fields from the payload before submitting.","If a legitimate workflow needs a bigger cap, raise MAX_BODY_BYTES in daemon.py and restart — recognizing the larger memory commitment per request."],"exampleFix":"# before: one giant submit\nclient.submit(\"save\", {\"content\": huge_transcript})\n\n# after: chunked submits\nfor chunk in chunks(huge_transcript, MAX_CHARS):\n    client.submit(\"save\", {\"content\": chunk})","handlingStrategy":"validation","validationCode":"import json\nfrom mempalace.daemon import MAX_BODY_BYTES\n\ndef fits(body: dict) -> bool:\n    return len(json.dumps(body).encode(\"utf-8\")) <= MAX_BODY_BYTES","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.request(\"POST\", \"/jobs\", payload)\nexcept DaemonError as exc:\n    if \"too large\" in str(exc):\n        for chunk in split_payload(payload):\n            client.request(\"POST\", \"/jobs\", chunk)","preventionTips":["Chunk large transcripts before submit (see split_mega_files.py).","Size-check serialized payloads against MAX_BODY_BYTES before sending.","Keep individual job payloads bounded; batch at the daemon side, not the client side."],"tags":["daemon","http","limits","payload-size"],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}