HKUDS/Vibe-Trading · error · ValueError

File too large: {file_size} bytes (max {WECOM_UPLOAD_MAX_BYT

Error message

File too large: {file_size} bytes (max {WECOM_UPLOAD_MAX_BYTES})

What it means

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.

Source

Thrown at agent/src/channels/wecom.py:422

        ``client._ws_manager.send_reply()``:

          ``aibot_upload_media_init``   → upload_id
          ``aibot_upload_media_chunk`` × N  (≤512 KB raw per chunk, base64)
          ``aibot_upload_media_finish`` → media_id

        Returns (media_id, media_type) on success, (None, None) on failure.
        """
        from wecom_aibot_sdk.utils import generate_req_id as _gen_req_id

        try:
            fname = os.path.basename(file_path)
            media_type = _guess_wecom_media_type(fname)

            # Read file size and data in a thread to avoid blocking the event loop
            def _read_file():
                file_size = os.path.getsize(file_path)
                if file_size > WECOM_UPLOAD_MAX_BYTES:
                    raise ValueError(
                        f"File too large: {file_size} bytes (max {WECOM_UPLOAD_MAX_BYTES})"
                    )
                with open(file_path, "rb") as f:
                    return file_size, f.read()

            file_size, data = await asyncio.to_thread(_read_file)
            # MD5 is used for file integrity only, not cryptographic security
            md5_hash = hashlib.md5(data).hexdigest()

            chunk_size = 512 * 1024  # 512 KB raw (before base64)
            mv = memoryview(data)
            chunk_list = [bytes(mv[i : i + chunk_size]) for i in range(0, file_size, chunk_size)]
            n_chunks = len(chunk_list)
            del mv, data

            # Step 1: init
            req_id = _gen_req_id("upload_init")
            resp = await client._ws_manager.send_reply(req_id, {

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Reduce or compress the file (transcode video, zip/trim logs, downsample images) below WECOM_UPLOAD_MAX_BYTES.
  2. Split the payload into multiple smaller files and send them sequentially.
  3. Upload large content out-of-band (e.g. object storage / URL link) and send the link instead of the raw file.
  4. Raise WECOM_UPLOAD_MAX_BYTES only if you have verified your WeCom app/API tier accepts larger media (not recommended).

Example fix

// before
await channel.send_file(chat_id, "/tmp/session-recording.mp4")  # 200MB

// after
if os.path.getsize(path) > WECOM_UPLOAD_MAX_BYTES:
    url = await upload_to_object_storage(path)
    await channel.send_text(chat_id, f"Recording too large, download here: {url}")
else:
    await channel.send_file(chat_id, path)
Defensive patterns

Strategy: validation

Validate before calling

import os
from agent.src.channels.wecom import WECOM_UPLOAD_MAX_BYTES

def can_upload(path: str) -> bool:
    return os.path.isfile(path) and os.path.getsize(path) <= WECOM_UPLOAD_MAX_BYTES

Try / catch

try:
    await channel.send_file(chat_id, path)
except ValueError as e:
    if "File too large" in str(e):
        await channel.send_text(chat_id, f"File too large, shared via link instead: {url}")
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/c07851d9350d55d5. Report an issue: GitHub.