{"record":{"id":"c07851d9350d55d5","repo":"HKUDS/Vibe-Trading","slug":"file-too-large-file-size-bytes-max-wecom-uplo","errorCode":null,"errorMessage":"File too large: {file_size} bytes (max {WECOM_UPLOAD_MAX_BYTES})","messagePattern":"File too large: (.+?) bytes \\(max (.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/channels/wecom.py","lineNumber":422,"sourceCode":"        ``client._ws_manager.send_reply()``:\n\n          ``aibot_upload_media_init``   → upload_id\n          ``aibot_upload_media_chunk`` × N  (≤512 KB raw per chunk, base64)\n          ``aibot_upload_media_finish`` → media_id\n\n        Returns (media_id, media_type) on success, (None, None) on failure.\n        \"\"\"\n        from wecom_aibot_sdk.utils import generate_req_id as _gen_req_id\n\n        try:\n            fname = os.path.basename(file_path)\n            media_type = _guess_wecom_media_type(fname)\n\n            # Read file size and data in a thread to avoid blocking the event loop\n            def _read_file():\n                file_size = os.path.getsize(file_path)\n                if file_size > WECOM_UPLOAD_MAX_BYTES:\n                    raise ValueError(\n                        f\"File too large: {file_size} bytes (max {WECOM_UPLOAD_MAX_BYTES})\"\n                    )\n                with open(file_path, \"rb\") as f:\n                    return file_size, f.read()\n\n            file_size, data = await asyncio.to_thread(_read_file)\n            # MD5 is used for file integrity only, not cryptographic security\n            md5_hash = hashlib.md5(data).hexdigest()\n\n            chunk_size = 512 * 1024  # 512 KB raw (before base64)\n            mv = memoryview(data)\n            chunk_list = [bytes(mv[i : i + chunk_size]) for i in range(0, file_size, chunk_size)]\n            n_chunks = len(chunk_list)\n            del mv, data\n\n            # Step 1: init\n            req_id = _gen_req_id(\"upload_init\")\n            resp = await client._ws_manager.send_reply(req_id, {","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/channels/wecom.py#L404-L440","documentation":"Raised by the WeCom (WeChat Work) channel when a file being prepared for upload exceeds WECOM_UPLOAD_MAX_BYTES. The size is checked via os.path.getsize before reading, inside a thread to avoid blocking the event loop. WeCom's media upload API enforces a hard payload limit, so the library refuses oversized files locally rather than failing mid-upload.","triggerScenarios":"Calling the WeCom channel's file/media send path with a file whose on-disk size is greater than WECOM_UPLOAD_MAX_BYTES; os.path.getsize(file_path) returns a value above the cap and ValueError is thrown from the asyncio.to_thread(_read_file) call.","commonSituations":"Users attaching large videos, logs, or generated reports (e.g. >20MB) through a WeCom bot; files that grew after being queued; archive/debug bundles automatically generated by the agent exceeding the WeCom media API limit.","solutions":["Reduce or compress the file (transcode video, zip/trim logs, downsample images) below WECOM_UPLOAD_MAX_BYTES.","Split the payload into multiple smaller files and send them sequentially.","Upload large content out-of-band (e.g. object storage / URL link) and send the link instead of the raw file.","Raise WECOM_UPLOAD_MAX_BYTES only if you have verified your WeCom app/API tier accepts larger media (not recommended)."],"exampleFix":"// before\nawait channel.send_file(chat_id, \"/tmp/session-recording.mp4\")  # 200MB\n\n// after\nif os.path.getsize(path) > WECOM_UPLOAD_MAX_BYTES:\n    url = await upload_to_object_storage(path)\n    await channel.send_text(chat_id, f\"Recording too large, download here: {url}\")\nelse:\n    await channel.send_file(chat_id, path)","handlingStrategy":"validation","validationCode":"import os\nfrom agent.src.channels.wecom import WECOM_UPLOAD_MAX_BYTES\n\ndef can_upload(path: str) -> bool:\n    return os.path.isfile(path) and os.path.getsize(path) <= WECOM_UPLOAD_MAX_BYTES","typeGuard":null,"tryCatchPattern":"try:\n    await channel.send_file(chat_id, path)\nexcept ValueError as e:\n    if \"File too large\" in str(e):\n        await channel.send_text(chat_id, f\"File too large, shared via link instead: {url}\")\n    else:\n        raise","preventionTips":["Check os.path.getsize before queuing file sends.","Compress or split large artifacts automatically.","Offload oversized content to object storage and send links."],"tags":["wecom","file-upload","size-limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}